diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index d135e798..271f5c14 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -85,6 +85,7 @@ default_settings = { "temperature": 5, "sdStatus": 1 }, + "maxWritePasses": 5, "additionalPorts": [], "longRunningCommands": ["G4", "G28", "G29", "G30", "G32", "M400", "M226"], "checksumRequiringCommands": ["M110"], diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 269ec8cb..a1666833 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -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):