7 def read_and_respond():
10 ser = serial.Serial(port, baudrate=9600, timeout=0.1)
11 print("Serial port",port,"opened successfully.")
12 except serial.SerialException as e:
13 print("Error opening the serial port ",port,":", e)
17 # Read 4 bytes from the serial port
18 read_bytes = ser.read(size=4)
20 if len(read_bytes) == 0:
23 if read_bytes == b"\x14\x82\x80\x81":
24 response = b"\x54\x82\x80\x81"
25 elif read_bytes == b"\x14\x81\x80\x81":
26 response = b"\x54\x81\x80\x81"
29 #response = b"\xDE\xAD\xBE\xEF"
30 print("ERROR no reponse for", read_bytes.hex())
32 # Send the response back
35 print("<<", read_bytes.hex(), ">>", response.hex())
37 if __name__ == "__main__":