-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcollectArduino.py
35 lines (28 loc) · 1.01 KB
/
collectArduino.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
import serial
import time
import json
z1baudrate = 38400
z1port = '/dev/cu.usbmodem143301' # set the correct port before run it
z1serial = serial.Serial(port=z1port, baudrate=z1baudrate)
z1serial.timeout = 2 # set read timeout
# print z1serial # debug serial.
print(z1serial.is_open) # True for opened
if z1serial.is_open:
while True:
size = z1serial.inWaiting()
if size:
data = z1serial.read(size)
etattt = (str(data).split("'")[1].split("2")[1].split("4"))
etatt = etattt[1].split("6")
etat = [etattt[0]]+etatt
print(etat)
etats=[]
for i in range(len(etat)):
etats.append({'etat_'+str(i+1): etat[i]})
with open('/Users/matthiasprevost/Desktop/etats.json', 'w') as write_file: # enregistrer dans un fichier .json
json.dump(etats, write_file, ensure_ascii = False)
else:
print('no data')
time.sleep(2)
else:
print('z1serial not open')