Reputation: 139
i am trying to make a connection in which i want to send data from my one com port named COM4 and receive it in COM5..i had made a connection using RS485..i am not receiving the proper data which i have sent from COM4 to my COM5..sometimes i get a little proper and sometimes not..i have kept the baudrate 9600 in both the ends..but still it is not reliable i.e.chance of getting correct data every time is not sure..
The code for receiving is as follows:
import serial
import time
ser=serial.Serial(port='COM5',baudrate=57600,timeout=1)
recv=[]
while True:
print(ser.read())
Sending Code is as follows:
import serial
import time
ser=serial.Serial(port='COM4',baudrate=57600,bytesize=8)
print(ser.portstr)
ser.write(serial.to_bytes([100,101]))
ser.close()
i am receiving some d and e at receiver
Upvotes: 0
Views: 310
Reputation: 3496
d and e is exactly what you are sending when you write bytes 0x64 (dec 100) and 0x65 (dec 101) on your port. You are probably receiving a byte array similar to b'de'
.
If you want to get hex printed you can try something like:
hex_string = binascii.hexlify(data).decode('utf-8')
Where data
contains the bytes you read from the port. Note that you need to import binascii
.
If you want to recover the list of decimal numbers you sent you might want to look at struct.unpack
.
Upvotes: 0