-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
61 lines (49 loc) · 1.46 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
from tkinter import *
import serial
try:
connexion = serial.Serial('COM3', 9600)
print("connexion réussit")
except Exception as error:
print(error)
exit()
distanceActuel = 4
limit = 0
affichage = ""
def lecture():
data = connexion.readline().decode()
print(data)
rep = data.split(" ")
data = data[:-1]
if rep[0] == "IN":
libelleInfo.configure(text="Dans la limite", fg='green')
distanceActuel = rep[1]
libelleDistance.configure(text='Distance actuelle: ' + str(distanceActuel) + ' cm')
if rep[0] == "OUT":
libelleInfo.configure(text="En dehors de la limite", fg='red')
distanceActuel = rep[1]
libelleDistance.configure(text='Distance actuelle: ' + str(distanceActuel) + ' cm')
connexion.flush()
def clicked():
connexion.write(bytes("#" + entrySet.get(), 'utf-8'))
print(bytes("#" + entrySet.get(), 'utf-8'))
window = Tk()
window.title('recording')
libelleSet = Label(window, text="Distance limit:")
libelleSet.grid(column=0, row=0)
entrySet = Entry(window, textvariable=limit)
entrySet.grid(column=0, row=1)
btnSet = Button(window, text="Envoyer", command=clicked)
btnSet.grid(column=0, row=2)
libelleDistance = Label(window, text='')
libelleDistance.grid(column=0, row=3)
libelleInfo = Label(window, text='')
libelleInfo.grid(column=0, row=4)
window.update()
try:
connexion.open()
except Exception as error:
pass
while True:
lecture()
window.update()
connexion.close()