From 3f61ebc29e8978c18063933b996c55ac8720fb3d Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 11:53:20 +0200 Subject: [PATCH 01/38] removed debugging output handling --- src/octoprint/util/comm_acc.py | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index ad11c3c8..bb73a048 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -978,32 +978,32 @@ class MachineCom(object): if line.strip() is not "": self._timeout = get_new_timeout("communication") - ##~~ debugging output handling - if line.startswith("//"): - debugging_output = line[2:].strip() - if debugging_output.startswith("action:"): - action_command = debugging_output[len("action:"):].strip() - - if action_command == "pause": - self._log("Pausing on request of the printer...") - self.setPause(True) - elif action_command == "resume": - self._log("Resuming on request of the printer...") - self.setPause(False) - elif action_command == "disconnect": - self._log("Disconnecting on request of the printer...") - self._callback.on_comm_force_disconnect() - else: - for hook in self._printer_action_hooks: - self._printer_action_hooks[hook](self, line, action_command) - else: - continue + # ##~~ debugging output handling + # if line.startswith("//"): + # debugging_output = line[2:].strip() + # if debugging_output.startswith("action:"): + # action_command = debugging_output[len("action:"):].strip() + # + # if action_command == "pause": + # self._log("Pausing on request of the printer...") + # self.setPause(True) + # elif action_command == "resume": + # self._log("Resuming on request of the printer...") + # self.setPause(False) + # elif action_command == "disconnect": + # self._log("Disconnecting on request of the printer...") + # self._callback.on_comm_force_disconnect() + # else: + # for hook in self._printer_action_hooks: + # self._printer_action_hooks[hook](self, line, action_command) + # else: + # continue ##~~ Error handling #line = self._handleErrors(line) # GRBL Position update - if self._grbl : + if self._grbl: if(self._state == self.STATE_HOMING and 'ok' in line): self._changeState(self.STATE_OPERATIONAL) self._onHomingDone(); From a61245a8b4ccbad31c0fe9d9b6de020f6ca9b1fc Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 16:54:59 +0200 Subject: [PATCH 02/38] a lot of changes in _monitor trying to reduce computational effort --- src/octoprint/util/comm_acc.py | 177 ++++++++++++++++----------------- 1 file changed, 88 insertions(+), 89 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index bb73a048..ab0c1a30 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1008,68 +1008,69 @@ class MachineCom(object): self._changeState(self.STATE_OPERATIONAL) self._onHomingDone(); - # TODO check if "Alarm" is enough - if("Alarm lock" in line): - self._changeState(self.STATE_LOCKED) + #if 'MPos:' in line: + # # check movement + # if grblLastStatus == line: + # grblMoving = False + # else: + # grblMoving = True + # grblLastStatus = line + # self._update_grbl_pos(line) + + # TODO maybe better in _gcode_X_sent ... + if("Idle" in line and (self._state == self.STATE_LOCKED)): + self._changeState(self.STATE_OPERATIONAL) + + ## TODO check if "Alarm" is enough + #if("Alarm lock" in line): + # self._changeState(self.STATE_LOCKED) if("['$H'|'$X' to unlock]" in line): self._changeState(self.STATE_LOCKED) - # TODO maybe better in _gcode_X_sent ... - if("Idle" in line and (self._state == self.STATE_LOCKED) ): - self._changeState(self.STATE_OPERATIONAL) - - # TODO highly experimental. needs testing. - if("Hold" in line and self._state == self.STATE_PRINTING): - self._changeState(self.STATE_PAUSED) + ## TODO highly experimental. needs testing. + #if("Hold" in line and self._state == self.STATE_PRINTING): + # self._changeState(self.STATE_PAUSED) #if("Run" in line and self._state == self.STATE_PAUSED): # self._changeState(self.STATE_PRINTING) - if 'MPos:' in line: - # check movement - if grblLastStatus == line: - grblMoving = False - else: - grblMoving = True - grblLastStatus = line - self._update_grbl_pos(line) - if("ALARM: Hard/soft limit" in line): - errorMsg = "Machine Limit Hit. Please reset the machine and do a homing cycle" - self._log(errorMsg) - self._errorValue = errorMsg - eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) - eventManager().fire(Events.LIMITS_HIT, {"error": self.getErrorString()}) - self._openSerial() - self._changeState(self.STATE_CONNECTING) + #if("ALARM: Hard/soft limit" in line): + # errorMsg = "Machine Limit Hit. Please reset the machine and do a homing cycle" + # self._log(errorMsg) + # self._errorValue = errorMsg + # eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) + # eventManager().fire(Events.LIMITS_HIT, {"error": self.getErrorString()}) + # self._openSerial() + # self._changeState(self.STATE_CONNECTING) - if("Invalid gcode" in line and self._state == self.STATE_PRINTING): - # TODO Pause machine instead of resetting it. - errorMsg = line - self._log(errorMsg) - self._errorValue = errorMsg -# self._changeState(self.STATE_ERROR) - eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) - self._openSerial() - self._changeState(self.STATE_CONNECTING) + #if("Invalid gcode" in line and self._state == self.STATE_PRINTING): + # # TODO Pause machine instead of resetting it. + # errorMsg = line + # self._log(errorMsg) + # self._errorValue = errorMsg +# # self._changeState(self.STATE_ERROR) + # eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) + # self._openSerial() + # self._changeState(self.STATE_CONNECTING) - if("Grbl" in line and self._state == self.STATE_PRINTING): - errorMsg = "Machine reset." - self._log(errorMsg) - self._errorValue = errorMsg - self._changeState(self.STATE_LOCKED) - eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) + #if("Grbl" in line and self._state == self.STATE_PRINTING): + # errorMsg = "Machine reset." + # self._log(errorMsg) + # self._errorValue = errorMsg + # self._changeState(self.STATE_LOCKED) + # eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) - if("Grbl" in line): - versionMatch = re.search("Grbl (?P.+?)(_(?P[0-9a-f]{7})(?P-dirty)?)? \[.+\]", line) - if(versionMatch): - versionDict = versionMatch.groupdict() - self._writeGrblVersionToFile(versionDict) - if self._compareGrblVersion(versionDict) is False: - self._flashGrbl() + #if("Grbl" in line): + # versionMatch = re.search("Grbl (?P.+?)(_(?P[0-9a-f]{7})(?P-dirty)?)? \[.+\]", line) + # if(versionMatch): + # versionDict = versionMatch.groupdict() + # self._writeGrblVersionToFile(versionDict) + # if self._compareGrblVersion(versionDict) is False: + # self._flashGrbl() - if("error:" in line): - self.handle_grbl_error(line) + #if("error:" in line): + # self.handle_grbl_error(line) # ##~~ SD file list # # if we are currently receiving an sd file list, each line is just a filename, so just read it and abort processing @@ -1239,16 +1240,44 @@ class MachineCom(object): feedback_errors.append("_all") ##~~ Parsing for pause triggers - if pause_triggers and not self.isStreaming(): - if "enable" in pause_triggers.keys() and pause_triggers["enable"].search(line) is not None: - self.setPause(True) - elif "disable" in pause_triggers.keys() and pause_triggers["disable"].search(line) is not None: - self.setPause(False) - elif "toggle" in pause_triggers.keys() and pause_triggers["toggle"].search(line) is not None: - self.setPause(not self.isPaused()) + #if pause_triggers and not self.isStreaming(): + # if "enable" in pause_triggers.keys() and pause_triggers["enable"].search(line) is not None: + # self.setPause(True) + # elif "disable" in pause_triggers.keys() and pause_triggers["disable"].search(line) is not None: + # self.setPause(False) + # elif "toggle" in pause_triggers.keys() and pause_triggers["toggle"].search(line) is not None: + # self.setPause(not self.isPaused()) - ### Baudrate detection - if self._state == self.STATE_DETECT_BAUDRATE: + ### Printing + if self._state == self.STATE_PRINTING: + if "ok" in line or (supportWait and "wait" in line): + # a wait while printing means our printer's buffer ran out, probably due to some ok getting + # swallowed, so we treat it the same as an ok here teo take up communication again + if self._resendSwallowNextOk: + self._resendSwallowNextOk = False + + elif self._resendDelta is not None: + self._resendNextCommand() + + else: + if self._sendFromQueue(): + pass + elif not self.isSdPrinting(): + self._sendNext() + + elif line.lower().startswith("resend") or line.lower().startswith("rs"): + self._handleResendRequest(line) + + elif line == "" and time.time() > self._timeout: + if not self._long_running_command: + self._log("Communication timeout during printing, forcing a line") + self._sendCommand("?") + self._clear_to_send.set() + else: + self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active") + + ## Baudrate detection + elif self._state == self.STATE_DETECT_BAUDRATE: if line == '' or time.time() > self._timeout: if self._baudrateDetectRetry > 0: self._serial.timeout = detection_timeout @@ -1286,8 +1315,6 @@ class MachineCom(object): self._onConnected(self.STATE_LOCKED) self._clear_to_send.set() - - ### Connection attempt elif self._state == self.STATE_CONNECTING: #line = self.__readline() @@ -1314,34 +1341,6 @@ class MachineCom(object): # resend -> start resend procedure from requested line elif line.lower().startswith("resend") or line.lower().startswith("rs"): self._handleResendRequest(line) - - ### Printing - elif self._state == self.STATE_PRINTING: - if line == "" and time.time() > self._timeout: - if not self._long_running_command: - self._log("Communication timeout during printing, forcing a line") - self._sendCommand("?") - self._clear_to_send.set() - else: - self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active") - - if "ok" in line or (supportWait and "wait" in line): - # a wait while printing means our printer's buffer ran out, probably due to some ok getting - # swallowed, so we treat it the same as an ok here teo take up communication again - if self._resendSwallowNextOk: - self._resendSwallowNextOk = False - - elif self._resendDelta is not None: - self._resendNextCommand() - - else: - if self._sendFromQueue(): - pass - elif not self.isSdPrinting(): - self._sendNext() - - elif line.lower().startswith("resend") or line.lower().startswith("rs"): - self._handleResendRequest(line) except: self._logger.exception("Something crashed inside the serial connection loop, please report this in OctoPrint's bug tracker:") From 29a85fec96c979435e51b45c30efdb7d033af260 Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 17:19:45 +0200 Subject: [PATCH 03/38] deactivated timeout reset --- src/octoprint/util/comm_acc.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index ab0c1a30..139e5fa7 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -975,8 +975,8 @@ class MachineCom(object): line = self._readline() if line is None: break - if line.strip() is not "": - self._timeout = get_new_timeout("communication") + # if line.strip() is not "": + # self._timeout = get_new_timeout("communication") # ##~~ debugging output handling # if line.startswith("//"): @@ -1268,13 +1268,13 @@ class MachineCom(object): elif line.lower().startswith("resend") or line.lower().startswith("rs"): self._handleResendRequest(line) - elif line == "" and time.time() > self._timeout: - if not self._long_running_command: - self._log("Communication timeout during printing, forcing a line") - self._sendCommand("?") - self._clear_to_send.set() - else: - self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active") + # elif line == "" and time.time() > self._timeout: + # if not self._long_running_command: + # self._log("Communication timeout during printing, forcing a line") + # self._sendCommand("?") + # self._clear_to_send.set() + # else: + # self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active") ## Baudrate detection elif self._state == self.STATE_DETECT_BAUDRATE: @@ -1323,9 +1323,9 @@ class MachineCom(object): # self._clear_to_send.set() elif " self._timeout: - print("TIMEOUT_CLOSE") - self.close() + # elif time.time() > self._timeout: + # print("TIMEOUT_CLOSE") + # self.close() ### Operational elif self._state == self.STATE_OPERATIONAL or self._state == self.STATE_PAUSED: From 5ecc0a1e90e8bb84f578241f87f97ca82d3c1087 Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 17:42:47 +0200 Subject: [PATCH 04/38] Revert "removed debugging output handling" This reverts commit 3f61ebc29e8978c18063933b996c55ac8720fb3d. --- src/octoprint/util/comm_acc.py | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 139e5fa7..f6b2f400 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -978,32 +978,32 @@ class MachineCom(object): # if line.strip() is not "": # self._timeout = get_new_timeout("communication") - # ##~~ debugging output handling - # if line.startswith("//"): - # debugging_output = line[2:].strip() - # if debugging_output.startswith("action:"): - # action_command = debugging_output[len("action:"):].strip() - # - # if action_command == "pause": - # self._log("Pausing on request of the printer...") - # self.setPause(True) - # elif action_command == "resume": - # self._log("Resuming on request of the printer...") - # self.setPause(False) - # elif action_command == "disconnect": - # self._log("Disconnecting on request of the printer...") - # self._callback.on_comm_force_disconnect() - # else: - # for hook in self._printer_action_hooks: - # self._printer_action_hooks[hook](self, line, action_command) - # else: - # continue + ##~~ debugging output handling + if line.startswith("//"): + debugging_output = line[2:].strip() + if debugging_output.startswith("action:"): + action_command = debugging_output[len("action:"):].strip() + + if action_command == "pause": + self._log("Pausing on request of the printer...") + self.setPause(True) + elif action_command == "resume": + self._log("Resuming on request of the printer...") + self.setPause(False) + elif action_command == "disconnect": + self._log("Disconnecting on request of the printer...") + self._callback.on_comm_force_disconnect() + else: + for hook in self._printer_action_hooks: + self._printer_action_hooks[hook](self, line, action_command) + else: + continue ##~~ Error handling #line = self._handleErrors(line) # GRBL Position update - if self._grbl: + if self._grbl : if(self._state == self.STATE_HOMING and 'ok' in line): self._changeState(self.STATE_OPERATIONAL) self._onHomingDone(); From ad745e067b4aeafe7bcedf6360b1b20974fecefd Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 17:47:56 +0200 Subject: [PATCH 05/38] remove changes --- src/octoprint/util/comm_acc.py | 180 +++++++++++++++++---------------- 1 file changed, 91 insertions(+), 89 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index f6b2f400..ace2e3c9 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -975,8 +975,8 @@ class MachineCom(object): line = self._readline() if line is None: break - # if line.strip() is not "": - # self._timeout = get_new_timeout("communication") + if line.strip() is not "": + self._timeout = get_new_timeout("communication") ##~~ debugging output handling if line.startswith("//"): @@ -1008,69 +1008,68 @@ class MachineCom(object): self._changeState(self.STATE_OPERATIONAL) self._onHomingDone(); - #if 'MPos:' in line: - # # check movement - # if grblLastStatus == line: - # grblMoving = False - # else: - # grblMoving = True - # grblLastStatus = line - # self._update_grbl_pos(line) - - # TODO maybe better in _gcode_X_sent ... - if("Idle" in line and (self._state == self.STATE_LOCKED)): - self._changeState(self.STATE_OPERATIONAL) - - ## TODO check if "Alarm" is enough - #if("Alarm lock" in line): - # self._changeState(self.STATE_LOCKED) + # TODO check if "Alarm" is enough + if("Alarm lock" in line): + self._changeState(self.STATE_LOCKED) if("['$H'|'$X' to unlock]" in line): self._changeState(self.STATE_LOCKED) - ## TODO highly experimental. needs testing. - #if("Hold" in line and self._state == self.STATE_PRINTING): - # self._changeState(self.STATE_PAUSED) + # TODO maybe better in _gcode_X_sent ... + if("Idle" in line and (self._state == self.STATE_LOCKED) ): + self._changeState(self.STATE_OPERATIONAL) + + # TODO highly experimental. needs testing. + if("Hold" in line and self._state == self.STATE_PRINTING): + self._changeState(self.STATE_PAUSED) #if("Run" in line and self._state == self.STATE_PAUSED): # self._changeState(self.STATE_PRINTING) + if 'MPos:' in line: + # check movement + if grblLastStatus == line: + grblMoving = False + else: + grblMoving = True + grblLastStatus = line + self._update_grbl_pos(line) - #if("ALARM: Hard/soft limit" in line): - # errorMsg = "Machine Limit Hit. Please reset the machine and do a homing cycle" - # self._log(errorMsg) - # self._errorValue = errorMsg - # eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) - # eventManager().fire(Events.LIMITS_HIT, {"error": self.getErrorString()}) - # self._openSerial() - # self._changeState(self.STATE_CONNECTING) + if("ALARM: Hard/soft limit" in line): + errorMsg = "Machine Limit Hit. Please reset the machine and do a homing cycle" + self._log(errorMsg) + self._errorValue = errorMsg + eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) + eventManager().fire(Events.LIMITS_HIT, {"error": self.getErrorString()}) + self._openSerial() + self._changeState(self.STATE_CONNECTING) - #if("Invalid gcode" in line and self._state == self.STATE_PRINTING): - # # TODO Pause machine instead of resetting it. - # errorMsg = line - # self._log(errorMsg) - # self._errorValue = errorMsg -# # self._changeState(self.STATE_ERROR) - # eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) - # self._openSerial() - # self._changeState(self.STATE_CONNECTING) + if("Invalid gcode" in line and self._state == self.STATE_PRINTING): + # TODO Pause machine instead of resetting it. + errorMsg = line + self._log(errorMsg) + self._errorValue = errorMsg +# self._changeState(self.STATE_ERROR) + eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) + self._openSerial() + self._changeState(self.STATE_CONNECTING) - #if("Grbl" in line and self._state == self.STATE_PRINTING): - # errorMsg = "Machine reset." - # self._log(errorMsg) - # self._errorValue = errorMsg - # self._changeState(self.STATE_LOCKED) - # eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) + if("Grbl" in line and self._state == self.STATE_PRINTING): + errorMsg = "Machine reset." + self._log(errorMsg) + self._errorValue = errorMsg + self._changeState(self.STATE_LOCKED) + eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) - #if("Grbl" in line): - # versionMatch = re.search("Grbl (?P.+?)(_(?P[0-9a-f]{7})(?P-dirty)?)? \[.+\]", line) - # if(versionMatch): - # versionDict = versionMatch.groupdict() - # self._writeGrblVersionToFile(versionDict) - # if self._compareGrblVersion(versionDict) is False: - # self._flashGrbl() + if("Grbl" in line): + versionMatch = re.search("Grbl (?P.+?)(_(?P[0-9a-f]{7})(?P-dirty)?)? \[.+\]", line) + if(versionMatch): + versionDict = versionMatch.groupdict() + self._writeGrblVersionToFile(versionDict) + if self._compareGrblVersion(versionDict) is False: + self._flashGrbl() - #if("error:" in line): - # self.handle_grbl_error(line) + if("error:" in line): + self.handle_grbl_error(line) # ##~~ SD file list # # if we are currently receiving an sd file list, each line is just a filename, so just read it and abort processing @@ -1240,44 +1239,17 @@ class MachineCom(object): feedback_errors.append("_all") ##~~ Parsing for pause triggers - #if pause_triggers and not self.isStreaming(): - # if "enable" in pause_triggers.keys() and pause_triggers["enable"].search(line) is not None: - # self.setPause(True) - # elif "disable" in pause_triggers.keys() and pause_triggers["disable"].search(line) is not None: - # self.setPause(False) - # elif "toggle" in pause_triggers.keys() and pause_triggers["toggle"].search(line) is not None: - # self.setPause(not self.isPaused()) - ### Printing - if self._state == self.STATE_PRINTING: - if "ok" in line or (supportWait and "wait" in line): - # a wait while printing means our printer's buffer ran out, probably due to some ok getting - # swallowed, so we treat it the same as an ok here teo take up communication again - if self._resendSwallowNextOk: - self._resendSwallowNextOk = False + if pause_triggers and not self.isStreaming(): + if "enable" in pause_triggers.keys() and pause_triggers["enable"].search(line) is not None: + self.setPause(True) + elif "disable" in pause_triggers.keys() and pause_triggers["disable"].search(line) is not None: + self.setPause(False) + elif "toggle" in pause_triggers.keys() and pause_triggers["toggle"].search(line) is not None: + self.setPause(not self.isPaused()) - elif self._resendDelta is not None: - self._resendNextCommand() - - else: - if self._sendFromQueue(): - pass - elif not self.isSdPrinting(): - self._sendNext() - - elif line.lower().startswith("resend") or line.lower().startswith("rs"): - self._handleResendRequest(line) - - # elif line == "" and time.time() > self._timeout: - # if not self._long_running_command: - # self._log("Communication timeout during printing, forcing a line") - # self._sendCommand("?") - # self._clear_to_send.set() - # else: - # self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active") - - ## Baudrate detection - elif self._state == self.STATE_DETECT_BAUDRATE: + ### Baudrate detection + if self._state == self.STATE_DETECT_BAUDRATE: if line == '' or time.time() > self._timeout: if self._baudrateDetectRetry > 0: self._serial.timeout = detection_timeout @@ -1315,6 +1287,8 @@ class MachineCom(object): self._onConnected(self.STATE_LOCKED) self._clear_to_send.set() + + ### Connection attempt elif self._state == self.STATE_CONNECTING: #line = self.__readline() @@ -1341,6 +1315,34 @@ class MachineCom(object): # resend -> start resend procedure from requested line elif line.lower().startswith("resend") or line.lower().startswith("rs"): self._handleResendRequest(line) + + ### Printing + elif self._state == self.STATE_PRINTING: + if line == "" and time.time() > self._timeout: + if not self._long_running_command: + self._log("Communication timeout during printing, forcing a line") + self._sendCommand("?") + self._clear_to_send.set() + else: + self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active") + + if "ok" in line or (supportWait and "wait" in line): + # a wait while printing means our printer's buffer ran out, probably due to some ok getting + # swallowed, so we treat it the same as an ok here teo take up communication again + if self._resendSwallowNextOk: + self._resendSwallowNextOk = False + + elif self._resendDelta is not None: + self._resendNextCommand() + + else: + if self._sendFromQueue(): + pass + elif not self.isSdPrinting(): + self._sendNext() + + elif line.lower().startswith("resend") or line.lower().startswith("rs"): + self._handleResendRequest(line) except: self._logger.exception("Something crashed inside the serial connection loop, please report this in OctoPrint's bug tracker:") From d5e4a5f4aef861cd3379ecf3350a6c77d4d42fd2 Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 17:59:56 +0200 Subject: [PATCH 06/38] added disconnect special command and added yappi to profile while loop --- src/octoprint/util/comm_acc.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index ace2e3c9..e88efcf5 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -4,6 +4,9 @@ __author__ = "Gina Häußge based on work by David Braam" __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License" +### DEBUGING START +import yappi +### DEBUG END import os import glob @@ -498,6 +501,8 @@ class MachineCom(object): self._temperature_timer = RepeatedTimer(frequency, self._poll_temperature, run_first=True) self._temperature_timer.start() + elif "disconnect" in specialcmd: + self.close() else: self._log("Command not Found! %s" % cmd) self._log("available commands are:") @@ -970,6 +975,8 @@ class MachineCom(object): self._sendCommand("?") self._clear_to_send.set() + yappi.start() + while self._monitoring_active: try: line = self._readline() @@ -1353,6 +1360,8 @@ class MachineCom(object): eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) self._log("Connection closed, closing down monitor") + yappi.get_func_stats().print_all() + def _process_registered_message(self, line, feedback_matcher, feedback_controls, feedback_errors): feedback_match = feedback_matcher.search(line) if feedback_match is None: From 23cab00b36beedf0e6df1eb71d038a43bd002803 Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 18:21:18 +0200 Subject: [PATCH 07/38] yappi output to /tmp/yappi --- src/octoprint/util/comm_acc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index e88efcf5..00956321 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1359,8 +1359,7 @@ class MachineCom(object): self._changeState(self.STATE_ERROR) eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) self._log("Connection closed, closing down monitor") - - yappi.get_func_stats().print_all() + yappi.get_func_stats().print_all(out=open("/tmp/yappi", 'w')) def _process_registered_message(self, line, feedback_matcher, feedback_controls, feedback_errors): feedback_match = feedback_matcher.search(line) From e4931acaa6c2b486371ede8667b0cc39e14021f6 Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 18:31:47 +0200 Subject: [PATCH 08/38] removed yappi --- src/octoprint/util/comm_acc.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 00956321..ca4f4954 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -4,10 +4,6 @@ __author__ = "Gina Häußge based on work by David Braam" __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License" -### DEBUGING START -import yappi -### DEBUG END - import os import glob import time @@ -975,8 +971,6 @@ class MachineCom(object): self._sendCommand("?") self._clear_to_send.set() - yappi.start() - while self._monitoring_active: try: line = self._readline() @@ -1359,7 +1353,6 @@ class MachineCom(object): self._changeState(self.STATE_ERROR) eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) self._log("Connection closed, closing down monitor") - yappi.get_func_stats().print_all(out=open("/tmp/yappi", 'w')) def _process_registered_message(self, line, feedback_matcher, feedback_controls, feedback_errors): feedback_match = feedback_matcher.search(line) From 4793ec0e543b9439052b1b632035a72a5cef5e9c Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 18:46:13 +0200 Subject: [PATCH 09/38] added cProfile --- src/octoprint/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/octoprint/__init__.py b/src/octoprint/__init__.py index 67baa4f7..8e9c4cca 100644 --- a/src/octoprint/__init__.py +++ b/src/octoprint/__init__.py @@ -3,6 +3,10 @@ import sys from octoprint.daemon import Daemon from octoprint.server import Server +### DEBUG START +import cProfile +### DEBUG END + #~~ version from ._version import get_versions @@ -81,4 +85,7 @@ def main(): octoprint.run() if __name__ == "__main__": - main() + ### DEBUG START + cProfile.run('main()', '/tmp/profilestats') + ### DEBUG END + #main() From adce7b877d027a1815d1569f8a6edeabbedb3891 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 09:50:10 +0200 Subject: [PATCH 10/38] removed cprofile --- src/octoprint/__init__.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/octoprint/__init__.py b/src/octoprint/__init__.py index 8e9c4cca..67baa4f7 100644 --- a/src/octoprint/__init__.py +++ b/src/octoprint/__init__.py @@ -3,10 +3,6 @@ import sys from octoprint.daemon import Daemon from octoprint.server import Server -### DEBUG START -import cProfile -### DEBUG END - #~~ version from ._version import get_versions @@ -85,7 +81,4 @@ def main(): octoprint.run() if __name__ == "__main__": - ### DEBUG START - cProfile.run('main()', '/tmp/profilestats') - ### DEBUG END - #main() + main() From 147034680d2efe2412f3a2b1211eab8b571fb447 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 10:40:10 +0200 Subject: [PATCH 11/38] added exception argument --- src/octoprint/util/comm_acc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index ca4f4954..abd308ce 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -428,13 +428,13 @@ class MachineCom(object): try: self._temperature_timer.cancel() self._temperature_timer = None - except: + except AttributeError: pass if self._sd_status_timer is not None: try: self._sd_status_timer.cancel() - except: + except AttributeError: pass self._monitoring_active = False From 8a9317d7426bef289c953bb641bc8ac917651466 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 11:31:55 +0200 Subject: [PATCH 12/38] changed sleep from 0.1sec to 0.001sec in _send_loop() --- src/octoprint/util/comm_acc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index abd308ce..cf94ddd3 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1757,7 +1757,7 @@ class MachineCom(object): while self._send_queue_active: try: if(self.RX_BUFFER_SIZE - sum(self.acc_line_lengths) < 20): - time.sleep(0.1) + time.sleep(0.001) continue # wait until we have something in the queue From ac3b5ebc541120a0ddb3f53704351cb8707d6d0c Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 11:31:55 +0200 Subject: [PATCH 13/38] changed sleep from 0.1sec to 0.001sec in _send_loop() --- src/octoprint/util/comm_acc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 2646e13d..e0e02be4 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1708,7 +1708,7 @@ class MachineCom(object): while self._send_queue_active: try: if(self.RX_BUFFER_SIZE - sum(self.acc_line_lengths) < 20): - time.sleep(0.1) + time.sleep(0.001) continue # wait until we have something in the queue From 42844c2ef9b60df54b964ec689bbb7556bc2c030 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 12:09:09 +0200 Subject: [PATCH 14/38] reverted to old sleep 0.1sec due to acc bug --- .gitignore | 1 + src/octoprint/util/comm_acc.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f6e2d3c9..4d9c960d 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ OctoPrint.egg-info /nbproject/ .directory .project +out/* diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index e0e02be4..2646e13d 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1708,7 +1708,7 @@ class MachineCom(object): while self._send_queue_active: try: if(self.RX_BUFFER_SIZE - sum(self.acc_line_lengths) < 20): - time.sleep(0.001) + time.sleep(0.1) continue # wait until we have something in the queue From 5b89302deb58d3296396069ccdea49114a0124d1 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 12:47:19 +0200 Subject: [PATCH 15/38] added stuff to resolve acc_line_length bug --- src/octoprint/util/comm_acc.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index cf94ddd3..2169d3b7 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1756,7 +1756,10 @@ class MachineCom(object): while self._send_queue_active: try: - if(self.RX_BUFFER_SIZE - sum(self.acc_line_lengths) < 20): + peeked_entry = self._send_queue.peek() + p_command, p_linenbr, p_cmd_type = peeked_entry + + if(self.RX_BUFFER_SIZE - sum(self.acc_line_lengths) - len(p_command) < 10): time.sleep(0.001) continue @@ -2341,6 +2344,7 @@ class TypedQueue(queue.Queue): def __init__(self, maxsize=0): queue.Queue.__init__(self, maxsize=maxsize) self._lookup = [] + self._peekedItem = None; def _put(self, item): if isinstance(item, tuple) and len(item) == 3: @@ -2354,7 +2358,11 @@ class TypedQueue(queue.Queue): queue.Queue._put(self, item) def _get(self): - item = queue.Queue._get(self) + if self._peekedItem is None: + item = queue.Queue._get(self) + else: + item = self._peekedItem + self._peekedItem = None if isinstance(item, tuple) and len(item) == 3: cmd, line, cmd_type = item @@ -2363,6 +2371,10 @@ class TypedQueue(queue.Queue): return item + def peek(self): + if self._peekedItem is None: + self._peekedItem = self._get() + return self._peekedItem class TypeAlreadyInQueue(Exception): def __init__(self, t, *args, **kwargs): From 77499fb86858fa1c7103eee765d349d21b850510 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 12:54:21 +0200 Subject: [PATCH 16/38] changed acc remaining value from 10 to 5 character --- src/octoprint/util/comm_acc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 2169d3b7..4d89e9d3 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1759,7 +1759,7 @@ class MachineCom(object): peeked_entry = self._send_queue.peek() p_command, p_linenbr, p_cmd_type = peeked_entry - if(self.RX_BUFFER_SIZE - sum(self.acc_line_lengths) - len(p_command) < 10): + if(self.RX_BUFFER_SIZE - sum(self.acc_line_lengths) - len(p_command) < 5): time.sleep(0.001) continue From 2449f9e327ca2f12e6bd348d558b5038f79415b8 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 16:40:49 +0200 Subject: [PATCH 17/38] changed standart position poll rate to 1sec and removed disabling during printing --- src/octoprint/util/comm_acc.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 4d89e9d3..dcecbf03 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -256,19 +256,6 @@ class MachineCom(object): if self._state == newState: return - if newState == self.STATE_PRINTING: - if self._temperature_timer is not None: - self._temperature_timer.cancel() - self._temperature_timer = None - elif newState == self.STATE_OPERATIONAL: - if self._temperature_timer is not None: - self._temperature_timer.cancel() - self._temperature_timer = RepeatedTimer(0.5, self._poll_temperature, run_first=True) - self._temperature_timer.start() - else: - if self._temperature_timer is not None: - self._temperature_timer.cancel() - if newState == self.STATE_CLOSED or newState == self.STATE_CLOSED_WITH_ERROR: if settings().get(["feature", "sdSupport"]): self._sdFileList = False @@ -480,7 +467,7 @@ class MachineCom(object): specialcmd = cmd[1:].lower() if "togglestatusreport" in specialcmd: if self._temperature_timer is None: - self._temperature_timer = RepeatedTimer(0.5, self._poll_temperature, run_first=True) + self._temperature_timer = RepeatedTimer(1, self._poll_temperature, run_first=True) self._temperature_timer.start() else: self._temperature_timer.cancel() @@ -1416,7 +1403,7 @@ class MachineCom(object): #self._temperature_timer = RepeatedTimer(lambda: get_interval("temperature"), self._poll_temperature, run_first=True) if self._temperature_timer is not None: self._temperature_timer.cancel() - self._temperature_timer = RepeatedTimer(0.5, self._poll_temperature, run_first=True) + self._temperature_timer = RepeatedTimer(1, self._poll_temperature, run_first=True) self._temperature_timer.start() if(nextState == None): From 9d383f303eb90b0743f114cbe2da7622d90cd352 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 18:46:00 +0200 Subject: [PATCH 18/38] added /disconnect to help message --- src/octoprint/util/comm_acc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index dcecbf03..025a6f16 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -491,6 +491,7 @@ class MachineCom(object): self._log("available commands are:") self._log(" /togglestatusreport") self._log(" /setstatusfrequency ") + self._log(" /disconnect") return eepromCmd = re.search("^\$[0-9]+=.+$", cmd) From 121716fd1a896e979f106c34e141703dfe7f13a1 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 10:36:12 +0200 Subject: [PATCH 19/38] added status report queued logic to handle allready queued '?' --- src/octoprint/util/comm_acc.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 025a6f16..db8160a9 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -175,6 +175,7 @@ class MachineCom(object): self.acc_line_lengths = [] # store char count of all send commands until ok is received self._clear_to_send = CountedEvent(max=10, name="comm.clear_to_send") self._send_queue = TypedQueue() + self._status_report_queued = False self._temperature_timer = None self._sd_status_timer = None @@ -1730,6 +1731,10 @@ class MachineCom(object): """ try: + if command == "?" and self._status_report_queued == True: + return + elif command == "?" and self._status_report_queued == False: + self._status_report_queued = True self._send_queue.put((command, linenumber, command_type)) except TypeAlreadyInQueue as e: self._logger.debug("Type already in queue: " + e.type) @@ -1754,6 +1759,9 @@ class MachineCom(object): # wait until we have something in the queue entry = self._send_queue.get() + if entry == "?": + self._status_report_queued = False + # make sure we are still active if not self._send_queue_active: break From e94890a8071e16ea418d78b932afde75a2952bd7 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 10:47:55 +0200 Subject: [PATCH 20/38] changed if statement to check for '?' IN command --- src/octoprint/util/comm_acc.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index db8160a9..d8ee0db1 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1731,10 +1731,11 @@ class MachineCom(object): """ try: - if command == "?" and self._status_report_queued == True: - return - elif command == "?" and self._status_report_queued == False: - self._status_report_queued = True + if "?" in command: + if self._status_report_queued is True: + return + else: + self._status_report_queued = True self._send_queue.put((command, linenumber, command_type)) except TypeAlreadyInQueue as e: self._logger.debug("Type already in queue: " + e.type) From 730033ef8280bf105c3c50667573a9f984fabc11 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 10:56:28 +0200 Subject: [PATCH 21/38] added debug message --- src/octoprint/util/comm_acc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index d8ee0db1..16301222 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1732,6 +1732,7 @@ class MachineCom(object): try: if "?" in command: + self._log("--- found ?: ", command) if self._status_report_queued is True: return else: From 54913c11547959f02527b4141a53d64c65317853 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 11:11:04 +0200 Subject: [PATCH 22/38] added debug message --- src/octoprint/util/comm_acc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 16301222..65b34fc5 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1732,7 +1732,8 @@ class MachineCom(object): try: if "?" in command: - self._log("--- found ?: ", command) + string = "--- found ?: %s" % command + self._log(string) if self._status_report_queued is True: return else: From 85ffe73b9822415a88cf6797098a3355fa9c0c34 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 11:22:05 +0200 Subject: [PATCH 23/38] blabla bug? --- src/octoprint/util/comm_acc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 65b34fc5..d368fca5 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1762,7 +1762,7 @@ class MachineCom(object): # wait until we have something in the queue entry = self._send_queue.get() - if entry == "?": + if "?" in entry: self._status_report_queued = False # make sure we are still active From 76324792e86c9993bc7ce2429df8ffe29926f6c8 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 11:31:01 +0200 Subject: [PATCH 24/38] blabla bug? --- src/octoprint/util/comm_acc.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index d368fca5..dcad2339 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1737,6 +1737,7 @@ class MachineCom(object): if self._status_report_queued is True: return else: + self._log("--- True") self._status_report_queued = True self._send_queue.put((command, linenumber, command_type)) except TypeAlreadyInQueue as e: @@ -1763,6 +1764,7 @@ class MachineCom(object): entry = self._send_queue.get() if "?" in entry: + self._log("--- False") self._status_report_queued = False # make sure we are still active From 546b6e81af86223badfb3df08ac10b52bfa73442 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 11:54:03 +0200 Subject: [PATCH 25/38] blabla bug? --- src/octoprint/util/comm_acc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index dcad2339..f3b1c431 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1758,6 +1758,7 @@ class MachineCom(object): if(self.RX_BUFFER_SIZE - sum(self.acc_line_lengths) - len(p_command) < 5): time.sleep(0.001) + self._log("--- wait") continue # wait until we have something in the queue From d1b6e91fea2ba8b9917f659178f2a45573d933da Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 12:24:34 +0200 Subject: [PATCH 26/38] changed _clear_to_send.set() position --- src/octoprint/util/comm_acc.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index f3b1c431..a437d86b 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -958,7 +958,6 @@ class MachineCom(object): # enqueue an M105 first thing if try_hello: self._sendCommand("?") - self._clear_to_send.set() while self._monitoring_active: try: @@ -1312,7 +1311,6 @@ class MachineCom(object): if not self._long_running_command: self._log("Communication timeout during printing, forcing a line") self._sendCommand("?") - self._clear_to_send.set() else: self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active") @@ -1738,6 +1736,7 @@ class MachineCom(object): return else: self._log("--- True") + self._clear_to_send.set() self._status_report_queued = True self._send_queue.put((command, linenumber, command_type)) except TypeAlreadyInQueue as e: @@ -1758,7 +1757,6 @@ class MachineCom(object): if(self.RX_BUFFER_SIZE - sum(self.acc_line_lengths) - len(p_command) < 5): time.sleep(0.001) - self._log("--- wait") continue # wait until we have something in the queue From d6b01068acc108df980fa8d8e97b87bbe90c2643 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 12:44:53 +0200 Subject: [PATCH 27/38] revert _clear_to_send.set() position --- src/octoprint/util/comm_acc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index a437d86b..dcad2339 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -958,6 +958,7 @@ class MachineCom(object): # enqueue an M105 first thing if try_hello: self._sendCommand("?") + self._clear_to_send.set() while self._monitoring_active: try: @@ -1311,6 +1312,7 @@ class MachineCom(object): if not self._long_running_command: self._log("Communication timeout during printing, forcing a line") self._sendCommand("?") + self._clear_to_send.set() else: self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active") @@ -1736,7 +1738,6 @@ class MachineCom(object): return else: self._log("--- True") - self._clear_to_send.set() self._status_report_queued = True self._send_queue.put((command, linenumber, command_type)) except TypeAlreadyInQueue as e: From 68e49049726cb7629e7846159edd3bb67e32d9f2 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 13:49:06 +0200 Subject: [PATCH 28/38] more debug messages --- src/octoprint/util/comm_acc.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index dcad2339..12b19a9b 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1761,7 +1761,9 @@ class MachineCom(object): continue # wait until we have something in the queue + self._log("+++ start get") entry = self._send_queue.get() + self._log("+++ start get") if "?" in entry: self._log("--- False") @@ -1815,7 +1817,9 @@ class MachineCom(object): self._clear_to_send.clear() # now we just wait for the next clear and then start again + self._log("*** start wait") self._clear_to_send.wait() + self._log("*** end wait") except: self._logger.exception("Caught an exception in the send loop") self._log("Closing down send loop") From 1593baf16b3de4c3ba6a1eff7c3fa8119adf3649 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 13:55:57 +0200 Subject: [PATCH 29/38] more debug messages --- src/octoprint/util/comm_acc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 12b19a9b..a6e1d699 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1763,7 +1763,7 @@ class MachineCom(object): # wait until we have something in the queue self._log("+++ start get") entry = self._send_queue.get() - self._log("+++ start get") + self._log("+++ end get") if "?" in entry: self._log("--- False") From 168a062dbb1eff604cda09d915a0f3f40a6049f5 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 14:25:40 +0200 Subject: [PATCH 30/38] more debug messages --- src/octoprint/util/comm_acc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index a6e1d699..5115a0c5 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1739,6 +1739,7 @@ class MachineCom(object): else: self._log("--- True") self._status_report_queued = True + self._log(">>> put: %s" % command) self._send_queue.put((command, linenumber, command_type)) except TypeAlreadyInQueue as e: self._logger.debug("Type already in queue: " + e.type) From 6a36933c25ff8e9dcc33d956f606d8f6676eb024 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 14:40:12 +0200 Subject: [PATCH 31/38] removed some debug messages --- src/octoprint/util/comm_acc.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 5115a0c5..b9fc2fe9 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -175,7 +175,6 @@ class MachineCom(object): self.acc_line_lengths = [] # store char count of all send commands until ok is received self._clear_to_send = CountedEvent(max=10, name="comm.clear_to_send") self._send_queue = TypedQueue() - self._status_report_queued = False self._temperature_timer = None self._sd_status_timer = None @@ -1731,14 +1730,6 @@ class MachineCom(object): """ try: - if "?" in command: - string = "--- found ?: %s" % command - self._log(string) - if self._status_report_queued is True: - return - else: - self._log("--- True") - self._status_report_queued = True self._log(">>> put: %s" % command) self._send_queue.put((command, linenumber, command_type)) except TypeAlreadyInQueue as e: @@ -1762,13 +1753,7 @@ class MachineCom(object): continue # wait until we have something in the queue - self._log("+++ start get") entry = self._send_queue.get() - self._log("+++ end get") - - if "?" in entry: - self._log("--- False") - self._status_report_queued = False # make sure we are still active if not self._send_queue_active: @@ -1818,9 +1803,7 @@ class MachineCom(object): self._clear_to_send.clear() # now we just wait for the next clear and then start again - self._log("*** start wait") self._clear_to_send.wait() - self._log("*** end wait") except: self._logger.exception("Caught an exception in the send loop") self._log("Closing down send loop") From 4fe4945f2441ba7640c865166b3ed2a73f8de44f Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 14:52:26 +0200 Subject: [PATCH 32/38] more debug messages --- src/octoprint/util/comm_acc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index b9fc2fe9..00ce61d9 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1753,6 +1753,7 @@ class MachineCom(object): continue # wait until we have something in the queue + print "qsize = " % self._send_queue.qsize() entry = self._send_queue.get() # make sure we are still active From 5cc305e72f295b83aa62f5a1cc4960d3dbc2b2b8 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 15:03:51 +0200 Subject: [PATCH 33/38] more debug messages --- src/octoprint/util/comm_acc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 00ce61d9..53ff8bce 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1753,7 +1753,8 @@ class MachineCom(object): continue # wait until we have something in the queue - print "qsize = " % self._send_queue.qsize() + string = "qsize = " % self._send_queue.qsize() + self._log(string) entry = self._send_queue.get() # make sure we are still active From 40b9eabd808d4e53cd0e10f6867df25eaf7b321a Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 15:13:03 +0200 Subject: [PATCH 34/38] more debug messages --- src/octoprint/util/comm_acc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 53ff8bce..e8ccad21 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1753,7 +1753,7 @@ class MachineCom(object): continue # wait until we have something in the queue - string = "qsize = " % self._send_queue.qsize() + string = "qsize = %s" % self._send_queue.qsize() self._log(string) entry = self._send_queue.get() From e93ffe0dba150b07d418e284ca56f1fdd4dc9663 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 16:40:02 +0200 Subject: [PATCH 35/38] removed cmd_type temperature_poll --- src/octoprint/util/comm_acc.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index e8ccad21..dbaf24fd 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1386,7 +1386,8 @@ class MachineCom(object): """ if self.isOperational() and not self.isStreaming() and not self._long_running_command and not self._heating: - self.sendCommand("?", cmd_type="temperature_poll") + #self.sendCommand("?", cmd_type="temperature_poll") + self.sendCommand("?") def _poll_sd_status(self): """ @@ -1753,8 +1754,6 @@ class MachineCom(object): continue # wait until we have something in the queue - string = "qsize = %s" % self._send_queue.qsize() - self._log(string) entry = self._send_queue.get() # make sure we are still active From 32ebec4973e8316a0f7cb8ab2bf692551d2ecfbb Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 16:48:40 +0200 Subject: [PATCH 36/38] blabla --- src/octoprint/util/comm_acc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index dbaf24fd..59cbe44f 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1387,7 +1387,7 @@ class MachineCom(object): if self.isOperational() and not self.isStreaming() and not self._long_running_command and not self._heating: #self.sendCommand("?", cmd_type="temperature_poll") - self.sendCommand("?") + self._sendCommand("?") def _poll_sd_status(self): """ From 40343d5b89e64bbae4acf5d9e75019599b9d0c5c Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 17:00:26 +0200 Subject: [PATCH 37/38] removed rest of debug messages --- src/octoprint/util/comm_acc.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 59cbe44f..2c7ca3b7 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1731,7 +1731,6 @@ class MachineCom(object): """ try: - self._log(">>> put: %s" % command) self._send_queue.put((command, linenumber, command_type)) except TypeAlreadyInQueue as e: self._logger.debug("Type already in queue: " + e.type) From b97995323a18f6e943d060bd028141216a772781 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 17:41:55 +0200 Subject: [PATCH 38/38] added stop of temperature_poll during printing --- src/octoprint/util/comm_acc.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 2c7ca3b7..83d6b82f 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -256,6 +256,15 @@ class MachineCom(object): if self._state == newState: return + if newState == self.STATE_PRINTING: + if self._temperature_timer is not None: + self._temperature_timer.cancel() + elif newState == self.STATE_OPERATIONAL: + if self._temperature_timer is not None: + self._temperature_timer.cancel() + self._temperature_timer = RepeatedTimer(1, self._poll_temperature, run_first=True) + self._temperature_timer.start() + if newState == self.STATE_CLOSED or newState == self.STATE_CLOSED_WITH_ERROR: if settings().get(["feature", "sdSupport"]): self._sdFileList = False @@ -1386,8 +1395,7 @@ class MachineCom(object): """ if self.isOperational() and not self.isStreaming() and not self._long_running_command and not self._heating: - #self.sendCommand("?", cmd_type="temperature_poll") - self._sendCommand("?") + self.sendCommand("?", cmd_type="temperature_poll") def _poll_sd_status(self): """