I have written a UART py-serial script, which looks like.
import serial
import time
try:
ser = serial.Serial(
#port='/dev/ttyAMA0',
port='/dev/ttyUSB1',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=2
)
print ('Connection is open : ',str(ser.isOpen()))
except Exception as e:
print ("Something got wrong: ", e)
ser.write(b'hello..')
and have a similar script as receiver.
what I want is: suppose timeout = 5
ser.write(b'Helloo...')
ser.flush()
ser.readline()
the other script is reading it and sending a response via serial only. this readline should wait maximum for this timeout, if it received response in 2 seconds then it should not wait for 5seconds.
But using this timeout it waits for 2 seconds, even if the data is received in a second.
so my concern is to wait maximum for timeout, but if data received earlier it should end and proceed.
Not able to find this functionality, please help.