From fa586426fa22a646eb76180aae8c014cd3399d2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sat, 12 Jul 2014 19:55:13 +0200 Subject: [PATCH] Connection handshake should now be more error resilient --- src/octoprint/comm/protocol/repetier.py | 2 +- .../comm/protocol/reprap/__init__.py | 21 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/octoprint/comm/protocol/repetier.py b/src/octoprint/comm/protocol/repetier.py index 0db58c5d6..f4f76b93d 100644 --- a/src/octoprint/comm/protocol/repetier.py +++ b/src/octoprint/comm/protocol/repetier.py @@ -43,7 +43,7 @@ class RepetierTextualProtocol(RepRapProtocol): pass if key is None: - return + return False if key in current_temperatures and current_temperatures[key] is not None and isinstance(current_temperatures[key], tuple): (actual, old_target) = current_temperatures[key] diff --git a/src/octoprint/comm/protocol/reprap/__init__.py b/src/octoprint/comm/protocol/reprap/__init__.py index 5f2077af8..20d1b280e 100644 --- a/src/octoprint/comm/protocol/reprap/__init__.py +++ b/src/octoprint/comm/protocol/reprap/__init__.py @@ -317,13 +317,14 @@ class RepRapProtocol(Protocol): return # initial handshake with the firmware - if self._state == State.CONNECTED: - if not self._startSeen and RepRapProtocol.MESSAGE_START(message): - self._startSeen = True - self._clear_for_send.set() - elif self._startSeen: - if RepRapProtocol.MESSAGE_OK(message): - self._changeState(State.OPERATIONAL) + if not self._startSeen and RepRapProtocol.MESSAGE_START(message): + # if we did not see "start" from the firmware yet and we just did we are cleared for sending + self._startSeen = True + self._clear_for_send.set() + + if self._state == State.CONNECTED and self._startSeen and RepRapProtocol.MESSAGE_OK(message): + # if we are currently connected, have seen start and just gotten an "ok" we are now operational + self._changeState(State.OPERATIONAL) # resend == roll back time a bit if RepRapProtocol.MESSAGE_RESEND(message): @@ -347,12 +348,16 @@ class RepRapProtocol(Protocol): def onTimeoutReceived(self, source): if self._transport != source: return + + if self._state == State.CONNECTED: + # it might be that the printer controller did not reset on connect and therefore we won't ever see a start => try clearing for send + self._clear_for_send.set() self._send_temperature_query(withType=True) ##~~ private def _evaluate_firmware_specific_messages(self, source, message): - pass + return True def _send(self, command, highPriority=False, commandType=None, withChecksum=None, withLinenumber=None): if withChecksum is None: