Unable to open serial port in Python

If you have specific questions or problems with any of my Freeware applications, post them here.
Post Reply
MarineLebrec
Posts: 1
Joined: Fri Jul 23, 2021 12:47 pm

Unable to open serial port in Python

Post by MarineLebrec »

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?
User avatar
roger
Site Admin
Posts: 431
Joined: Fri Apr 24, 2009 12:41 am
Contact:

Re: Unable to open serial port in Python

Post by roger »

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.
Post Reply