gpt4 book ai didi

python - 在 python : Unknown characters 中读取 arduino 串行连接

转载 作者:行者123 更新时间:2023-12-04 18:51:56 25 4
gpt4 key购买 nike

我正在使用 Python 通过 pyserial 与我的 Arduino 对话。模块。

import serial
ser=serial.Serial('/dev/ttyUSB0', 115200)

我得到以下结果:
ser.read(20)
'y8\t0.16\t0.16\t-0.65\r\n'

这就是我需要的。

但是如果我关闭端口并再次打开它,我会得到以下信息:
ser.close()
ser=serial.Serial('/dev/ttyUSB0', 115200)
ser.read(20)
'4\xfa\x9a\xf9t\xff\x1a\xffA\xff<\xf2x\xf68\xf6A\xffA\xff'

这些符号是什么?如何获得正确的字符?

我的操作系统是 Ubuntu

最佳答案

这些是“反斜杠替换”的 unicode 字符。基本上,ASCII ,它是一个字符列表(如 A% ),不能代表 Unicode 中的所有字符(比 ASCII 更长的字符列表)。我建议你看看the codecs library to deal with unicode .

关于python - 在 python : Unknown characters 中读取 arduino 串行连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30132549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com