请教个问题,pyserial 的数据发送与接收

各位技术大拿们好!刚入手研究串口这一块,有点小问题,我这样发送数据和收到的数据有点问题:

打印的输出和我预期的不一致 我不确定是我的发送的数据有问题,还是读取数据的函数调用有问题,串口调试工具上 发送和接受的数据是这样的:

这个数据应该是16进制数字,但还是不清楚我写的代码问题在哪里,希望老哥们指点一下,万分感谢!

Jason990420
最佳答案

write(data)

Output the given string over the serial port. This should be of type bytes (or compatible such as bytearray or memoryview).

>>> data = bytes([0x01,0x03,0x00,0x01,0x00,0x02,0x95,0xCB])
>>> data
b'\x01\x03\x00\x01\x00\x02\x95\xcb'
1年前 评论
讨论数量: 1
Jason990420

write(data)

Output the given string over the serial port. This should be of type bytes (or compatible such as bytearray or memoryview).

>>> data = bytes([0x01,0x03,0x00,0x01,0x00,0x02,0x95,0xCB])
>>> data
b'\x01\x03\x00\x01\x00\x02\x95\xcb'
1年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!