-
Notifications
You must be signed in to change notification settings - Fork 0
/
wek.py
49 lines (40 loc) · 1.18 KB
/
wek.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import serial
ser = serial.Serial('/dev/ttyACM0',9600)
ser.flushInput()
#serSend = serial.Serial('/dev/ttyACM0',14400)
#import argparse
import random
import time
import math
from pythonosc import osc_message_builder
from pythonosc import udp_client
weki = udp_client.SimpleUDPClient("127.0.0.1", 6448)
#weki = udp_client.SimpleUDPClient("127.0.0.1", 6448)
# used in checking who sent serial msg
def is_number(s):
if not s:
return False
try:
float(s)
return True
except ValueError:
return False
run = 1
while run:
#if ser.readline():
raw = ser.readline().decode()
#print(raw);
# if incoming isn't array of vals, ignore
if raw[0] != '[':
print(raw, 'not arr')
else:
print('array')
vals = raw.replace('\r', '').replace('\n','')
vals = vals.replace('[','').replace(']','').replace('\r', '').replace('\n','')
vals = vals.split(',')
for i in range(len(vals)):
vals[i] = float(vals[i])#
print(vals)
weki.send_message("/wek/inputs", vals )
# else:
# print('no serial')