-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor_usb.py
More file actions
29 lines (22 loc) · 841 Bytes
/
Copy pathmonitor_usb.py
File metadata and controls
29 lines (22 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
import time
import os
print("USB ESP32 Monitor - Press Ctrl+C to stop")
print("This will check if /dev/ttyACM0 exists every 0.1 seconds")
print("Times when device disappears will show the pattern")
count = 0
last_state = None
try:
while True:
exists = os.path.exists('/dev/ttyACM0')
current_time = time.time()
if exists != last_state:
state_str = "CONNECTED" if exists else "DISCONNECTED"
print(f"[{current_time:.3f}] {state_str}")
last_state = exists
count += 1
if count % 50 == 0: # Print alive signal every 5 seconds
print(f"[{current_time:.3f}] Monitoring... (state: {'UP' if exists else 'DOWN'})")
time.sleep(0.1)
except KeyboardInterrupt:
print("\nMonitoring stopped")