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.
Error communicating...unicode strings are not supported, please encode to bytes: '$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屋!