Made communication mode more error resilient

master
Bryan Mayland 2013-06-20 17:41:10 +02:00 committed by Gina Häußge
parent 8b702db0d0
commit 50914df07a
1 changed files with 202 additions and 194 deletions

View File

@ -581,6 +581,7 @@ class MachineCom(object):
startSeen = not settings().getBoolean(["feature", "waitForStartOnConnect"])
heatingUp = False
while True:
try:
line = self._readline()
if line == None:
break
@ -795,6 +796,13 @@ class MachineCom(object):
self._sendNext()
elif "resend" in line.lower() or "rs" in line:
self._handleResendRequest(line)
except:
self._logger.exception("Something crashed inside the serial connection loop, please report this in OctoPrint's bug tracker:")
errorMsg = "Please see octoprint.log for details"
self._log(errorMsg)
self._errorValue = errorMsg
self._changeState(self.STATE_ERROR)
self._log("Connection closed, closing down monitor")
def _handleResendRequest(self, line):
@ -849,7 +857,7 @@ class MachineCom(object):
return ret
def close(self, isError = False):
if self._serial != None:
if self._serial is not None:
self._serial.close()
if isError:
self._changeState(self.STATE_CLOSED_WITH_ERROR)
@ -867,7 +875,7 @@ class MachineCom(object):
# Make sure we are only handling one sending job at a time
with self._sendingLock:
self._logger.debug("Resending line %d, delta is %d, history log is %s items strong" % (self._currentLine - self._resendDelta, self._resendDelta, len(self._lastLines)))
cmd = self._lastLines[-(self._resendDelta+1)]
cmd = self._lastLines[-(self._resendDelta + 1)]
lineNumber = self._currentLine - self._resendDelta
self._doSendWithChecksum(cmd, lineNumber)