Fastas
Fastas

Reputation: 89

Pyserial read is not returning what I write out

currently I have a raspberry pi ports connected to two serial devices. the devices are usb to RS485/RS422 converter. both are connected with wires to the proper terminals (terminal 1 of device A to terminal 2 of device B, terminal 2 of device A to terminal 1 of device B).

I'm able to successfully read and write from one device to the other, however the return read data is not the same as the data I wrote.

For example, if the message I am trying to send is "Te", the message I read is b'U\x13\x00'.

I am currently running python 3 on buster.

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

I except the output of bytes in read to convert to the string I wrote in write.py, however the output is always something completely different.

EDIT: link to serial devices(usb to RS-485/RS-422)

Upvotes: 1

Views: 1479

Answers (1)

Marcos G.
Marcos G.

Reputation: 3496

You wiring seems to be wrong:

... terminal 1 of device A to terminal 2 of device B, terminal 2 of device A to terminal 1 of device B...

That's OK for UART or RS232, but for RS485 the correct wiring is A to A and B to B (straight instead of crossing RX to TX).

Rewire and it'll work.

Upvotes: 1

Related Questions