27 lines
696 B
Python
27 lines
696 B
Python
import serial
|
|
import time
|
|
|
|
try:
|
|
puerto = serial.Serial('/dev/ttyAMA0', 921600, timeout=0.1)
|
|
print("Puerto abierto correctamente.")
|
|
|
|
# Limpiar buffer
|
|
puerto.reset_input_buffer()
|
|
|
|
# Enviar comando de adelante al 20%
|
|
print("Enviando comando: A:0.200,0.200,0.200,0.200")
|
|
puerto.write(b"A:0.200,0.200,0.200,0.200\n")
|
|
|
|
t_end = time.time() + 2.0
|
|
while time.time() < t_end:
|
|
if puerto.in_waiting:
|
|
line = puerto.readline().decode('utf-8', errors='ignore').strip()
|
|
print("RX:", line)
|
|
|
|
# Detener
|
|
puerto.write(b"S:\n")
|
|
print("Comando S (stop) enviado.")
|
|
|
|
except Exception as e:
|
|
print("Error:", e)
|