-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
87 lines (64 loc) · 2.61 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
from tkinter import *
import tkinter as tk
import comm as serial
import components
import time
import threading
from tkinter import Button, Tk
class MainWindow:
def __init__(self, master):
self.master = master
self.master.protocol("WM_DELETE_WINDOW", self.closeWindow)
self.master.resizable(0,0)
# Título de la ventana
self.master.title("CAN Sender-Receiver")
# Dimensión de la pantalla
# self.master.geometry("1230x466")
# self.master.attributes("-fullscreen", True)
self.thread2 = threading.Thread(name="read", target=self.readQueue)
# Se crea el objeto para la comunicación serial
self.comm = serial.Serial(self.thread2)
# Instancia la clase con los componentes que se verán en pantalla
self.components = components.Componentes(self.master, self.comm)
# Dibuja componentes
self.components.drawSelect()
self.components.drawValues(0)
self.components.drawTerminal()
# self.components.drawPortSelect(self.comm.getPorts())
self.components.drawButtons()
self.components.buttonStates()
self.drawButtons()
def closeWindow(self):
if self.comm.isConnected():
self.comm.closePort()
# self.thread2.join()
self.master.destroy()
def readQueue(self):
while self.comm.isConnected():
time.sleep(0.1)
# print('queueRead')
queueRead = self.comm.getQueue()
self.components.insertList(queueRead)
# self.components.insertTerminal(str(queueRead))
# self.components.insertTerminal('\n')
def datosEquipo(self):
self.components.insertList('')
def canSend(self):
commands = self.components.getValues()
arbitrationId = (commands[0] << 5) | commands[1]
dataLow = commands[2:6][::-1]
dataHigh = commands[6:10][::-1]
envio = dataLow + dataHigh
self.comm.sendCmd(arbitrationId, envio)
def drawButtons(self):
self.buttonFrame = Frame(self.master)
self.buttonFrame.grid(row=8, column=8, columnspan=2)
self.btnSend = Button(self.buttonFrame, text="Enviar", command=self.canSend)
self.btnSend.pack(side=TOP, padx=30, pady=10)
self.btnSend = Button(self.buttonFrame, text="Datos Equipo", command=self.datosEquipo)
self.btnSend.pack(side=TOP, padx=30, pady=10)
self.btnSend = Button(self.buttonFrame, text="Limpiar", command=self.components.clearList)
self.btnSend.pack(side=TOP, padx=30, pady=10)
root = Tk()
main = MainWindow(root)
root.mainloop()