-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFisnarOutputDevicePlugin.py
More file actions
95 lines (75 loc) · 4.67 KB
/
FisnarOutputDevicePlugin.py
File metadata and controls
95 lines (75 loc) · 4.67 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 time
from cura.CuraApplication import CuraApplication
from UM.Logger import Logger
from UM.Message import Message
from UM.OutputDevice.OutputDevicePlugin import OutputDevicePlugin
from .FisnarOutputDevice import FisnarOutputDevice
from .FisnarRobotExtension import FisnarRobotExtension
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
class FisnarOutputDevicePlugin(OutputDevicePlugin):
# this class manages the FisnarOutputDevice instance which is used to control
# the fisnar via RS232 printing and manual control (and pick and place). As
# the FisnarOutputDevice class also holds an UltimusV instance for dispenser
# control, this class also manages the UltimusV instance
#
# The UltimusV does not have it's own output device manager class because
# by its own, it can't do anything with slicer output - it is merely a peripheral
# used by the Fisnar. In order to execute pick and place manuevers, however, it must
# be controled independently over RS232, so this class also manages that connection
def __init__(self):
super().__init__()
if FisnarOutputDevicePlugin._instance is not None:
Logger.log("e", "FisnarOutputDevicePlugin instantiated more than once")
FisnarOutputDevicePlugin._instance = self
self._check_updates = True # for controlling while loop in _updateThread
self._update_thread = threading.Thread(target=self._updateThread, name="FisnarRobotPlugin Serial Finder")
self._update_thread.daemon = True # constantly checks for serial connections until shutdown
self._fisnar_port_name = None # type: str, the name of the serial port from FisnarRobotExtension
self._application = CuraApplication.getInstance()
self._fre_instance = FisnarRobotExtension.getInstance()
self._dispenser_manager = self._fre_instance.getDispenserManager()
def start(self):
# start checking for serial port updates
Logger.log("i", "FisnarOutputDevicePlugin instance starting...")
# creating FisnarOutputDevice
self.getOutputDeviceManager().addOutputDevice(FisnarOutputDevice())
# initializing com port name
self._fisnar_port_name = self._fre_instance.com_port
# start update thread to find open serial ports
self._check_updates = True
self._update_thread.start()
def stop(self):
# stop checking for serial port updates
Logger.log("i", "FisnarOutputDevicePlugin instance stopping...")
self._check_updates = False # stops while loop in _updateThread
self.getOutputDeviceManager().getOutputDevice("fisnar_f5200n").close()
self.getOutputDeviceManager().removeOutputDevice("fisnar_f5200n")
self._dispenser_manager.closeAll()
def _updateThread(self):
# try to connect to fisnar and dispenser serial port every 10 seconds if they aren't already connected
while self._check_updates:
self._fisnar_port_name = self._fre_instance.com_port
self.getOutputDeviceManager().getOutputDevice("fisnar_f5200n").fisnarPortNameUpdated.emit()
# TODO: put dispenser ports in manual control ui and emit signal here - basically the above line but for the dispensers
if not self.getOutputDeviceManager().getOutputDevice("fisnar_f5200n").isConnected(): # if fisnar port not connected, try to.
if self._fisnar_port_name not in (None, "None"):
self.getOutputDeviceManager().getOutputDevice("fisnar_f5200n").connect(self._fisnar_port_name)
if self.getOutputDeviceManager().getOutputDevice("fisnar_f5200n").isConnected():
fis_msg = Message(text = catalog.i18nc("@message", "Fisnar F5200N successfully connected via: " + str(self._fisnar_port_name)),
title = catalog.i18nc("@message", "Connection Status Update"))
fis_msg.show()
for dispenser in self._dispenser_manager.getDispensers():
if not dispenser.isConnected() and dispenser.available.is_set():
if dispenser.getComPort() not in (None, "None"):
dispenser.connect()
if dispenser.isConnected():
disp_msg = Message(text = catalog.i18nc("@message", f"UltimusV dispenser '{dispenser.name}' successfully connected via: {dispenser.getComPort()}"),
title = catalog.i18nc("@message", "Connection Status Update"))
disp_msg.show()
time.sleep(3)
_instance = None
@classmethod
def getInstance(cls):
return cls._instance