通过串口发送十六进制值的问题

时间:2019-07-19 06:15:08

标签: python python-3.x serial-port

我正在通过串行端口发送十六进制数字列表,尽管它可以正常工作直到两位数字,但是当我发送3位十六进制数字时,就会出现问题。 0xA1,0x3D,0x52等工作正常,但在发送数字(例如0x131,0x255等)时显示错误消息,即ValueError:字节必须在范围(0,256)中 如何发送这些类型的值?

我按原样发送诸如131,255之类的值,而无需在它们前面写“ 0x”,那么它可以发送,但这些值随后以int形式发送..我希望它们以十六进制..如0x131, 0x255等

ser.write(serial.to_bytes([0xA1,0x3D,0x00,0x01,0x52,0x00,0x01,0x10,0x60,0x0A,0x00,0x01,0x01,0x00,0x00,0x46,0x00,0x01,0x131, 255,191,255,207,255,191,255,131,255,128,255,182,255,182,255,182,255,190,255,128,255,191,255,191,255,191,255,191,255,193,255,190,255,190,255,190,255,221,255,193,255,190,255,190,255,190,255,193,255,128,255,253,255,251,255,253,255,128,255,128,255,182,255,182,255,182,255,190,255]))

0 个答案:

没有答案