comm.py (549B)
1import serial 2import sys 3 4def readcmd(): 5 while True: 6 line = ser.readline().strip().decode() 7 if len(line) > 0: 8 print("<", line) 9 if line[0] == '!': 10 break 11 return line 12 13def sendcmd(line): 14 print(">", line) 15 ser.write(line.encode() + b"\r") 16 17with serial.Serial(sys.argv[1], 9600, timeout=1) as ser: 18 sendcmd("!INIT") 19 assert(readcmd() == "!OK") 20 21 while True: 22 line = readcmd() 23 assert(line == "!FLAG") 24 sendcmd("!OK") 25 sendcmd("ENO{S4f3_Cr4cKd}")