Good day,
I am trying to read HEX data streams via RS232 on my TRB245 router. I am specifically trying to use pySerial to achieve this. I have installed all of the necessary packages and have a python sample script running on the router that is able to partially read the incoming data. I am however experiencing issues with the consistency of the received strings, when I try to read more bytes in the string (for example > 200 bytes) it never registers a read. The ser.inWaiting() also function also seems to always remain at 0, even if it does receive and print out a string. Currently I am only a reading incoming bytes. I have tried to write a command and then read the response but with no success. Any possible suggestions on what might be causing the reading issues? I have attached my code below (the functions that are commented out are all of the variations that I have tried already.
import time
import serial
print('Ready...')
#command =b'\xaa\x41\xa1\x06\x11\xa3'
ser = serial.Serial(
port ='/dev/rs232,
baudrate = 9600,
parity = serial.STOPBITS_ONE,
bytesize = serial.EIGHTBITS,
timeout = None #Some suggest increasing this timeout
)
ser.isOpen()
ser.setRTS(False)
ser.setDTR(False)
ser.flushInput()
ser.flushOutput()
#ser.write(command)
#print('sent')
#time.sleep(0.1)
#response=ser.read(6)
#print(response)
while 1:
#BytesToRead = ser.inWaiting() #Read amount of Bytes
#y = ser.read_until(size=None) #Read until byte string empty
x = ser.read().hex() #Read one byte
#z = ser.read(100).hex() #Read up to 100 bytes
#time.sleep(1) #Optional delay
print(x) #Print x, y or z
if BytesToRead > 0: #Test if ser.inWaiting sees multiple bytes
print('Hello')