From b62f6b536a2df49b759c1eecd484108d03b1f2d6 Mon Sep 17 00:00:00 2001 From: nearology Date: Mon, 9 Nov 2026 20:19:52 +0330 Subject: [PATCH] init --- scripts/serial_command.py | 67 +++++++++++++++++++++++++++++++++++++++ workflows/serial.yml | 16 ++++++++++ 2 files changed, 83 insertions(+) create mode 100644 scripts/serial_command.py create mode 100644 workflows/serial.yml diff --git a/scripts/serial_command.py b/scripts/serial_command.py new file mode 100644 index 0000000..003f8eb --- /dev/null +++ b/scripts/serial_command.py @@ -0,0 +1,67 @@ +import serial +import sys +import time + +PORT = "/dev/ttyUSB0" +BAUDRATE = 115200 +TIMEOUT = 2 +MAX_WAIT = 10 + +COMMAND = "bdinfo" + +try: + with serial.Serial( + port=PORT, + baudrate=BAUDRATE, + timeout=0.2, + write_timeout=TIMEOUT + ) as ser: + + print(f"Connected to {PORT}", flush=True) + + # Clear old serial data + ser.reset_input_buffer() + + # Send command to U-Boot + ser.write((COMMAND + "\r").encode()) + ser.flush() + + print(f"Command sent: {COMMAND}", flush=True) + print("------ U-Boot Response ------", flush=True) + + response = bytearray() + start_time = time.monotonic() + last_data_time = start_time + + while time.monotonic() - start_time < MAX_WAIT: + + if ser.in_waiting: + data = ser.read(ser.in_waiting) + response.extend(data) + + # Print response in real time + print( + data.decode("utf-8", errors="replace"), + end="", + flush=True + ) + + last_data_time = time.monotonic() + + # Stop when no new data arrives for 2 seconds + if response and time.monotonic() - last_data_time > TIMEOUT: + break + + time.sleep(0.05) + + print("\n-----------------------------") + + if not response: + print("ERROR: No response from U-Boot") + sys.exit(1) + + print("Command completed successfully") + +except serial.SerialException as e: + print(f"Serial error: {e}") + sys.exit(1) diff --git a/workflows/serial.yml b/workflows/serial.yml new file mode 100644 index 0000000..1c96f44 --- /dev/null +++ b/workflows/serial.yml @@ -0,0 +1,16 @@ +name: U-Boot Serial Command + +on: + workflow_dispatch: + +jobs: + uboot-command: + runs-on: serial-runner + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Execute U-Boot bdinfo + run: | + ~/serial-venv/bin/python scripts/serial_command.py