From 0a46567c179c3b1c12fc4635a77d7c39a4d42cb2 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Wed, 13 Apr 2016 16:57:08 +0200 Subject: [PATCH] USB printing now uses printeroutputdevice for temperatures CURA-1339 --- plugins/USBPrinting/ControlWindow.qml | 3 +- plugins/USBPrinting/USBPrinterManager.py | 4 +-- plugins/USBPrinting/USBPrinterOutputDevice.py | 29 +++++-------------- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/plugins/USBPrinting/ControlWindow.qml b/plugins/USBPrinting/ControlWindow.qml index 50dfe64f1f..5f6951bedc 100644 --- a/plugins/USBPrinting/ControlWindow.qml +++ b/plugins/USBPrinting/ControlWindow.qml @@ -25,7 +25,8 @@ UM.Dialog Label { //: USB Printing dialog label, %1 is head temperature - text: catalog.i18nc("@label","Extruder Temperature %1").arg(manager.extruderTemperature) + Component.onCompleted: console.log(manager.hotendTemperatures) + text: catalog.i18nc("@label","Extruder Temperature %1").arg(manager.hotendTemperatures[0]) } Label { diff --git a/plugins/USBPrinting/USBPrinterManager.py b/plugins/USBPrinting/USBPrinterManager.py index 1c2c96484f..f49cafeb04 100644 --- a/plugins/USBPrinting/USBPrinterManager.py +++ b/plugins/USBPrinting/USBPrinterManager.py @@ -197,7 +197,7 @@ class USBPrinterManager(QObject, SignalEmitter, OutputDevicePlugin, Extension): self._printer_connections[serial_port] = connection def _onPrinterConnectionStateChanged(self, serial_port): - if self._printer_connections[serial_port].connectionState == ConnectionState.CLOSED: + if self._printer_connections[serial_port].connectionState == ConnectionState.CONNECTED: self.getOutputDeviceManager().addOutputDevice(self._printer_connections[serial_port]) else: self.getOutputDeviceManager().removeOutputDevice(serial_port) @@ -209,7 +209,7 @@ class USBPrinterManager(QObject, SignalEmitter, OutputDevicePlugin, Extension): self._printer_connections_model.addRoleName(Qt.UserRole + 1,"name") self._printer_connections_model.addRoleName(Qt.UserRole + 2, "printer") for connection in self._printer_connections: - if self._printer_connections[connection].isConnected: + if self._printer_connections[connection].connectionState == ConnectionState.CONNECTED: self._printer_connections_model.appendItem({"name":connection, "printer": self._printer_connections[connection]}) return self._printer_connections_model diff --git a/plugins/USBPrinting/USBPrinterOutputDevice.py b/plugins/USBPrinting/USBPrinterOutputDevice.py index 4514d58ae3..8de0a74f76 100644 --- a/plugins/USBPrinting/USBPrinterOutputDevice.py +++ b/plugins/USBPrinting/USBPrinterOutputDevice.py @@ -69,21 +69,6 @@ class USBPrinterOutputDevice(PrinterOutputDevice): # List of gcode lines to be printed self._gcode = [] - # Number of extruders - self._extruder_count = 1 - - # Temperatures of all extruders - self._extruder_temperatures = [0] * self._extruder_count - - # Target temperatures of all extruders - self._target_extruder_temperatures = [0] * self._extruder_count - - #Target temperature of the bed - self._target_bed_temperature = 0 - - # Temperature of the bed - self._bed_temperature = 0 - # Current Z stage location self._current_z = 0 @@ -274,6 +259,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice): if sucesfull_responses >= self._required_responses_auto_baud: self._serial.timeout = 2 # Reset serial timeout self.setConnectionState(ConnectionState.CONNECTED) + self._listen_thread.start() # Start listening Logger.log("i", "Established printer connection on port %s" % self._serial_port) return @@ -408,15 +394,14 @@ class USBPrinterOutputDevice(PrinterOutputDevice): Logger.log("i", "Printer connection listen thread started for %s" % self._serial_port) temperature_request_timeout = time.time() ok_timeout = time.time() - while self._connected: + while self._connection_state == ConnectionState.CONNECTED: line = self._readline() - if line is None: break # None is only returned when something went wrong. Stop listening if time.time() > temperature_request_timeout: - if self._extruder_count > 0: - self._temperature_requested_extruder_index = (self._temperature_requested_extruder_index + 1) % self._extruder_count + if self._num_extruders > 0: + self._temperature_requested_extruder_index = (self._temperature_requested_extruder_index + 1) % self._num_extruders self.sendCommand("M105 T%d" % (self._temperature_requested_extruder_index)) else: self.sendCommand("M105") @@ -437,7 +422,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice): elif b" T:" in line or line.startswith(b"T:"): #Temperature message try: - self._setExtruderTemperature(self._temperature_requested_extruder_index,float(re.search(b"T: *([0-9\.]*)", line).group(1))) + self._setHotendTemperature(self._temperature_requested_extruder_index, float(re.search(b"T: *([0-9\.]*)", line).group(1))) except: pass if b"B:" in line: # Check if it's a bed temperature @@ -469,8 +454,8 @@ class USBPrinterOutputDevice(PrinterOutputDevice): else: # Request the temperature on comm timeout (every 2 seconds) when we are not printing.) if line == b"": - if self._extruder_count > 0: - self._temperature_requested_extruder_index = (self._temperature_requested_extruder_index + 1) % self._extruder_count + if self._num_extruders > 0: + self._temperature_requested_extruder_index = (self._temperature_requested_extruder_index + 1) % self._num_extruders self.sendCommand("M105 T%d" % self._temperature_requested_extruder_index) else: self.sendCommand("M105")