Nov-10-2021, 02:24 PM
Hello ,
Hello ,
I'm trying to read RS485 data from one pi to another (using TTL to RS485 device)
on the "sender" side I have this simple code:
in the receiver side I have this code:
I can see the sender sending this data:
but on the receiver I get this :
**when I connect it to my computer I can see the data correcrt.
what am I missing \ doing wrong ?
** when I try to decode the answer
I get this error:
Hello ,
I'm trying to read RS485 data from one pi to another (using TTL to RS485 device)
on the "sender" side I have this simple code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import time import serial from time import sleep import random import string send = serial.Serial( port = '/dev/serial0' , baudrate = 9600 , parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE, bytesize = serial.EIGHTBITS, timeout = 1 ) while True : letters = string.ascii_letters digits = string.digits data = ''.join(random.choice(letters) + random.choice(digits) for i in range ( 20 )) data = (data + "\n\r" ) send.write(data) print (data) time.sleep( 0.2 ) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import serial RS485 = serial.Serial( port = '/dev/serial0' , baudrate = 9600 , parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE, bytesize = serial.EIGHTBITS, timeout = 1 ) while True : x = RS485.readline() print (x) |
I can see the sender sending this data:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
f6d6d0F9B3L1K2C6K0y6m0N2O4S9A8u5y2t0J7f2 H1r1W2X6X0B2i0Y4b0w8U2M6C8X3i1D1D5p9F2y5 f8J8m7z6y3m2U6I3U0Z7J6M4l7Z0B5v4F6H5e2Q2 L6Z0G8m1Q2Q2d6O3t7M8J7h8h8E8b8Z9H3P5I5R2 l3N3T7C2o3T3K3c8G2S5h3G6x6b1O4X1R5B6o1U0 O5S2S3m5L4J5Z7i3U6r5J8h1J2r5k6y8T4S6h7I7 B9E4t5S0k0K1k0T4w4j3t1i0K3w2A5Y9h9N6k2m5 u7E9p4O9D9X0O7V1h1Y6J1R4n3s0g6L2P1A3Z9q9 p3K1X6t0a5P1W4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x8d>B\x8d*d\x89B\x16b\xb2 B\x16@;B\x98d\x19D\xaa@;; \xa2@7\x03Bbb#b\xc9\x81@L\x82\xfe%\xabDw\x12B\x12`J\xafb\xb2bB\xe7\x18\x0ef\x10@\x10\xa2`\x88*b7@B\xe6\xaa\xc9\xbbDbnDw\xb2bI\xa7F\xbb\x81r\tFr\x1ab\xc8\xb2B\x98\x11B\x8eB\x82\xfe\xe8\x11Dv\x89d\x0cb\x91\x11Ds\xbb@\x82\xff3\x82@\xe8D\xc8\x0bB\x13@B.F \xf2#F\xc9d;@\xb2\n' |
what am I missing \ doing wrong ?
** when I try to decode the answer
1 2 3 |
x = RS485.readline() data = str (x, 'utf-8' ) print (data) |
1 |
'utf-8' codec can't decode byte 0xf2 in position 0 : invalid continuation byte |