-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtest_serial_commands.py
More file actions
executable file
·54 lines (43 loc) · 1.45 KB
/
test_serial_commands.py
File metadata and controls
executable file
·54 lines (43 loc) · 1.45 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
"""
Test script to debug serial communication with ESP32
"""
import serial
import sys
import time
PORT = "/dev/ttyACM0"
BAUD = 921600
def main():
print(f"Connecting to {PORT} at {BAUD} baud...")
try:
ser = serial.Serial(PORT, BAUD, timeout=2)
time.sleep(0.5)
ser.reset_input_buffer()
ser.reset_output_buffer()
print("Connected! Sending LIST_FILES command...")
ser.write(b"LIST_FILES\n")
time.sleep(0.1)
print("\nWaiting for response (10 seconds)...\n")
start = time.time()
while time.time() - start < 10:
if ser.in_waiting > 0:
line = ser.readline().decode('ascii', errors='ignore').rstrip()
if line:
print(f"RX: {repr(line)}")
print("\n\nSending GET_LOG_FILENAME command...")
ser.write(b"GET_LOG_FILENAME\n")
time.sleep(0.1)
print("\nWaiting for response (5 seconds)...\n")
start = time.time()
while time.time() - start < 5:
if ser.in_waiting > 0:
line = ser.readline().decode('ascii', errors='ignore').rstrip()
if line:
print(f"RX: {repr(line)}")
ser.close()
print("\n\nDone!")
except serial.SerialException as e:
print(f"Serial error: {e}")
sys.exit(1)
if __name__ == "__main__":
main()