Arduino'错误通信......不支持unicode字符串,请编码为字节'PySerial [英] Arduino 'Error communicating...unicode strings are not supported, please encode to bytes' PySerial
问题描述
我正在尝试通过 PySerial 连接到我的 MultiWii,但是我不断收到此错误.
I'm trying to connect to my MultiWii over PySerial, however I keep getting this error.
错误通信...不支持unicode字符串,请编码为字节:'$M<\x00ll'
这是代码失败的部分:
BASIC="\x24\x4d\x3c\x00"
MSP_ATTITUDE=BASIC+"\x6C\x6C"
ser.write(MSP_ATTITUDE)
我尝试使用 .encode()
对字符串进行编码,但出现此错误:
I've tried encoding the strings with .encode()
in which I get this error:
Error communicating...'bytes' object has no attribute 'encode'
我试过 bytearray(MSP_ATTITUDE,'ascii') 并得到上一个错误.
I've tried bytearray(MSP_ATTITUDE,'ascii') and get the previous error.
我之所以这么问,是因为这个错误圈真的没有意义.任何人都可以帮忙吗?如果有帮助,我可以提供有关代码的更多信息.
I'm only asking this because this error circle doesn't really make sense. Can anyone help? I can provide more information regarding the code if it'll help.
提前致谢
推荐答案
你应该尝试:
BASIC = b"\x24\x4d\x3c\x00"
MSP_ATTITUDE = BASIC + b"\x6C\x6C"
因此它们被视为bytes
对象而不是unicode 字符串.
So that they are treated as bytes
objects and not unicode strings.
这篇关于Arduino'错误通信......不支持unicode字符串,请编码为字节'PySerial的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!