Example #1
0
 def start_printing(self, filename: str) -> None:
     # the printer's firmware is weird when the file is in a subdirectory. we need to
     # send M23 to select the file with its full path and then M6030 with just the
     # basename.
     self.select_file(filename)
     response = self._send_and_read(
         (f"M6030 '{os.path.basename(filename)}'").encode(),
         # the mainboard takes longer to reply to this command, so we override the
         # timeout to 2 seconds
         timeout_secs=2.0,
     )
     if "ok" not in response:
         raise UnexpectedPrinterResponse(response)
Example #2
0
 def test_error_handling_while_stopping_print(self) -> None:
     self.printer_mock.stop_printing.side_effect = UnexpectedPrinterResponse(
         "foobar\r\n")
     response = self.client.post("/api/printer/command/cancel_print")
     expect(response.status_code).to_equal(500)
     expect(response.get_json()).to_equal({
         "title":
         "Unexpected Printer Response",
         "description":
         "The printer returned an unexpected response: " + "'foobar\\r\\n'",
         "traceback":
         ANY,
     })
     self.printer_mock.stop_printing.assert_called_once_with()
Example #3
0
 def _extract_response_with_regex(self, regex: str, data: str) -> Match[str]:
     match = re.search(regex, data)
     if match is None:
         raise UnexpectedPrinterResponse(data)
     return match
Example #4
0
 def stop_motors(self) -> None:
     response = self._send_and_read(b"M112")
     if "ok" not in response:
         raise UnexpectedPrinterResponse(response)
Example #5
0
 def stop_printing(self) -> None:
     response = self._send_and_read(b"M33")
     if "Error" in response:
         raise UnexpectedPrinterResponse(response)
Example #6
0
 def resume_printing(self) -> None:
     response = self._send_and_read(b"M24")
     if "ok" not in response:
         raise UnexpectedPrinterResponse(response)
Example #7
0
 def move_to_home(self) -> None:
     response = self._send_and_read(b"G28")
     if "ok" not in response:
         raise UnexpectedPrinterResponse(response)
Example #8
0
 def move_by(self, z_dist_mm: float, mm_per_min: int = 600) -> None:
     response = self._send_and_read(
         (f"G0 Z{z_dist_mm:.1f} F{mm_per_min} I0").encode()
     )
     if "ok" not in response:
         raise UnexpectedPrinterResponse(response)
Example #9
0
 def select_file(self, filename: str) -> None:
     response = self._send_and_read((f"M23 /{filename}").encode())
     if "File opened" not in response:
         raise UnexpectedPrinterResponse(response)