-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_pos.py
More file actions
32 lines (30 loc) · 814 Bytes
/
read_pos.py
File metadata and controls
32 lines (30 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import serial
import time
import json
import redis
r = redis.Redis(host='localhost', port=6379, db=0)
DWM = serial.Serial(port="/dev/ttyACM1", baudrate=115200)
print("Connected to " + DWM.name)
DWM.write("\r\r".encode())
print("Encode")
time.sleep(1)
DWM.write("lec\r".encode())
print("Encode")
time.sleep(1)
try:
while True:
data = DWM.readline()
if(data):
data=data.decode()
print(data)
if("nan" not in data and "POS" in data):
data = data.replace("\r\n","")
data = data.split(",")
pos = {"x": data[3], "y": data[4]}
print(pos)
pos = json.dumps(pos)
r.set(data[2],pos)
DWM.write("\r".encode())
DWM.close()
except KeyboardInterrupt:
print("Stop")