Files
mcp_screen/scratch/reboot_and_read.py
T

40 lines
1.0 KiB
Python

import serial
import time
import sys
def main():
port = "/dev/cu.usbmodem411CF91D65091"
print(f"Connecting to {port} at 115200...")
try:
ser = serial.Serial(port, 115200, timeout=1.0)
except Exception as e:
print(f"Error: {e}")
return
print("Sending Ctrl-C to interrupt...")
ser.write(b'\x03')
time.sleep(0.5)
print("--- Current buffer contents ---")
print(ser.read_all().decode("utf-8", "ignore"))
print("Sending Ctrl-D to trigger soft reboot...")
ser.write(b'\x04')
print("--- Capturing boot output (10 seconds) ---")
start_time = time.time()
try:
while time.time() - start_time < 10.0:
if ser.in_waiting > 0:
data = ser.read(ser.in_waiting)
sys.stdout.write(data.decode("utf-8", "ignore"))
sys.stdout.flush()
time.sleep(0.05)
except KeyboardInterrupt:
pass
finally:
ser.close()
print("\nConnection closed.")
if __name__ == "__main__":
main()