def clean(self):
        try:
            if self.mainboard:
                self.mainboard.send_cmd("@HOME_BUTTON_TRIGGER\n", raw=1)
                self.mainboard.close()
                self.mainboard = None
        except Exception:
            logger.exception("Mainboard error while quit")

        try:
            if self.toolhead:
                if self.toolhead.ready:
                    # > Check should toolhead power deplayoff
                    if self.toolhead.module_name == "EXTRUDER":
                        for t in self.toolhead.status.get("rt", ()):
                            if t > 60:
                                logger.debug("Set toolhead delay off")
                                metadata.delay_toolhead_poweroff = b"\x01"
                                break
                    # ^
                    self.toolhead.shutdown()
                self.toolhead = None
        except Exception:
            logger.exception("Toolhead error while quit")

        try:
            tools.toolhead_standby()
        except Exception:
            logger.exception("HAL control error while quit")

        metadata.update_device_status(0, 0, "N/A", "")
Beispiel #2
0
    def clean(self):
        try:
            if self.mainboard:
                if self.mainboard.ready:
                    self.mainboard.send_cmd("X1E0")
                self.mainboard.close()
                self.mainboard = None
        except Exception:
            logger.exception("Mainboard error while quit")

        if self.camera:
            self.camera.close()
            self.camera = None

        metadata.update_device_status(0, 0, "N/A", "")
Beispiel #3
0
    def on_process_dead(self, watcher, revent):
        logger.info("Player %i quit: %i", self.proc.pid, watcher.rstatus)

        # This code is use for debug only
        try:
            os.kill(self.proc.pid, 0)
            logger.error("Player %i still alive!", self.proc.pid)
            os.kill(self.proc.pid, SIGKILL)
        except OSError:
            pass

        metadata.update_device_status(0, 0, "N/A", err_label="")
        watcher.stop()
        if watcher.data:
            watcher.data(self)
            watcher = None
Beispiel #4
0
    def __init__(self, loop, taskfile, terminated_callback=None):
        storage = Storage("run")

        oldpid = load_pid(storage.get_path("fluxplayerd.pid"))
        if oldpid is not None:
            try:
                os.kill(oldpid, SIGKILL)
                logger.error("Kill old player process: %i", oldpid)
            except Exception:
                logger.exception("Error while kill old process: %i", oldpid)

        s = create_mainboard_socket()
        try:
            s.send("\n@DISABLE_LINECHECK\nX5S115\n")

            if os.path.exists(PLAY_ENDPOINT):
                os.unlink(PLAY_ENDPOINT)
            ff = FCodeFile(taskfile)

            self.playinfo = ff.metadata, ff.image_buf

            cmd = [
                "fluxplayer", "-c", PLAY_ENDPOINT, "--task", taskfile, "--log",
                storage.get_path("fluxplayerd.log"), "--pid",
                storage.get_path("fluxplayerd.pid")
            ]
            if logger.getEffectiveLevel() <= 10:
                cmd += ["--debug"]

            f = open(storage.get_path("fluxplayerd.err.log"), "a")
            proc = Popen(cmd, stdin=PIPE, stderr=f.fileno())
            child_watcher = loop.child(proc.pid, False, self.on_process_dead,
                                       terminated_callback)
            child_watcher.start()
            metadata.update_device_status(1, 0, "N/A", err_label="")

            self.child_watcher = child_watcher
            self.proc = proc

        except FCodeError as e:
            s.send("X5S0\n")
            raise RuntimeError(FILE_BROKEN, *e.args)
        except Exception as e:
            s.send("X5S0\n")
            raise RuntimeError(UNKNOWN_ERROR)
        finally:
            s.close()
    def on_timer(self, watcher, revent):
        metadata.update_device_status(self.st_id, 0, "N/A",
                                      self.handler.address)

        if self.toolhead_updating:
            return

        try:
            self.mainboard.patrol()
            self.toolhead.patrol()

            if self._on_macro_running:
                self._on_macro_running()

        except (HeadOfflineError, HeadResetError) as e:
            logger.info("%s", e)
            tools.toolhead_standby()
            if self._macro:
                self._on_macro_error(e)
            self.toolhead.bootstrap(self.on_toolhead_ready)

        except RuntimeError as e:
            logger.info("%s", e)
            if self._macro:
                self._on_macro_error(e)

        except SystemError:
            if self.busying:
                self.handler.send_text("error %s" % SUBSYSTEM_ERROR)
                self.stack.exit_task(self)
            else:
                logger.exception("Mainboard dead during maintain")
                self.handler.send_text("error %s" % SUBSYSTEM_ERROR)
                self.handler.close()

        except IOError:
            logger.warn("Socket IO Error")
            self.handler.close()

        except Exception:
            logger.exception("Unhandle error")
            self.handler.close()
Beispiel #6
0
 def on_timer(self, watcher, revent):
     metadata.update_device_status(self.st_id, 0, "N/A",
                                   self.handler.address)
Beispiel #7
0
 def clean(self):
     metadata.update_device_status(0, 0, "N/A", "")
     tools.toolhead_standby()
Beispiel #8
0
 def __init__(self, stack, handler):
     super(RawTask, self).__init__(stack, handler)
     handler.binary_mode = True
     metadata.update_device_status(self.st_id, 0, "N/A", handler.address)