-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
159 lines (127 loc) · 4.13 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import serial
from tkinter import *
# import sys
import numpy as np
import re
# import string
premierMarqu = False
m = np.zeros(50, float)
marqueur = "ANG"
marqueurs = [["DCM", "ANG", "AN", "THI"], ['X', 'Y', 'Z', "MX", "MY", "MZ", "?X", "?Y", "?Z"],
["Roll:Roulis", "Pitch:Elevation", "Yaw:Lacet"],
["Accel X", "Accel Y", "Accel Z", "Gyro X", "Gyro Y", "Gyro Z", "Magnetom X", "Magnetom Y"
, "Magnetom Z"],
["Accel X", "Accel Y", "Accel Z", "Gyro X", "Gyro Y", "Gyro Z", "Magnetom X", "Magnetom Y", "Magnetom Z",
"TEMP:"]]
elementsaFiltrer = ["n", 'r', 'b', "\\", "'", ",DCM:", ",THI:", "TMP:,", ",AN", "C", "M", ":"]
entete = []
RawData = "" # variable contenant la ligne envoyé par le port serie
curs = 0 # curseur qui pointe les données entre les marqueurs
# lit les données
def tempo():
global RawData
global premierMarqu
global marqueur
if premierMarqu:
decodeserial()
else:
while marqueur not in str(RawData):
RawData = ser.readline()
# #print("not flushed")
premierMarqu = True # premiers élements parasites filtrés
RawData = ser.readline()
print("Donnees :", RawData) # ##print a string
placevaleurs()
root.after(1, tempo)
def decodeserial():
global curs
global RawData
global m
# lstDat = str(RawData).split(',')
floatArray = []
# epurSplit = "0"
# sommeFloat = 0
# #print (lstDat)
print("chaine épurée", epurchaine2())
epurSplit = epurchaine2().split(',')
for n in range(len(np.asarray(epurSplit))):
n = n
# #print("chaine splitéé",np.asarray(epurSplit)[n])
if np.asarray(epurSplit)[0] != '':
try:
floatArray = np.asarray(epurSplit).astype(float)
# #print("len",len(floatArray))
except:
print("erreur")
else:
return
# #print("len",len(floatArray))
for z in range((len(floatArray))):
m[z] = floatArray[z]
# #print("index",z,"curs",curs,"m ",m)
# #print(len(floatArray))
curs += 1
def epurchaine2():
global elementsaFiltrer
global RawData
chepur = str(RawData)
chepur = re.sub('[^0-9,.-]', '', chepur)
chepur = re.sub('^[,]', '', chepur)
chepur = re.sub('[,]$', '', chepur)
chepur = re.sub("[,]{2}", ',', chepur)
# for d in elementsaFiltrer:
# chepur = chepur.replace(d, "")
print("chepur2", chepur)
# chepur = chepur.replace(" ",",")#mets une virgule entre les chaines
return chepur
def placevaleurs():
global m
global vars
for f in range(len(m)):
vars[f % 9].set(m[f % 9])
def on_closing():
ser.close() # close port
root.destroy()
# Les Initialisations
# Port serie
ser = serial.Serial('/dev/ttyUSB0') # open serial port
ser.baudrate = 115200
# #print(ser.name) # check which port was really used
# premiere lecture du port serie pour dimensionner la fenetre.
# noinspection SyntaxErrro
if not premierMarqu:
while marqueur not in str(RawData):# a MODIFIER
RawData = ser.readline()
# #print("not flushed")
premierMarqu = True # premiers élements parasites filtrés
print(str(RawData))
for t in range(4):
for i, y in enumerate(marqueurs[0]):
print("cherche", y, i)
if (y in str(RawData)) and y != "":
print("trouvé", str(RawData).find(y))
for t in marqueurs[i + 1]:
entete.append(t)
marqueurs[0][i] = ""
RawData = ser.readline()
print(entete, marqueurs[0])
# Fenetre d'affichage
root = Tk()
root.title("Matrice DCM")
r = 0
vars = []
text = StringVar()
for col, item in enumerate(['X', 'Y', 'Z', "MX", "MY", "MZ", "?X", "?Y", "?Z"]):
vars.append(StringVar())
l = Label(root, text=item, width=10)
e = Label(root, textvariable=vars[-1], width=10)
l.grid(row=(col % 3), column=(col // 3) * 2)
e.grid(row=(col % 3), column=((col // 3) * 2) + 1)
# boucle d'événement sur tempo
root.after(30, tempo)
root.protocol("WM_DELETE_WINDOW", on_closing)
# boucle principale
root.mainloop()
ser.close() # close port
for i, j in enumerate(marqueur):
print(j)