mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
Create test_ltc_serial.py
This commit is contained in:
parent
4319ee4fde
commit
8abf2a81bf
1 changed files with 34 additions and 0 deletions
34
test_ltc_serial.py
Normal file
34
test_ltc_serial.py
Normal file
|
|
@ -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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue