tag.id用串口好像没法直接输 怎么用语句用串口输出?
显示错误是object with buffer protocol required
MicroPython教程5-编码与串口 (https://singtown.com/learn/556/)
因为id是数字,write要求字符串,所以你有两个选择
- uart.writechar(id)发送数字
- uart.weite(str(id))发送字符串
@kidswong999 谢谢 解决了 那如果要用串口输tag.x_translation()这种四个字节的float数据呢?我想用8位十六进制数据接收 麻烦了
更精细的打包为二进制,可以使用struct.pack,非常强大
<https://cn.bing.com/search?q=python3+struct+pack&qs=n&form=QBLH&sp=-1&pq=undefined&sc=0-19&sk=&cvid=7E54CAFD99784066A9762F5265FC2FB9>
uart.write()可以发送bytes
data = bytearray([1,2,3,4])
uart.write(data)struct.pack之后的二进制数据,uart.write()进去就行
MicroPython教程7-IO中断与回调函数<https://singtown.com/learn/582/>
如果接收一个float类型的数据应该怎么写呢?
@b4gf 新的问题,单独发帖子提问。