From d0e9b1546f26ef8970679aea9d3a612b56523a44 Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Fri, 7 Aug 2015 16:09:08 -0400 Subject: [PATCH] Do not allow firmware to ask for a resend of more than 10 lines. This is because if power gets interrupted or reset button is pressed, then it will ask us to resend from line 0, and it will cause the print to be restarted, which can be dangerous if there is a print half-finished on the bed. Fixes T37 --- Cura/util/machineCom.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Cura/util/machineCom.py b/Cura/util/machineCom.py index 5fe86611..9a516b61 100644 --- a/Cura/util/machineCom.py +++ b/Cura/util/machineCom.py @@ -487,11 +487,20 @@ class MachineCom(object): else: self._sendNext() elif "resend" in line.lower() or "rs" in line: + newPos = self._gcodePos try: - self._gcodePos = int(line.replace("N:"," ").replace("N"," ").replace(":"," ").split()[-1]) + newPos = int(line.replace("N:"," ").replace("N"," ").replace(":"," ").split()[-1]) except: if "rs" in line: - self._gcodePos = int(line.split()[1]) + newPos = int(line.split()[1]) + # If we need to resend more than 10 lines, we can assume that the machine + # was shut down and turned back on or something else that's weird just happened. + # In that case, it can be dangerous to restart the print, so we'd better kill it + if self._gcodePos > newPos + 10: + self.cancelPrint() + else: + self._gcodePos = newPos + self._log("Connection closed, closing down monitor") def _setBaudrate(self, baudrate): -- 2.30.2