import serial import threading import time import sys REAL_PORT = "COM5" # MiniMate hardware VIRTUAL_PORT = "COM4" # Bridge side of COM3<->COM4 pair BAUD = 38400 def hex_dump(data): return " ".join(f"{b:02X}" for b in data) def forward(src, dst, label): while True: try: data = src.read(1024) # blocking read if data: print(f"[{label}] {hex_dump(data)}") dst.write(data) except serial.SerialException as e: print(f"[{label}] Serial error: {e}") break except Exception as e: print(f"[{label}] Unexpected error: {e}") break def main(): print("Opening ports...") real = serial.Serial( REAL_PORT, BAUD, timeout=0.1, # IMPORTANT: not zero write_timeout=0.1 ) virt = serial.Serial( VIRTUAL_PORT, BAUD, timeout=0.1, write_timeout=0.1 ) print(f"Connected: {REAL_PORT} <-> {VIRTUAL_PORT}") t1 = threading.Thread(target=forward, args=(virt, real, "BLASTWARE -> S3"), daemon=True) t2 = threading.Thread(target=forward, args=(real, virt, "S3 -> BLASTWARE"), daemon=True) t1.start() t2.start() try: while True: time.sleep(1) except KeyboardInterrupt: print("Stopping bridge...") real.close() virt.close() sys.exit(0) if __name__ == "__main__": main()