-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathserialPort.py
More file actions
95 lines (70 loc) · 2.74 KB
/
Copy pathserialPort.py
File metadata and controls
95 lines (70 loc) · 2.74 KB
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
import threading
import schedule
from Connection.serialPortThread import SerialPortThread
from DataStructures.makesmithInitFuncs import MakesmithInitFuncs
class SerialPort(MakesmithInitFuncs):
"""
The SerialPort is an object which manages communication with the device over the serial port.
The actual connection is run in a separate thread by an instance of a SerialPortThread object.
"""
serialPortRequest = ""
# COMports = ListProperty(("Available Ports:", "None"))
def __init__(self):
"""
Runs on creation, schedules the software to attempt to connect to the machine
"""
schedule.every(5).seconds.do(self.openConnection)
def setPort(self, port):
"""
Defines which port the machine is attached to
"""
self.data.console_queue.put(port)
self.data.comport = port
def connect(self, *args):
"""
Forces the software to begin trying to connect on the new port.
This function may not be necessary, but it should stay in because it simplifies the user experience.
"""
self.data.config.setValue(
"Makesmith Settings", "COMport", str(self.data.comport)
)
"""
Serial Connection Functions
"""
def openConnection(self, *args):
# This function opens the thread which handles the input from the serial port
if not self.data.connectionStatus:
# self.data.ui_queue.put(
# "Action: connectionStatus:_" + json.dumps({'status': 'disconnected', 'port': 'none'})
# ) # the "_" facilitates the parse
self.data.ui_queue1.put(
"Action",
"connectionStatus",
{
"status": "disconnected",
"port": "none",
"fakeServoStatus": self.data.fakeServoStatus,
},
)
x = SerialPortThread()
x.data = self.data
self.th = threading.Thread(target=x.getmessage)
self.th.daemon = True
self.th.start()
else:
self.data.ui_queue1.put(
"Action",
"connectionStatus",
{
"status": "connected",
"port": self.data.comport,
"fakeServoStatus": self.data.fakeServoStatus,
},
)
# self.data.ui_queue.put(
# "Action: connectionStatus:_" + json.dumps({'status': 'connected', 'port': self.data.comport})
# ) # the "_" facilitates the parse
def closeConnection(self):
self.serialPortRequest = "requestToClose"
def getConnectionStatus(self):
return self.serialPortRequest