Files
scanengine-3/helios_terminal.py
T
Thomas Ales [M S E] a0e0151b5d pre uc480 integration
2026-05-22 09:38:39 -05:00

72 lines
1.8 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Simple serial terminal for manual Helios laser testing.
Allows sending raw commands and viewing responses.
"""
import serial
import sys
from threading import Thread
import time
def read_from_port(ser):
"""Read data from serial port and display it."""
while True:
try:
if ser.in_waiting:
data = ser.read(ser.in_waiting)
print(f"\n[RX] {data.decode('ascii', errors='replace')}", end='')
sys.stdout.flush()
except:
break
time.sleep(0.01)
def main():
"""Run interactive serial terminal."""
port = "/dev/ttyUSB2"
if len(sys.argv) > 1:
port = sys.argv[1]
try:
ser = serial.Serial(
port=port,
baudrate=9600,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=0.1
)
print(f"Connected to {port} at 9600 baud")
print("Type commands and press Enter. Type 'quit' to exit.\n")
# Start reader thread
reader_thread = Thread(target=read_from_port, args=(ser,), daemon=True)
reader_thread.start()
while True:
try:
user_input = input("[TX] ")
if user_input.lower() == 'quit':
break
# Send command with carriage return
command = user_input + '\r'
ser.write(command.encode('ascii'))
time.sleep(0.1)
except KeyboardInterrupt:
break
except Exception as e:
print(f"Error: {e}")
ser.close()
print("\nDisconnected")
except Exception as e:
print(f"Failed to open {port}: {e}")
sys.exit(1)
if __name__ == "__main__":
main()