feat(mic): try1: setup sound with usb
This commit is contained in:
41
client/src/reveier.py
Normal file
41
client/src/reveier.py
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env python3
|
||||
import sys
|
||||
import time
|
||||
|
||||
import serial
|
||||
|
||||
# Настройки порта
|
||||
SERIAL_PORT = "/dev/ttyACM0"
|
||||
BAUD_RATE = 115200
|
||||
|
||||
|
||||
def read_serial_data():
|
||||
try:
|
||||
# Открытие порта. Timeout позволяет прерывать блокирующее чтение.
|
||||
ser = serial.Serial(SERIAL_PORT, BAUD_RATE, timeout=1)
|
||||
print(f"Connected to {SERIAL_PORT}")
|
||||
|
||||
while True:
|
||||
if ser.in_waiting > 0:
|
||||
# Чтение строки, декодирование и удаление пробелов
|
||||
line = ser.readline().decode("utf-8", errors="replace").strip()
|
||||
if line:
|
||||
print(f"[RX]: {line}")
|
||||
else:
|
||||
# Небольшая пауза, чтобы не грузить CPU ПК
|
||||
time.sleep(0.01)
|
||||
|
||||
except serial.SerialException as e:
|
||||
print(f"Error opening serial port: {e}")
|
||||
print(
|
||||
"Hint: Check if /dev/ttyACM0 exists and you have permissions (group uucp)."
|
||||
)
|
||||
except KeyboardInterrupt:
|
||||
print("\nExiting...")
|
||||
finally:
|
||||
if "ser" in locals() and ser.is_open:
|
||||
ser.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
read_serial_data()
|
||||
Reference in New Issue
Block a user