mirror of
https://github.com/PotentiaRobotics/engine-software.git
synced 2025-04-09 23:00:21 -04:00
33 lines
573 B
Python
33 lines
573 B
Python
import socket
|
|
#!/usr/bin/env python
|
|
|
|
import serial
|
|
import time
|
|
|
|
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=2)
|
|
ser.flush()
|
|
|
|
host = ''
|
|
port = 2345
|
|
s = socket.socket()
|
|
s.bind((host, port))
|
|
s.listen(2)
|
|
while True:
|
|
conn, addr = s.accept()
|
|
print("Connected by", addr)
|
|
data = conn.recv(1024)
|
|
|
|
print("received data:", data)
|
|
# Get rid of garbage/incomplete data
|
|
|
|
|
|
# Infinite loop
|
|
|
|
ser.write(data)
|
|
time.sleep(0.01)
|
|
receive_string = ser.readline().decode('utf-8').rstrip()
|
|
print(receive_string)
|
|
|
|
conn.send(data)
|
|
conn.close()
|