示例#1
0
    def _getResponse(self):
        """
        Auxiliar method to read the command response queue
        :return:
        """
        if self._beeConn is None:
            return None
        try:
            ret = self._responseQueue.get()
        except:
            self._log("Exception raised while reading from command response queue: %s" % (get_exception_string()))
            self._errorValue = get_exception_string()
            return None

        if ret == '':
            #self._log("Recv: TIMEOUT")
            return ''

        try:
            self._log("Recv: %s" % sanitize_ascii(ret))
        except ValueError as e:
            self._log("WARN: While reading last line: %s" % e)
            self._log("Recv: %r" % ret)

        return ret
示例#2
0
 def do_auto_connect(self, port, *args, **kwargs):
     try:
         self._logger.info("do_auto_connect")
         (autoport, baudrate) = self._settings.global_get(
             ["serial",
              "port"]), self._settings.global_get(["serial", "baudrate"])
         if not autoport:
             autoport = "AUTO"
         if not port:
             port = "AUTO"
         if autoport == "AUTO" or os.path.realpath(
                 autoport) == os.path.realpath(port):
             self._logger.info("realpath match")
             printer_profile = self._printer_profile_manager.get_default()
             profile = printer_profile[
                 "id"] if "id" in printer_profile else "_default"
             if not self._printer.is_closed_or_error():
                 self._logger.info(
                     "Not autoconnecting; printer already connected")
                 return
             self._logger.info(
                 "Attempting to connect to {0} at {1} with profile {2}".
                 format(autoport, baudrate, repr(profile)))
             self._printer.connect(port=autoport,
                                   baudrate=baudrate,
                                   profile=profile)
         else:
             self._logger.info("realpath no match")
             self._logger.info(
                 "Skipping auto connect on %s because it isn't %s" %
                 (os.path.realpath(port), os.path.realpath(autoport)))
     except:
         self._logger.error("Exception in do_auto_connect %s",
                            get_exception_string())
示例#3
0
    def _getResponse(self):
        """
        Auxiliar method to read the command response queue
        :return:
        """
        if self._beeConn is None:
            return None
        try:
            ret = self._responseQueue.get()
        except:
            self._log("Exception raised while reading from command response queue: %s" % (get_exception_string()))
            self._errorValue = get_exception_string()
            return None

        if ret == '':
            #self._log("Recv: TIMEOUT")
            return ''

        try:
            self._log("Recv: %s" % sanitize_ascii(ret))
        except ValueError as e:
            self._log("WARN: While reading last line: %s" % e)
            self._log("Recv: %r" % ret)

        return ret
示例#4
0
    def startPrint(self, pos=None):
        """
        Starts the printing operation
        :param pos: if the string 'memory' is passed the printer will print the last file in the printer's memory
        """
        if not self.isOperational() or self.isPrinting():
            return

        if self._currentFile is None and pos is None:
            raise ValueError("No file selected for printing")

        try:
            self._changeState(self.STATE_PREPARING_PRINT)

            if self.isSdFileSelected():
                print_resp = self._beeCommands.startSDPrint(self._currentFile.getFilename())

                if print_resp:
                    self._sd_status_timer = RepeatedTimer(self._timeout_intervals.get("sdStatus", 1.0), self._poll_sd_status, run_first=True)
                    self._sd_status_timer.start()
            elif pos == 'from_memory':
                print_resp = self._beeCommands.repeatLastPrint()
            else:
                print_resp = self._beeCommands.printFile(self._currentFile.getFilename())

            if print_resp is True:
                self._heatupWaitStartTime = time.time()
                self._heatupWaitTimeLost = 0.0
                self._pauseWaitStartTime = 0
                self._pauseWaitTimeLost = 0.0

                self._heating = True

                self._preparing_print = True
                self._prepare_print_thread = threading.Thread(target=self._preparePrintThread, name="comm._preparePrint")
                self._prepare_print_thread.daemon = True
                self._prepare_print_thread.start()
            else:
                self._errorValue = "Error while preparing the printing operation."
                self._logger.exception(self._errorValue)
                self._changeState(self.STATE_ERROR)
                eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
                return

        except:
            self._errorValue = get_exception_string()
            self._logger.exception("Error while trying to start printing: " + self.getErrorString())
            self._changeState(self.STATE_ERROR)
            eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
示例#5
0
	def do_auto_connect(self, port, *args, **kwargs):
		try:
			self._logger.info("do_auto_connect")
			(autoport, baudrate) = self._settings.global_get(["serial", "port"]), self._settings.global_get_int(["serial", "baudrate"])
			if autoport == "AUTO" or os.path.realpath(autoport) == os.path.realpath(port):
				self._logger.info("realpath match")
				printer_profile = self._printer_profile_manager.get_default()
				profile = printer_profile["id"] if "id" in printer_profile else "_default"
				self._logger.info("Attempting to connect to %s at %d with profile %s" % (autoport, baudrate, repr(profile)))
				self._printer.connect(port=autoport, baudrate=baudrate, profile=profile)
			else:
				self._logger.info("realpath no match")
				self._logger.info("Skipping auto connect on %s because it isn't %s" % (os.path.realpath(port), os.path.realpath(autoport)))
		except:
			self._logger.error("Exception in do_auto_connect %s", get_exception_string())
示例#6
0
    def startPrint(self, pos=None):
        """
        Starts the printing operation
        :param pos: unused parameter, just to keep the interface compatible with octoprint
        """
        if not self.isOperational() or self.isPrinting():
            return

        if self._currentFile is None:
            raise ValueError("No file selected for printing")

        try:
            self._changeState(self.STATE_PREPARING_PRINT)

            if self.isSdFileSelected():
                print_resp = self._beeCommands.startSDPrint(self._currentFile.getFilename())

                if print_resp:
                    self._sd_status_timer = RepeatedTimer(self._timeout_intervals.get("sdStatus", 1.0), self._poll_sd_status, run_first=True)
                    self._sd_status_timer.start()
            else:
                print_resp = self._beeCommands.printFile(self._currentFile.getFilename())

            if print_resp is True:
                self._heatupWaitStartTime = time.time()
                self._heatupWaitTimeLost = 0.0
                self._pauseWaitStartTime = 0
                self._pauseWaitTimeLost = 0.0

                self._heating = True

                self._prepare_print_thread = threading.Thread(target=self._preparePrintThread, name="comm._preparePrint")
                self._prepare_print_thread.daemon = True
                self._prepare_print_thread.start()
            else:
                self._errorValue = "Error while preparing the printing operation."
                self._logger.exception(self._errorValue)
                self._changeState(self.STATE_ERROR)
                eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
                return

        except:
            self._errorValue = get_exception_string()
            self._logger.exception("Error while trying to start printing: " + self.getErrorString())
            self._changeState(self.STATE_ERROR)
            eventManager().fire(Events.ERROR, {"error": self.getErrorString()})