-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRWSerial.py
More file actions
40 lines (34 loc) · 1004 Bytes
/
RWSerial.py
File metadata and controls
40 lines (34 loc) · 1004 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
33
34
35
36
37
38
39
40
import serial
import time
import json
arduino1 = serial.Serial(port='COM13', baudrate=9600, timeout=1)
def writeSerial(Text):
Text = json.dumps(Text)
arduino1.write(Text.encode(encoding='UTF-8'))
return Text
def readSerial():
Text = arduino1.readline()
Text = Text.decode()
try:
Text = json.loads(Text)
return Text
except:
return False
def doSomething(i):
Text = {"Geschwindigkeit": [1000, i*12, i], "Richtung":[1,1,-1]}
return Text
if __name__ == "__main__":
i = 0
while True:
if arduino1.isOpen():
Text = doSomething(i)
print("send: " + writeSerial(Text))
print("get: " + str(readSerial()))
# Values = readSerial()
# if Values != False:
# print(Values["Geschwindigkeit"])
# print(Values["Geschwindigkeit"][-1])
time.sleep(1)
else:
print("Nicht verbunden")
i += 1