No endless circles if we can't write any bytes to serial

This commit is contained in:
Gina Häußge 2016-07-21 16:10:00 +02:00
parent c6225aa834
commit 3614033b0d
2 changed files with 18 additions and 0 deletions

View file

@ -85,6 +85,7 @@ default_settings = {
"temperature": 5,
"sdStatus": 1
},
"maxWritePasses": 5,
"additionalPorts": [],
"longRunningCommands": ["G4", "G28", "G29", "G30", "G32", "M400", "M226"],
"checksumRequiringCommands": ["M110"],

View file

@ -236,6 +236,8 @@ class MachineCom(object):
except:
pass
self._max_write_passes = settings().getInt(["serial", "maxWritePasses"])
self._hello_command = settings().get(["serial", "helloCommand"])
self._trigger_ok_for_m29 = settings().getBoolean(["serial", "triggerOkForM29"])
@ -1945,8 +1947,11 @@ class MachineCom(object):
cmd += "\n"
written = 0
passes = 0
while written < len(cmd):
to_send = cmd[written:]
old_written = written
try:
written += self._serial.write(to_send)
except serial.SerialTimeoutException:
@ -1968,6 +1973,18 @@ class MachineCom(object):
self.close(is_error=True)
break
if old_written == written:
# nothing written this pass
passes += 1
if passes > self._max_write_passes:
# nothing written in max consecutive passes, we give up
message = "Could not write anything to the serial port in {} tries, something appears to be wrong with the printer communication".format(self._max_write_passes)
self._logger.error(message)
self._log(message)
self._errorValue = "Could not write to serial port"
self.close(is_error=True)
break
##~~ command handlers
def _gcode_T_sent(self, cmd, cmd_type=None):