diff --git a/src/octoprint/plugins/virtual_printer/virtual.py b/src/octoprint/plugins/virtual_printer/virtual.py index e231fb7a..45645653 100644 --- a/src/octoprint/plugins/virtual_printer/virtual.py +++ b/src/octoprint/plugins/virtual_printer/virtual.py @@ -25,7 +25,8 @@ class VirtualPrinter(object): sleep_after_regex = re.compile("sleep_after ([GMTF]\d+) (\d+)") sleep_after_next_regex = re.compile("sleep_after_next ([GMTF]\d+) (\d+)") custom_action_regex = re.compile("action_custom ([a-zA-Z0-9_]+)(\s+.*)?") - prepare_ok_regex = re.compile("prepare_ok (.*)?") + prepare_ok_regex = re.compile("prepare_ok (.*)") + send_regex = re.compile("send (.*)") def __init__(self, seriallog_handler=None, read_timeout=5.0, write_timeout=10.0): import logging @@ -560,6 +561,11 @@ class VirtualPrinter(object): | Sleeps s after each execution of sleep_after_next | Sleeps s after execution of next + + # Misc + + send + | Sends back """ for line in usage.split("\n"): self._send("echo: {}".format(line.strip())) @@ -589,6 +595,7 @@ class VirtualPrinter(object): sleep_after_next_match = VirtualPrinter.sleep_after_next_regex.match(data) custom_action_match = VirtualPrinter.custom_action_regex.match(data) prepare_ok_match = VirtualPrinter.prepare_ok_regex.match(data) + send_match = VirtualPrinter.send_regex.match(data) if sleep_match is not None: interval = int(sleep_match.group(1)) @@ -612,6 +619,8 @@ class VirtualPrinter(object): elif prepare_ok_match is not None: ok = prepare_ok_match.group(1) self._prepared_oks.append(ok) + elif send_match is not None: + self._send(send_match.group(1)) except: pass diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 562a3b3a..15bbf5eb 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -1392,6 +1392,18 @@ class MachineCom(object): self._log("There was a timeout while trying to connect to the printer") self.close(wait=False) + ### Operational (idle or busy) + elif self._state in (self.STATE_OPERATIONAL, + self.STATE_PRINTING, + self.STATE_PAUSED, + self.STATE_TRANSFERING_FILE): + if line == "start": # exact match, to be on the safe side + message = "Printer sent 'start' while already operational. External reset? " \ + "Resetting line numbers to be on the safe side" + self._log(message) + self._logger.warn(message) + self.resetLineNumbers() + except: self._logger.exception("Something crashed inside the serial connection loop, please report this in OctoPrint's bug tracker:")