"""Quick AT command terminal - minicom but less hostile. Usage: python at_terminal.py [port] Default port: /dev/ttyUSB2 (SIM7600 AT command interface) """ import sys import serial import threading PORT = sys.argv[1] if len(sys.argv) > 1 else "/dev/ttyUSB2" BAUD = 115200 def reader(ser): """Background thread: print everything the modem sends.""" while True: try: data = ser.read(ser.in_waiting or 1) if data: sys.stdout.write(data.decode("utf-8", errors="replace")) sys.stdout.flush() except Exception: break def main(): print(f"Opening {PORT} @ {BAUD} baud") print("Type AT commands. Ctrl+C to quit.\n") ser = serial.Serial(PORT, BAUD, timeout=0.1) t = threading.Thread(target=reader, args=(ser,), daemon=True) t.start() try: while True: line = input() ser.write((line + "\r\n").encode()) except (KeyboardInterrupt, EOFError): print("\nBye.") finally: ser.close() if __name__ == "__main__": main()