Pyserial 读取不返回我写出的内容
Pyserial read is not returning what I write out
目前我有一个 raspberry pi 端口连接到两个串行设备。这些设备是 USB 到 RS485/RS422 转换器。两者都用电线连接到正确的端子(设备 A 的端子 1 到设备 B 的端子 2,设备 A 的端子 2 到设备 B 的端子 1)。
我能够成功地从一台设备读取和写入另一台设备,但是return读取的数据与我写入的数据不同。
例如,如果我要发送的消息是"Te",那么我阅读的消息是b'U\x13\x00'
。
我目前 运行 python 3 级。
ser = serial.Serial(port='port 1', baudrate = 9600)
message = "Te"
message = message.encode('ascii')
while True:
ser.write(message)
time.sleep(1)
write.py
ser = serial.Serial(port = 'port 2', baudrate = 9600)
while True:
serial_line = ser.read(50)#placehoder until I am able to get correct values
print(serial_line)
read.py
我除了将读取的字节输出转换为我在 write.py 中写入的字符串,但是输出总是完全不同的东西。
编辑:
link to serial devices(USB 转 RS-485/RS-422)
你的接线好像有误:
... terminal 1 of device A to terminal 2 of device B, terminal 2 of device A to terminal 1 of device B...
这对于 UART 或 RS232 没问题,但对于 RS485,正确的接线是 A 到 A 和 B 到 B(直接而不是穿过 RX 到 TX)。
重新布线即可。
目前我有一个 raspberry pi 端口连接到两个串行设备。这些设备是 USB 到 RS485/RS422 转换器。两者都用电线连接到正确的端子(设备 A 的端子 1 到设备 B 的端子 2,设备 A 的端子 2 到设备 B 的端子 1)。
我能够成功地从一台设备读取和写入另一台设备,但是return读取的数据与我写入的数据不同。
例如,如果我要发送的消息是"Te",那么我阅读的消息是b'U\x13\x00'
。
我目前 运行 python 3 级。
ser = serial.Serial(port='port 1', baudrate = 9600)
message = "Te"
message = message.encode('ascii')
while True:
ser.write(message)
time.sleep(1)
write.py
ser = serial.Serial(port = 'port 2', baudrate = 9600)
while True:
serial_line = ser.read(50)#placehoder until I am able to get correct values
print(serial_line)
read.py
我除了将读取的字节输出转换为我在 write.py 中写入的字符串,但是输出总是完全不同的东西。
编辑: link to serial devices(USB 转 RS-485/RS-422)
你的接线好像有误:
... terminal 1 of device A to terminal 2 of device B, terminal 2 of device A to terminal 1 of device B...
这对于 UART 或 RS232 没问题,但对于 RS485,正确的接线是 A 到 A 和 B 到 B(直接而不是穿过 RX 到 TX)。
重新布线即可。