mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
backend of usb printing now works
This commit is contained in:
parent
208e9d28bf
commit
4de4273966
2 changed files with 80 additions and 21 deletions
|
@ -13,14 +13,21 @@ class USBPrinterManager(SignalEmitter,PluginObject):
|
|||
super().__init__()
|
||||
self._serial_port_list = []
|
||||
self._printer_connections = []
|
||||
|
||||
self._check_ports_thread = threading.Thread(target=self._updateConnectionList)
|
||||
self._check_ports_thread.daemon = True
|
||||
self._check_ports_thread.start()
|
||||
time.sleep(2)
|
||||
self.connectAllConnections()
|
||||
|
||||
## DEBUG CODE
|
||||
#time.sleep(1)
|
||||
#self._printer_connections[0]._sendCommand("M109")
|
||||
#self.connectAllConnections()
|
||||
#time.sleep(5)
|
||||
#f = open("Orb.gcode")
|
||||
#lines = f.readlines()
|
||||
#print(len(lines))
|
||||
#print(len(self._printer_connections))
|
||||
#self.sendGCodeToAllActive(lines)
|
||||
#print("sending heat " , self.sendCommandToAllActive("M104 S190"))
|
||||
|
||||
|
||||
## Check all serial ports and create a PrinterConnection object for them.
|
||||
# Note that this does not validate if the serial ports are actually usable!
|
||||
|
@ -28,6 +35,7 @@ class USBPrinterManager(SignalEmitter,PluginObject):
|
|||
def _updateConnectionList(self):
|
||||
while True:
|
||||
temp_serial_port_list = self.getSerialPortList(only_list_usb = True)
|
||||
print(temp_serial_port_list)
|
||||
if temp_serial_port_list != self._serial_port_list: # Something changed about the list since we last changed something.
|
||||
disconnected_ports = [port for port in self._serial_port_list if port not in temp_serial_port_list ]
|
||||
self._serial_port_list = temp_serial_port_list
|
||||
|
@ -42,14 +50,58 @@ class USBPrinterManager(SignalEmitter,PluginObject):
|
|||
self._printer_connections.remove(connection)
|
||||
time.sleep(5) #Throttle, as we don't need this information to be updated every single second.
|
||||
|
||||
## Attempt to connect with all possible connections.
|
||||
def connectAllConnections(self):
|
||||
print("DERP DERP")
|
||||
for connection in self._printer_connections:
|
||||
print("connection ",connection)
|
||||
connection.connect()
|
||||
|
||||
|
||||
## send gcode to printer and start printing
|
||||
def sendGCodeByPort(self, serial_port, gcode_list):
|
||||
printer_connection = self.getConnectionByPort(serial_port)
|
||||
if printer_connection is not None:
|
||||
printer_connection.printGCode(gcode_list)
|
||||
return True
|
||||
return False
|
||||
|
||||
## Send gcode to all active printers.
|
||||
# \return True if there was at least one active connection.
|
||||
def sendGCodeToAllActive(self, gcode_list):
|
||||
for printer_connection in self.getActiveConnections():
|
||||
printer_connection.printGCode(gcode_list)
|
||||
if len(self.getActiveConnections()):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
## Send a command to a printer indentified by port
|
||||
# \param serial port String indentifieing the port
|
||||
# \param command String with the g-code command to send.
|
||||
# \return True if connection was found, false otherwise
|
||||
def sendCommandByPort(self, serial_port, command):
|
||||
printer_connection = self.getConnectionByPort(serial_port)
|
||||
if printer_connection is not None:
|
||||
printer_connection.sendCommand(command)
|
||||
return True
|
||||
return False
|
||||
|
||||
## Send a command to all active (eg; connected) printers
|
||||
# \param command String with the g-code command to send.
|
||||
# \return True if at least one connection was found, false otherwise
|
||||
def sendCommandToAllActive(self, command):
|
||||
for printer_connection in self.getActiveConnections():
|
||||
printer_connection.sendCommand(command)
|
||||
if len(self.getActiveConnections()):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
## Get a list of printer connection objects that are connected.
|
||||
def getActiveConnections(self):
|
||||
return [connection for connection in self._printer_connections if connection.isConnected()]
|
||||
|
||||
##
|
||||
## get a printer connection object by serial port
|
||||
def getConnectionByPort(self, serial_port):
|
||||
for printer_connection in self._printer_connections:
|
||||
if serial_port == printer_connection.getSerialPort():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue