From 8069d08d3b75c2723d9234dd3d1f4b3330f52ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 9 Feb 2016 11:32:56 +0100 Subject: [PATCH] Do not hiccup on manually sent M28 commands In case of trying to switch to state printing with no selected file that scenario is now caught by setting an internal manualStreaming flag. That will stop the M105 polling until M29 is sent (through whatever means). Note that printing is not disabled... this is merely for testing stuff and not encouraged to be used for actually streaming files to the printer, use the built-in functionality for that! --- .../plugins/virtual_printer/virtual.py | 1 + src/octoprint/util/comm.py | 21 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/octoprint/plugins/virtual_printer/virtual.py b/src/octoprint/plugins/virtual_printer/virtual.py index dff4f6d4..c0cb74fe 100644 --- a/src/octoprint/plugins/virtual_printer/virtual.py +++ b/src/octoprint/plugins/virtual_printer/virtual.py @@ -587,6 +587,7 @@ class VirtualPrinter(): def _finishSdFile(self): self._writingToSd = False self._selectedSdFile = None + self.outgoing.put("Done saving file") def _sdPrintingWorker(self): self._selectedSdFilePos = 0 diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index ba0a1721..cf950aa2 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -271,6 +271,7 @@ class MachineCom(object): self._sdFiles = [] self._sdFileToSelect = None self._ignore_select = False + self._manualStreaming = False # print job self._currentFile = None @@ -1035,15 +1036,14 @@ class MachineCom(object): elif 'File selected' in line: if self._ignore_select: self._ignore_select = False - elif self._currentFile is not None: + elif self._currentFile is not None and self.isSdFileSelected(): # final answer to M23, at least on Marlin, Repetier and Sprinter: "File selected" self._callback.on_comm_file_selected(self._currentFile.getFilename(), self._currentFile.getFilesize(), True) eventManager().fire(Events.FILE_SELECTED, { "file": self._currentFile.getFilename(), "origin": self._currentFile.getFileLocation() }) - elif 'Writing to file' in line: - # anwer to M28, at least on Marlin, Repetier and Sprinter: "Writing to file: %s" + elif 'Writing to file' in line and self.isStreaming(): self._changeState(self.STATE_PRINTING) self._clear_to_send.set() line = "ok" @@ -1237,7 +1237,7 @@ class MachineCom(object): will be done. """ - if self.isOperational() and not self.isStreaming() and not self._long_running_command and not self._heating: + if self.isOperational() and not self.isStreaming() and not self._long_running_command and not self._heating and not self._manualStreaming: self.sendCommand("M105", cmd_type="temperature_poll") def _poll_sd_status(self): @@ -1437,6 +1437,9 @@ class MachineCom(object): return ret def _getNext(self): + if self._currentFile is None: + return None + line = self._currentFile.getNext() if line is None: if self.isStreaming(): @@ -1795,6 +1798,16 @@ class MachineCom(object): if self.isPrinting() and not self.isSdPrinting(): self.setPause(True) + def _gcode_M28_sent(self, cmd, cmd_type=None): + if not self.isStreaming(): + self._log("Detected manual streaming. Disabling temperature polling. Finish writing with M29. Do NOT attempt to print while manually streaming!") + self._manualStreaming = True + + def _gcode_M29_sent(self, cmd, cmd_type=None): + if self._manualStreaming: + self._log("Manual streaming done. Re-enabling temperature polling. All is well.") + self._manualStreaming = False + def _gcode_M140_queuing(self, cmd, cmd_type=None): if not self._printerProfileManager.get_current_or_default()["heatedBed"]: self._log("Warn: Not sending \"{}\", printer profile has no heated bed".format(cmd))