【问题标题】:Serial data problem in orange Pi zero serial port python橙色Pi零串口python中的串行数据问题
【发布时间】:2021-09-16 19:54:44
【问题描述】:

我正在使用串行端口从 RFID 卡读取 RFID 数据。卡在连续发送数据。

serial_port = serial.Serial(
    port="/dev/ttyS2",
    timeout=2,
    baudrate=38400,
    bytesize=serial.EIGHTBITS,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE
)
while True:
    cmdRet=serial_port.read(6)
    print("Raw1 = "+str(cmdRet))


如果我使用 USB 转串口转换器并将其连接到橙色 PI,则它正在正确读取数据。根据文档,当它没有检测到 RFID 卡时,它会连续发送 ASCII U\r\n 但是如果我连接橙色 PI 的 UART,它会读取不正确的数据,就像没有 RFID 卡时它会读取 \x00\xbdUy=

\x00 用于NULL 字符,0xbd 甚至不是有效的utf-8 字符。

我也连接了公共地,我不确定问题是什么。谁能指导我?

我必须在最终产品中使用橙色 PI 的 UART。

【问题讨论】:

  • 您需要清楚地识别您正在尝试使用的这些“串行端口”。您是否将 RS-232 端口与串行 (UART) TTL 端口混淆了?
  • 我认为你是对的。 TTL 应与 TTL 连接,RS-232 应与 RS-232 连接。

标签: python serial-port pyserial rfid orange-pi


【解决方案1】:
  • 因为它正在从串口读取字节。
  • 尝试解码,如***.decode("utf-8")

【讨论】:

  • 这与解码无关。我将此解码与 USB 到串行转换器一起使用,并且读取完美,当我在 UART 中使用解码时它甚至会出错。错误是print("Raw1 = "+cmdRet.decode("utf-8")) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbd in position 0: invalid start byte
猜你喜欢
  • 2017-02-09
  • 2019-02-06
  • 2017-05-12
  • 1970-01-01
  • 2017-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-14
相关资源
最近更新 更多