From fa584d59c57ed5338b3d96850544e67c770dd1bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Wed, 22 May 2013 18:56:02 +0200 Subject: [PATCH] Made progress calculation more resilient, do not hit printer with commands like a freight train during warm up --- octoprint/printer.py | 5 ++++- octoprint/util/comm.py | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/octoprint/printer.py b/octoprint/printer.py index c7d182e..cce9ba2 100644 --- a/octoprint/printer.py +++ b/octoprint/printer.py @@ -416,7 +416,10 @@ class Printer(): newProgress = 0.0 else: newLine = self._comm.getPrintPos() - newProgress = float(newLine) / float(len(self._gcodeList)) + if self._gcodeList is not None: + newProgress = float(newLine) / float(len(self._gcodeList)) + else: + newProgress = 0.0 self._setProgressData(newProgress, newLine, self._comm.getPrintTime(), self._comm.getPrintTimeRemainingEstimate()) diff --git a/octoprint/util/comm.py b/octoprint/util/comm.py index 47153d5..9ca969b 100644 --- a/octoprint/util/comm.py +++ b/octoprint/util/comm.py @@ -637,7 +637,11 @@ class MachineCom(object): self._sendCommand("M105") tempRequestTimeout = time.time() + 5 elif self._state == self.STATE_PRINTING: - # Even when printing request the temperture every 5 seconds. + if line == '' and time.time() > timeout: + self._log("Communication timeout during printing, forcing a line") + line = 'ok' + + # Even when printing request the temperature every 5 seconds. if time.time() > tempRequestTimeout: self._commandQueue.put("M105") tempRequestTimeout = time.time() + 5 @@ -647,13 +651,9 @@ class MachineCom(object): self._commandQueue.put("M27") sdStatusRequestTimeout = time.time() + 1 - if not self._commandQueue.empty(): + if 'ok' in line and not self._commandQueue.empty(): self._sendCommand(self._commandQueue.get()) else: - if line == '' and time.time() > timeout: - self._log("Communication timeout during printing, forcing a line") - line = 'ok' - if 'ok' in line: timeout = time.time() + 5 if not self._commandQueue.empty():