I'm sending some data via uart. I take single file and split it into 5120byte parts(chunks). Between sending this chunks there is interruption (probably based on baudrate value) I need to catch this interruption and switch from sending data to receiving data. Is this possible this way ?
example code to send data :
ser = serial.Serial(
port='/dev/ttyS0',
baudrate=115200)
def send():
with open("path_to_my_file_to_send", "rb") as fh:
while True:
chunk = fh.read(5120)
if not chunk: break
ser.write(chunk)
def reveice():
global receivedData
receivedData = ""
time.sleep(0.001)
while ser.inWaiting() > 0:
receivedData= ser.read(1)
while True:
if len(receivedData ) == 1:
print ("received data")
break
else:
print("no received data")
break
So what you can do is send data from your send then wait for the recieve to send an acknowledgement. This way semd will know its data is successfully recieved and it can send new data then. If not than it can re transmit it or if it recieves the interrupt msg it can stop. At the send side u can recieve and then send acknowledgement. This acknowledgement could be length of the msgs which can be verified at the send side.