From 121716fd1a896e979f106c34e141703dfe7f13a1 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 12 Oct 2015 10:36:12 +0200 Subject: [PATCH 01/20] 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 02/20] 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 03/20] 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 04/20] 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 05/20] 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 06/20] 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 07/20] 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 08/20] 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 09/20] 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 10/20] 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 11/20] 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 12/20] 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 13/20] 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 14/20] 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 15/20] 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 16/20] 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 17/20] 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 18/20] 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 19/20] 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 20/20] 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): """