I am writing a serial adapter for some scientific equipment whose set uses UTF-8 character encodings. All responses from the hardware end with a carriage return (u '\ r'). I would like to use the pySerial readline() function with the specified EOL character, so I have this setting, ala this thread :
import serial import io ser = serial.Serial(port='COM10', baudrate=128000) sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser, 1), encoding='utf-8', newline=u'\r') ser.open()
Oddly, the first command line (non-Unicode using pySerial directly) causes the correct hardware behavior. The second (unicode via the Python io module) makes it move randomly and then freeze. Why should it be? Sending Unicode command lines to the hardware runs IF , and the command line only has a few characters. After you start sending bytes with hex(ord(byte)) values> 0x7F (outside the ASCII range), you will start to run intro problems. I can get around this problem without much trouble, but would like to know what is going on. Thanks!
source share