Unable to open serial port in Python

If you have specific questions or problems with any of my Freeware applications, post them here.

Unable to open serial port in Python

Postby MarineLebrec » Fri Jul 23, 2021 12:54 pm

Hi,
I am able to connect to serial ports using the CoolTerm application without any issues.
When I try to run the #open the serial port# portion of Introduction.py in Python, I am coming across the error:
"UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 7507: invalid start byte".
I assume that this is because all commands are written in ASCII and not utf-8. Any idea how I can get around this?
MarineLebrec
 
Posts: 1
Joined: Fri Jul 23, 2021 12:47 pm

Re: Unable to open serial port in Python

Postby roger » Fri Jul 23, 2021 6:44 pm

Try changing this line in the CoolTerm.py module, in the getData function, on line 253 from
Code: Select all
return DATA.decode()

to
Code: Select all
return DATA.decode(encoding='ascii')


This ensures decoding using ASCII when bytes larger than 0x7F are received.
User avatar
roger
Site Admin
 
Posts: 281
Joined: Fri Apr 24, 2009 12:41 am


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron