32 lines
640 B
Python
32 lines
640 B
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Execute command on J1900 via serial console."""
|
||
|
|
import serial, time, sys
|
||
|
|
|
||
|
|
PORT = "/dev/ttyUSB0"
|
||
|
|
BAUD = 115200
|
||
|
|
|
||
|
|
def main():
|
||
|
|
if len(sys.argv) < 2:
|
||
|
|
print(f"Usage: {sys.argv[0]} <command>")
|
||
|
|
sys.exit(1)
|
||
|
|
|
||
|
|
cmd = " ".join(sys.argv[1:])
|
||
|
|
ser = serial.Serial(PORT, BAUD, timeout=0.5)
|
||
|
|
ser.reset_input_buffer()
|
||
|
|
|
||
|
|
ser.write((cmd + "\r").encode())
|
||
|
|
time.sleep(3)
|
||
|
|
|
||
|
|
out = b""
|
||
|
|
while True:
|
||
|
|
chunk = ser.read(4096)
|
||
|
|
if not chunk:
|
||
|
|
break
|
||
|
|
out += chunk
|
||
|
|
|
||
|
|
ser.close()
|
||
|
|
print(out.decode("utf-8", errors="replace"))
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|