示例#1
0
    def connect(self, port=None, baudrate=None, profile=None):
        """
         Connects to a BVC printer. Ignores port, baudrate parameters.
         They are kept just for interface compatibility
        """
        if self._comm is not None:
            self._comm.close()

        self._comm = BeeCom(callbackObject=self,
                            printerProfileManager=self._printerProfileManager)
        self._comm.confirmConnection()

        bee_commands = self._comm.getCommandsInterface()

        # homes all axis
        if bee_commands is not None and bee_commands.isPrinting() is False:
            bee_commands.home()

        # selects the printer profile based on the connected printer name
        printer_name = self.get_printer_name()

        # converts the name to the id
        printer_id = None
        if printer_name is not None:
            printer_id = printer_name.lower().replace(' ', '')
        self._printerProfileManager.select(printer_id)

        # if the printer is printing or in shutdown mode selects the last selected file for print
        # and starts the progress monitor
        lastFile = settings().get(['lastPrintJobFile'])
        if lastFile is not None and (self.is_shutdown() or self.is_printing()
                                     or self.is_paused()):
            # Calls the select_file with the real previous PrintFileInformation object to recover the print status
            self.select_file(self._currentPrintJobFile, False)
            self._comm.startPrintStatusProgressMonitor()

        # gets current Filament profile data
        self._currentFilamentProfile = self.getSelectedFilamentProfile()

        # subscribes event handlers
        eventManager().subscribe(Events.PRINT_CANCELLED,
                                 self.on_print_cancelled)
        eventManager().subscribe(Events.PRINT_CANCELLED_DELETE_FILE,
                                 self.on_print_cancelled_delete_file)
        eventManager().subscribe(Events.PRINT_DONE, self.on_print_finished)
示例#2
0
    def disconnect(self):
        """
        Closes the connection to the printer.
        """
        super(BeePrinter, self).disconnect()

        # Instantiates the comm object just to allow for a state to be returned. This is a workaround
        # to allow to have the "Connecting..." string when the printer is connecting when the comm object is None...
        # This forces the printer to be used in auto-connect mode
        self._comm = BeeCom(callbackObject=self,
                            printerProfileManager=self._printerProfileManager)
        self._comm.confirmConnection()

        # Starts the connection monitor thread
        import threading
        bvc_conn_thread = threading.Thread(
            target=detect_bvc_printer_connection, args=(self.connect, ))
        bvc_conn_thread.daemon = True
        bvc_conn_thread.start()