diff --git a/src/octoprint/plugins/virtual_printer/virtual.py b/src/octoprint/plugins/virtual_printer/virtual.py index 1d9adba6..77b79ead 100644 --- a/src/octoprint/plugins/virtual_printer/virtual.py +++ b/src/octoprint/plugins/virtual_printer/virtual.py @@ -16,7 +16,7 @@ from serial import SerialTimeoutException from octoprint.settings import settings from octoprint.plugin import plugin_manager -class VirtualPrinter(): +class VirtualPrinter(object): command_regex = re.compile("[GM]\d+") sleep_regex = re.compile("sleep (\d+)") sleep_after_regex = re.compile("sleep_after ([GM]\d+) (\d+)") @@ -25,7 +25,7 @@ class VirtualPrinter(): def __init__(self, read_timeout=5.0, write_timeout=10.0): import logging - self._logger = logging.getLogger("octoprint.plugin.virtual_printer.VirtualPrinter") + self._logger = logging.getLogger("octoprint.plugins.virtual_printer.VirtualPrinter") self._read_timeout = read_timeout self._write_timeout = write_timeout @@ -108,6 +108,24 @@ class VirtualPrinter(): return "VIRTUAL(read_timeout={read_timeout},write_timeout={write_timeout},options={options})"\ .format(read_timeout=self._read_timeout, write_timeout=self._write_timeout, options=settings().get(["devel", "virtualPrinter"])) + @property + def timeout(self): + return self._read_timeout + + @timeout.setter + def timeout(self, value): + self._logger.debug("Setting read timeout to {}s".format(value)) + self._read_timeout = value + + @property + def write_timeout(self): + return self._write_timeout + + @write_timeout.setter + def write_timeout(self, value): + self._logger.debug("Setting write timeout to {}s".format(value)) + self._write_timeout = value + def _clearQueue(self, queue): try: while queue.get(block=False): diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 84fe8d80..d135e798 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -81,6 +81,7 @@ default_settings = { "detection": 0.5, "connection": 10, "communication": 30, + "heatup": 2, "temperature": 5, "sdStatus": 1 }, diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index bd84f70a..e9bb8fb6 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -956,7 +956,10 @@ class MachineCom(object): if line is None: break if line.strip() is not "": - self._timeout = get_new_timeout("communication", self._timeout_intervals) + if self._heating: + self._timeout = get_new_timeout("heatup", self._timeout_intervals) + else: + self._timeout = get_new_timeout("communication", self._timeout_intervals) ##~~ debugging output handling if line.startswith("//"): @@ -1059,8 +1062,7 @@ class MachineCom(object): elif ' T:' in line or line.startswith('T:') or ' T0:' in line or line.startswith('T0:') or ((' B:' in line or line.startswith('B:')) and not 'A:' in line): if not disable_external_heatup_detection and not line.strip().startswith("ok") and not self._heating: self._logger.debug("Externally triggered heatup detected") - self._heating = True - self._heatupWaitStartTime = time.time() + self._track_heatup() self._processTemperatures(line) self._callback.on_comm_temperature_update(self._temp, self._bedTemp) @@ -1259,10 +1261,7 @@ class MachineCom(object): self._currentTool = self._formerTool self._formerTool = None - if self._heatupWaitStartTime: - self._heatupWaitTimeLost = self._heatupWaitTimeLost + (time.time() - self._heatupWaitStartTime) - self._heatupWaitStartTime = None - self._heating = False + self._finish_heatup() if not self._state in (self.STATE_PRINTING, self.STATE_OPERATIONAL, self.STATE_PAUSED): return @@ -1291,6 +1290,10 @@ class MachineCom(object): self._resendSameCommand() self._clear_to_send.set() + elif self._heating: + self._logger.debug("Timeout while in an active heatup, considering heatup to be over then") + self._finish_heatup() + else: self._log("Communication timeout while printing, trying to trigger response from printer. " + general_message) self._sendCommand("M105", cmd_type="temperature") @@ -1298,6 +1301,18 @@ class MachineCom(object): return + def _track_heatup(self): + self._heating = True + self._heatupWaitStartTime = time.time() + self._serial.timeout = settings().getFloat(["serial", "timeout", "heatup"]) + + def _finish_heatup(self): + if self._heatupWaitStartTime: + self._heatupWaitTimeLost = self._heatupWaitTimeLost + (time.time() - self._heatupWaitStartTime) + self._heatupWaitStartTime = None + self._heating = False + self._serial.timeout = settings().getFloat(["serial", "timeout", "communication"]) + def _continue_sending(self): if self._state == self.STATE_PRINTING: if not self._sendFromQueue() and not self.isSdPrinting(): @@ -2036,15 +2051,13 @@ class MachineCom(object): pass def _gcode_M109_sent(self, cmd, cmd_type=None): - self._heatupWaitStartTime = time.time() self._long_running_command = True - self._heating = True + self._track_heatup() self._gcode_M104_sent(cmd, cmd_type, wait=True) def _gcode_M190_sent(self, cmd, cmd_type=None): - self._heatupWaitStartTime = time.time() self._long_running_command = True - self._heating = True + self._track_heatup() self._gcode_M140_sent(cmd, cmd_type, wait=True) def _gcode_M110_sending(self, cmd, cmd_type=None):