From 17c6c83503e4526762d0ef9f1cdff6023f0f1247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 15 Jun 2018 17:02:53 +0200 Subject: [PATCH] Fix SD printing --- .../plugins/virtual_printer/virtual.py | 2 +- src/octoprint/printer/standard.py | 8 ++++-- src/octoprint/util/comm.py | 27 ++++++++++++------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/octoprint/plugins/virtual_printer/virtual.py b/src/octoprint/plugins/virtual_printer/virtual.py index e1aa40202..e37785151 100644 --- a/src/octoprint/plugins/virtual_printer/virtual.py +++ b/src/octoprint/plugins/virtual_printer/virtual.py @@ -1158,10 +1158,10 @@ class VirtualPrinter(object): def _finishSdPrint(self): if not self._killed: self._sdPrintingSemaphore.clear() + self._output("Done printing file") self._selectedSdFilePos = 0 self._sdPrinting = False self._sdPrinter = None - self._output("Done printing file") def _waitForHeatup(self, heater, only_wait_if_higher): delta = 1 diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 7de61daeb..c1355bbad 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -440,8 +440,12 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): self._validateJob(path, sd) origin = FileDestinations.SDCARD if sd else FileDestinations.LOCAL - path_on_disk = self._fileManager.path_on_disk(origin, path) - path_in_storage = self._fileManager.path_in_storage(origin, path_on_disk) + if sd: + path_on_disk = "/" + path + path_in_storage = path + else: + path_on_disk = self._fileManager.path_on_disk(origin, path) + path_in_storage = self._fileManager.path_in_storage(origin, path_on_disk) recovery_data = self._fileManager.get_recovery_data() if recovery_data: diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index bf347ad80..e595d5746 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -1011,9 +1011,15 @@ class MachineCom(object): self._callback.on_comm_print_job_started() if self.isSdFileSelected(): + interval = self._timeout_intervals.get("sdStatus", 1.0) + if interval <= 0: + interval = 1.0 + self._sd_status_timer = RepeatedTimer(interval, self._poll_sd_status, run_first=True) + if not external_sd: # make sure to ignore the "file selected" later on, otherwise we'll reset our progress data self._ignore_select = True + self.sendCommand("M23 {filename}".format(filename=self._currentFile.getFilename()), part_of_job=True, tags=tags | {"trigger:comm.start_print",}) @@ -1025,15 +1031,15 @@ class MachineCom(object): else: self._currentFile.pos = 0 + def start_polling(): + self._sd_status_timer.start() + self.sendCommand("M24", + on_sent=start_polling, part_of_job=True, tags=tags | {"trigger:comm.start_print",}) - - interval = self._timeout_intervals.get("sdStatus", 1.0) - if interval <= 0: - interval = 1.0 - self._sd_status_timer = RepeatedTimer(interval, self._poll_sd_status, run_first=True) - self._sd_status_timer.start() + else: + self._sd_status_timer.start() else: if pos is not None and isinstance(pos, int) and pos > 0: self._currentFile.seek(pos) @@ -1890,7 +1896,7 @@ class MachineCom(object): self._currentFile.size = total self._callback.on_comm_progress() - elif 'Not SD printing' in line and self.isSdFileSelected() and self.isPrinting(): + elif 'Not SD printing' in line and self.isSdFileSelected() and self.isPrinting() and not self.isFinishing(): # something went wrong, printer is reporting that we actually are not printing right now... self.cancelPrint(external_sd=True) elif 'File opened' in line and not self._ignore_select: @@ -1933,6 +1939,8 @@ class MachineCom(object): self._changeState(self.STATE_PRINTING) elif 'Done printing file' in line and self.isSdPrinting(): # printer is reporting file finished printing + self._changeState(self.STATE_FINISHING) + self._currentFile.done = True self._currentFile.pos = 0 @@ -1942,11 +1950,12 @@ class MachineCom(object): except: pass - self._changeState(self.STATE_FINISHING) + self.sendCommand("M400", part_of_job=True) self._callback.on_comm_print_job_done() def finalize(): self._changeState(self.STATE_OPERATIONAL) - self.sendCommand(SendQueueMarker(finalize)) + self.sendCommand(SendQueueMarker(finalize), part_of_job=True) + self._continue_sending() elif 'Done saving file' in line: if self._trigger_ok_for_m29: # workaround for most versions of Marlin out in the wild