fts-can/Tools/lifecycle_test.py

34 lines
1.2 KiB
Python
Raw Normal View History

2024-06-24 16:12:03 +00:00
from datetime import datetime
2024-06-24 15:48:55 +00:00
import serial
import time
# Serial Port Configuration
port = '/dev/ttyUSB0' # Replace with your actual serial port (e.g., 'COM3' on Windows)
baudrate = 57600 # Replace with your desired baud rate
timeout = 1 # Optional timeout for read operations (in seconds)
2024-06-24 16:12:03 +00:00
datetime_format = '%Y-%m-%d %H:%M:%S'
NUM_CYCLES = 150000
2024-06-24 15:48:55 +00:00
# Serial Connection Setup
try:
ser = serial.Serial(port, baudrate, timeout=timeout)
print(f"Connected to serial port: {port}")
ser.write("fts arm\n".encode()) # Encode string to bytes for transmission
print(f"Sent ARM")
cnt = 0
while cnt < NUM_CYCLES:
ser.write("fts fire\n".encode()) # Encode string to bytes for transmission
2024-06-24 16:12:03 +00:00
current_time = datetime.now().strftime(datetime_format)
print(f"{current_time} Sent FIRE # {cnt}")
2024-06-24 15:48:55 +00:00
time.sleep(1) # Wait for 1 second
ser.write("fts reset\n".encode()) # Encode string to bytes for transmission
2024-06-24 16:12:03 +00:00
current_time = datetime.now().strftime(datetime_format)
print(f"{current_time} Sent RESET")
2024-06-24 15:48:55 +00:00
time.sleep(1) # Wait for 1 second
cnt+=1
print("----------TEST FINISHED----------")
except serial.SerialException as e:
print(f"Error opening serial port: {e}")