问题
encode('utf-16')
will write the hexadecimal to serial port, but it is sending only 5 bit's on serial port.
port = 'COM4'
baud = 9600
ser = serial.Serial(port, baud, timeout=1)
ser.reset_input_buffer()
ser.isOpen()
command = '4c 31 32 33'
ser.write(bytearray(str(command), 'utf-16'))
ser.close()
-----------------------------------------
a = ser.readline().decode('utf-16')
s = ''.join([chr(int(x, 16)) for x in a.split()])
Output: L
Expected output: L123
来源:https://stackoverflow.com/questions/55490010/pyserial-cant-write-the-complete-bytes-to-serial-port-hex-data