irrigation_system/software/serial_reset_monitor.py

56 lines
1.7 KiB
Python

#!/usr/bin/env python3
import serial
import time
import sys
def monitor_serial_with_reset():
try:
# Open serial port
ser = serial.Serial('/dev/ttyACM1', 115200, timeout=1)
print("Serial port opened successfully")
# Clear any existing data
ser.flushInput()
ser.flushOutput()
# Send reset command
print("Sending reset command...")
ser.write(b"reset\n")
time.sleep(0.1)
# Read output for 10 seconds
print("Reading serial output...")
start_time = time.time()
output_lines = []
while time.time() - start_time < 10:
if ser.in_waiting > 0:
try:
line = ser.readline().decode('utf-8', errors='replace').strip()
if line:
print(f"[{time.time() - start_time:.3f}s] {line}")
output_lines.append(line)
except Exception as e:
print(f"Error reading line: {e}")
time.sleep(0.01)
ser.close()
print("\nSerial monitoring complete")
# Summary
print("\n=== SUMMARY ===")
supply_voltage_lines = [line for line in output_lines if "Supply voltage" in line]
if supply_voltage_lines:
print("Supply voltage readings:")
for line in supply_voltage_lines:
print(f" {line}")
else:
print("No supply voltage readings found")
except Exception as e:
print(f"Error: {e}")
sys.exit(1)
if __name__ == "__main__":
monitor_serial_with_reset()