From 8abf2a81bf885f984020da569ec824989ec52c98 Mon Sep 17 00:00:00 2001 From: Chris Frankland-Wright <85807217+cjfranko@users.noreply.github.com> Date: Mon, 7 Jul 2025 19:53:48 +0100 Subject: [PATCH] Create test_ltc_serial.py --- test_ltc_serial.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test_ltc_serial.py diff --git a/test_ltc_serial.py b/test_ltc_serial.py new file mode 100644 index 0000000..dc4d9f0 --- /dev/null +++ b/test_ltc_serial.py @@ -0,0 +1,34 @@ +import serial +import re + +# Adjust this as needed +SERIAL_PORT = "/dev/ttyACM0" +BAUD_RATE = 115200 + +# Regex pattern to match: [LOCK] 10:00:00:00 | 24.00FPS +ltc_pattern = re.compile(r"\[(LOCK|FREE)\]\s+(\d{2}:\d{2}:\d{2}:\d{2})\s+\|\s+([\d.]+FPS)") + +def main(): + print(f"šŸ”Œ Connecting to serial port: {SERIAL_PORT} @ {BAUD_RATE} baud") + try: + with serial.Serial(SERIAL_PORT, BAUD_RATE, timeout=1) as ser: + print("šŸ“” Listening for LTC messages...\n") + while True: + line = ser.readline().decode(errors='ignore').strip() + match = ltc_pattern.match(line) + if match: + status, timecode, framerate = match.groups() + if status == "LOCK": + print(f"šŸ”’ {status} | ā± {timecode} | šŸŽž {framerate}") + else: + print(f"🟔 {status} | ā± {timecode} | šŸŽž {framerate}") + else: + if line: + print(f"āš ļø Unrecognised line: {line}") + except serial.SerialException as e: + print(f"āŒ Serial error: {e}") + except KeyboardInterrupt: + print("\nšŸ›‘ Stopped by user.") + +if __name__ == "__main__": + main()