pyserial can't write the complete bytes to serial port (hex data)

人盡茶涼 提交于 2020-01-25 10:50:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!