diff --git a/docs/development/virtual_printer.rst b/docs/development/virtual_printer.rst index 479cdc198..85d35c50e 100644 --- a/docs/development/virtual_printer.rst +++ b/docs/development/virtual_printer.rst @@ -57,60 +57,71 @@ You can simulate certain conditions and communications through the terminal tab All commands start with ``!!DEBUG:`` and are followed by the command you want to execute. For instance, sending ``!!DEBUG:action_disconnect`` will disconnect the printer. Sending ``!!DEBUG`` without command will show a help -message with all the available commands. +message with all the available commands: -Action Triggers -............... +.. code-block:: none -``action_pause`` -Sends a "// action:pause" action trigger to the host. + OctoPrint Virtual Printer debug commands -``action_resume`` -Sends a "// action:resume" action trigger to the host. + help + ? + | This help. -``action_disconnect`` -Sends a "// action:disconnect" action trigger to the host. + # Action Triggers -``action_custom [ ]`` -Sends a custom "// action: " action trigger to the host. + action_pause + | Sends a "// action:pause" action trigger to the host. + action_resume + | Sends a "// action:resume" action trigger to the host. + action_disconnect + | Sends a "// action:disconnect" action trigger to the + | host. + action_custom [ ] + | Sends a custom "// action: " + | action trigger to the host. -Communication Errors -.................... + # Communication Errors -``dont_answer`` -Will not acknowledge the next command. + dont_answer + | Will not acknowledge the next command. + go_awol + | Will completely stop replying + trigger_resend_lineno + | Triggers a resend error with a line number mismatch + trigger_resend_checksum + | Triggers a resend error with a checksum mismatch + trigger_missing_checksum + | Triggers a resend error with a missing checksum + trigger_missing_lineno + | Triggers a "no line number with checksum" error w/o resend request + drop_connection + | Drops the serial connection + prepare_ok + | Will cause to be enqueued for use, + | will be used instead of actual "ok" -``go_awol`` -Will completely stop replying. + # Reply Timing / Sleeping -``trigger_resend_lineno`` -Triggers a resend error with a line number mismatch + sleep + | Sleep s + sleep_after + | Sleeps s after each execution of + sleep_after_next + | Sleeps s after execution of next -``trigger_resend_checksum`` -Triggers a resend error with a checksum mismatch + # SD printing -``drop_connection`` -Drops the serial connection + start_sd + | Select and start printing file from SD + select_sd + | Select file from SD, don't start printing it yet. Use + | start_sd to start the print + cancel_sd + | Cancels an ongoing SD print -``prepare_ok `` -Will cause to be enqueued for use, will be used instead of actual "ok" + # Misc -Reply Timing / Sleeping -....................... -``sleep `` -Sleep s - -``sleep_after `` -Sleeps s after each execution of - -``sleep_after_next `` -Sleeps s after execution of next - -Misc -.... - -``help`` -Show the available commands. - -``send `` -Sends back + send + | Sends back + reset + | Simulates a reset. Internal state will be lost. diff --git a/src/octoprint/plugins/virtual_printer/virtual.py b/src/octoprint/plugins/virtual_printer/virtual.py index e37785151..3d9ada889 100644 --- a/src/octoprint/plugins/virtual_printer/virtual.py +++ b/src/octoprint/plugins/virtual_printer/virtual.py @@ -30,6 +30,7 @@ class VirtualPrinter(object): send_regex = re.compile("send (.*)") set_ambient_regex = re.compile("set_ambient ([-+]?[0-9]*\.?[0-9]+)") start_sd_regex = re.compile("start_sd (.*)") + select_sd_regex = re.compile("select_sd (.*)") def __init__(self, seriallog_handler=None, read_timeout=5.0, write_timeout=10.0): import logging @@ -736,7 +737,10 @@ class VirtualPrinter(object): # SD printing start_sd - | Start printing file from SD + | Select and start printing file from SD + select_sd + | Select file from SD, don't start printing it yet. Use + | start_sd to start the print cancel_sd | Cancels an ongoing SD print @@ -793,6 +797,7 @@ class VirtualPrinter(object): send_match = VirtualPrinter.send_regex.match(data) set_ambient_match = VirtualPrinter.set_ambient_regex.match(data) start_sd_match = VirtualPrinter.start_sd_regex.match(data) + select_sd_match = VirtualPrinter.select_sd_regex.match(data) if sleep_match is not None: interval = int(sleep_match.group(1)) @@ -822,8 +827,10 @@ class VirtualPrinter(object): self._ambient_temperature = float(set_ambient_match.group(1)) self._send("// set ambient temperature to {}".format(self._ambient_temperature)) elif start_sd_match is not None: - self._selectSdFile(start_sd_match.group(1)) + self._selectSdFile(start_sd_match.group(1), check_already_open=True) self._startSdPrint() + elif select_sd_match is not None: + self._selectSdFile(select_sd_match.group(1)) except: pass @@ -843,10 +850,14 @@ class VirtualPrinter(object): self._send(item) self._send("End file list") - def _selectSdFile(self, filename): + def _selectSdFile(self, filename, check_already_open=False): if filename.startswith("/"): filename = filename[1:] + file = os.path.join(self._virtualSd, filename.lower()) + if self._selectedSdFile == file and check_already_open: + return + if not os.path.exists(file) or not os.path.isfile(file): self._send("open failed, File: %s." % filename) else: