From e844d422755485bc84a5d88bbea2ab5f2006a5fc Mon Sep 17 00:00:00 2001 From: Giles Hall Date: Fri, 28 Nov 2014 19:28:03 +0000 Subject: [PATCH] added G4 hook to increase the timeout for serial communication --- src/octoprint/events.py | 1 + src/octoprint/util/comm.py | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/octoprint/events.py b/src/octoprint/events.py index 83b55354..23e673d2 100644 --- a/src/octoprint/events.py +++ b/src/octoprint/events.py @@ -62,6 +62,7 @@ class Events(object): HOME = "Home" Z_CHANGE = "ZChange" WAITING = "Waiting" + DWELL = "Dwelling" COOLING = "Cooling" ALERT = "Alert" CONVEYOR = "Conveyor" diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index eef72246..72a4caaf 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -77,6 +77,8 @@ gcodeToEvent = { "M226": Events.WAITING, "M0": Events.WAITING, "M1": Events.WAITING, + # dwell command + "G4": Events.DWELL, # part cooler "M245": Events.COOLING, @@ -637,7 +639,7 @@ class MachineCom(object): self._changeState(self.STATE_CONNECTING) #Start monitoring the serial port. - timeout = getNewTimeout("communication") + self.timeout = getNewTimeout("communication") tempRequestTimeout = getNewTimeout("temperature") sdStatusRequestTimeout = getNewTimeout("sdStatus") startSeen = not settings().getBoolean(["feature", "waitForStartOnConnect"]) @@ -651,7 +653,7 @@ class MachineCom(object): if line is None: break if line.strip() is not "": - timeout = getNewTimeout("communication") + self.timeout = getNewTimeout("communication") ##~~ Error handling line = self._handleErrors(line) @@ -823,7 +825,7 @@ class MachineCom(object): ### Baudrate detection if self._state == self.STATE_DETECT_BAUDRATE: - if line == '' or time.time() > timeout: + if line == '' or time.time() > self.timeout: if len(self._baudrateDetectList) < 1: self.close() self._errorValue = "No more baudrates to test, and no suitable baudrate found." @@ -843,7 +845,7 @@ class MachineCom(object): self._log("Trying baudrate: %d" % (baudrate)) self._baudrateDetectRetry = 5 self._baudrateDetectTestOk = 0 - timeout = getNewTimeout("communication") + self.timeout = getNewTimeout("communication") self._serial.write('\n') self._sendCommand("M105") self._testingBaudrate = True @@ -879,7 +881,7 @@ class MachineCom(object): else: self.initSdCard() eventManager().fire(Events.CONNECTED, {"port": self._port, "baudrate": self._baudrate}) - elif time.time() > timeout: + elif time.time() > self.timeout: self.close() ### Operational @@ -901,7 +903,7 @@ class MachineCom(object): ### Printing elif self._state == self.STATE_PRINTING: - if line == "" and time.time() > timeout: + if line == "" and time.time() > self.timeout: self._log("Communication timeout during printing, forcing a line") line = 'ok' @@ -1246,6 +1248,19 @@ class MachineCom(object): self.cancelPrint() return cmd + def _gcode_G4(self, cmd): + # we are intending to dwell for a period of time, increase the timeout to match + cmd = cmd.upper() + p_idx = cmd.find('P') + s_idx = cmd.find('S') + _timeout = 0 + if p_idx != -1: + # dwell time is specified in milliseconds + _timeout = int(cmd[p_idx+1:]) / 1000.0 + elif s_idx != -1: + # dwell time is specified in seconds + _timeout = int(cmd[s_idx+1:]) + self.timeout = getNewTimeout("communication") + _timeout ### MachineCom callback ################################################################################################