Arduino'通信错误...不支持unicode字符串,请编码为字节'PySerial [英] Arduino 'Error communicating...unicode strings are not supported, please encode to bytes' PySerial

查看:727
本文介绍了Arduino'通信错误...不支持unicode字符串,请编码为字节'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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆