Initial commit

This commit is contained in:
2025-12-24 19:49:58 +03:00
commit 2cde55d401
16 changed files with 939 additions and 0 deletions

40
tests/test_device.py Normal file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/env python3
import threading
import time
import serial
PORT = "/dev/ttyACM0"
BAUDRATE = 115200
def read_from_port(ser):
while True:
if ser.in_waiting > 0:
data = ser.read(ser.in_waiting)
print(f"Received: {data.decode('utf-8', errors='ignore')}")
try:
ser = serial.Serial(PORT, BAUDRATE, timeout=1)
print(f"Connected to {PORT}")
# Запускаем чтение в фоне
thread = threading.Thread(target=read_from_port, args=(ser,), daemon=True)
thread.start()
# Пишем данные
counter = 0
while True:
msg = f"Ping {counter}\n"
ser.write(msg.encode("utf-8"))
print(f"Sent: {msg.strip()}")
counter += 1
time.sleep(1)
except serial.SerialException as e:
print(f"Error: {e}")
except KeyboardInterrupt:
print("\nExiting...")
if "ser" in locals() and ser.is_open:
ser.close()