Repository navigation
Expand file tree
/
Copy pathvalidator.py
More file actions
56 lines (41 loc) · 1.53 KB
/
Copy pathvalidator.py
File metadata and controls
56 lines (41 loc) · 1.53 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
55
56
import serial
import time
import random
PORT = 'COM3' # Make sure this matches your Arduino!
BAUD_RATE = 115200
def run_validation():
print(f"--- STARTING NXP VALIDATION PROTOCOL ---")
try:
arduino = serial.Serial(PORT, BAUD_RATE, timeout=2)
print("Waiting for device boot...")
time.sleep(2)
passed = 0
failed = 0
for i in range(1, 51):
test_input = random.randint(0, 100)
expected = (test_input * 2) + 5
arduino.write(f"{test_input}\n".encode())
# We need to catch errors if reading fails
response = arduino.readline().decode().strip()
if response == str(expected):
print(f"Test #{i}: Input {test_input} -> Output {response} [PASS]")
passed += 1
else:
print(f"Test #{i}: Input {test_input} -> Output {response} [FAIL]")
failed += 1
time.sleep(0.05)
# --- KEY FIX IS HERE ---
# Notice these lines still have space (Tab) on the left.
# They are still inside the "try" safety net.
print("-" * 30)
print(f"RESULTS: {passed} PASSED, {failed} FAILED")
if failed == 0:
print("STATUS: SYSTEM VALIDATED")
else:
print("STATUS: BUGS FOUND...")
arduino.close()
# Now the 'except' lines up perfectly with the 'try'
except Exception as e:
print(f"CRITICAL ERROR: {e}")
if __name__ == "__main__":
run_validation()