+ 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 newPos == 1 or self._gcodePos > newPos + 100:
+ self._callback.mcMessage("Print canceled due to loss of communication to printer (USB unplugged or power lost)")
+ self.cancelPrint()
+ else:
+ self._gcodePos = newPos
+ elif self._state == self.STATE_PAUSED:
+ #Even when printing request the temperature every 5 seconds.
+ if time.time() > tempRequestTimeout:
+ if self._extruderCount > 0:
+ self._temperatureRequestExtruder = (self._temperatureRequestExtruder + 1) % self._extruderCount
+ self.sendCommand("M105 T%d" % (self._temperatureRequestExtruder))
+ else:
+ self.sendCommand("M105")
+ tempRequestTimeout = time.time() + 5
+ if line == '' and time.time() > timeout:
+ line = 'ok'
+ if 'ok' in line:
+ self.receivedOK()
+ timeout = time.time() + 5
+ if not self._commandQueue.empty():
+ self._sendCommand(self._commandQueue.get())
+ elif 'start' in line:
+ self._currentCommands = []
+