40 lines
1.0 KiB
Python
40 lines
1.0 KiB
Python
#!/usr/bin/env python3
|
|
import serial
|
|
import time
|
|
import sys
|
|
|
|
def monitor_serial():
|
|
try:
|
|
# Open serial connection
|
|
ser = serial.Serial('/dev/ttyACM3', 115200, timeout=1)
|
|
print("Connected to /dev/ttyACM3")
|
|
|
|
# Send reset command
|
|
ser.write(b'reset\n')
|
|
print("Sent reset command")
|
|
|
|
# Wait a bit and then read output
|
|
time.sleep(0.5)
|
|
|
|
# Read output for 10 seconds
|
|
start_time = time.time()
|
|
while time.time() - start_time < 10:
|
|
if ser.in_waiting > 0:
|
|
data = ser.read(ser.in_waiting)
|
|
try:
|
|
text = data.decode('utf-8', errors='ignore')
|
|
print(text, end='')
|
|
except:
|
|
print(f"Raw bytes: {data}")
|
|
time.sleep(0.1)
|
|
|
|
ser.close()
|
|
print("\nSerial monitor closed")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
sys.exit(1)
|
|
|
|
if __name__ == "__main__":
|
|
monitor_serial()
|