Ejemplo n.º 1
0
    def start(self):
        # type: () -> None
        """ Start the MasterComunicator, this starts the background read thread. """
        if self.__init_master:
            self._flush_serial_input()

        if not self.__read_thread:
            self.__read_thread = BaseThread(name='masterread', target=self.__read)
            self.__read_thread.daemon = True

        if not self.__running:
            self.__running = True
            self.__read_thread.start()
Ejemplo n.º 2
0
    def send_passthrough_data(self, data):
        """ Send raw data on the serial port.

        :param data: string of bytes with raw command for the master.
        :raises: :class`InMaintenanceModeException` if master is in maintenance mode.
        """
        if self.__maintenance_mode:
            raise InMaintenanceModeException()

        if not self.__passthrough_mode:
            self.__command_lock.acquire()
            self.__passthrough_done.clear()
            self.__passthrough_mode = True
            passthrough_thread = BaseThread(name='passthroughwait', target=self.__passthrough_wait)
            passthrough_thread.daemon = True
            passthrough_thread.start()

        self.__write_to_serial(data)
Ejemplo n.º 3
0
    def __init__(self, cmd, cid, callback, send_to_passthrough=False):
        """
        Create a background consumer using a cmd, cid and callback.

        :param cmd: the MasterCommand to consume.
        :param cid: the communication id.
        :param callback: function to call when an instance was found.
        :param send_to_passthrough: whether to send the command to the passthrough.
        """
        self.cmd = cmd
        self.cid = cid
        self.callback = callback
        self.last_cmd_data = None  # type: Optional[bytearray]  # Keep the data of the last command.
        self.send_to_passthrough = send_to_passthrough

        self._queue = Queue()
        self._running = True
        self._callback_thread = BaseThread(name='masterdeliver', target=self._consumer)
        self._callback_thread.setDaemon(True)
        self._callback_thread.start()