import string import serial import time port = serial.Serial(port='COM3', baudrate=2400, bytesize=8, parity='N', stopbits=1) for c in string.ascii_uppercase: for n in range(100): d = c+f"{n:02d}" port.write((d+chr(13)).encode()) port.flush() r = port.read_all().decode('ascii').rstrip() print(f"{d} : {r}", sep='^H') if 'NAK' not in r: print() time.sleep(0.1)