Files

32 lines
733 B
Python
Executable File

#!/usr/bin/env python3
"""Send commands to the DUT and print JSON responses.
Usage: dut_cmd.py PORT [--listen SECONDS] CMD [CMD...]
Each CMD is sent as a line; output is echoed for --listen seconds (default 3).
"""
import sys
import time
import serial
port = sys.argv[1]
args = sys.argv[2:]
listen = 3.0
if args and args[0] == "--listen":
listen = float(args[1])
args = args[2:]
s = serial.Serial(port, 115200, timeout=0.2)
time.sleep(0.2)
s.reset_input_buffer()
for cmd in args:
s.write((cmd + "\n").encode())
s.flush()
time.sleep(0.1)
end = time.time() + listen
while time.time() < end:
line = s.readline()
if line:
sys.stdout.write(line.decode(errors="replace"))
sys.stdout.flush()