mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 10:22:02 +00:00
final test_ltc_serial.py
This commit is contained in:
parent
c0ec2f755c
commit
53565a8652
1 changed files with 7 additions and 12 deletions
|
|
@ -1,8 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import sys
|
|
||||||
if hasattr(sys.stdout, "reconfigure"):
|
|
||||||
sys.stdout.reconfigure(encoding='utf-8')
|
|
||||||
|
|
||||||
import serial
|
import serial
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
@ -16,10 +11,10 @@ ltc_pattern = re.compile(
|
||||||
)
|
)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print(f"🔌 Connecting to serial port: {SERIAL_PORT} @ {BAUD_RATE} baud")
|
print(f"[INFO] Connecting to serial port: {SERIAL_PORT} @ {BAUD_RATE} baud")
|
||||||
try:
|
try:
|
||||||
with serial.Serial(SERIAL_PORT, BAUD_RATE, timeout=1) as ser:
|
with serial.Serial(SERIAL_PORT, BAUD_RATE, timeout=1) as ser:
|
||||||
print("📡 Listening for LTC messages...\n")
|
print("[INFO] Listening for LTC messages...\n")
|
||||||
while True:
|
while True:
|
||||||
line = ser.readline().decode(errors='ignore').strip()
|
line = ser.readline().decode(errors='ignore').strip()
|
||||||
match = ltc_pattern.match(line)
|
match = ltc_pattern.match(line)
|
||||||
|
|
@ -27,16 +22,16 @@ def main():
|
||||||
status, timecode, framerate = match.groups()
|
status, timecode, framerate = match.groups()
|
||||||
framerate = framerate.upper()
|
framerate = framerate.upper()
|
||||||
if status == "LOCK":
|
if status == "LOCK":
|
||||||
print(f"🔒 {status:<4} | ⏱ {timecode} | 🎞 {framerate}")
|
print(f"[LOCK] {status:<4} | Timecode: {timecode} | Rate: {framerate}")
|
||||||
else:
|
else:
|
||||||
print(f"🟡 {status:<4} | ⏱ {timecode} | 🎞 {framerate}")
|
print(f"[FREE] {status:<4} | Timecode: {timecode} | Rate: {framerate}")
|
||||||
else:
|
else:
|
||||||
if line:
|
if line:
|
||||||
print(f"⚠️ Unrecognised line: {line}")
|
print(f"[WARN] Unrecognised line: {line}")
|
||||||
except serial.SerialException as e:
|
except serial.SerialException as e:
|
||||||
print(f"❌ Serial error: {e}")
|
print(f"[ERROR] Serial error: {e}")
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\n🛑 Stopped by user.")
|
print("\n[EXIT] Stopped by user.")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue