コード例 #1
0
ファイル: commands.py プロジェクト: deshi-basara/libreXC
    def request_cmd(byteId, value):
        """
        Requests the parsing of a command on the arduino side.

        The request is sent via serial-connection to arduino with a
        custom message protocol.
        """
        # setup protocol bytes
        start_byte = 0x11
        cmd_byte = byteId
        if value == -1:
            parameter_byte = 255  # 255 = no parameter
        else:
            parameter_byte = value
        check_byte = cmd_byte ^ parameter_byte
        end_byte = 0x22

        # setup message with bytes
        message = [
            start_byte, start_byte, start_byte,
            cmd_byte,
            parameter_byte,
            check_byte,
            end_byte, end_byte, end_byte
        ]

        # send package
        try:
            tty = serial.Serial(port=Config.get_tty_port(), baudrate=57600)
            tty.write(message)
            print("Request Command wrote to Serial: {0}".format(message))
        except Exception as e:
            print("Request Command serial Exception: {0}".format(e))
コード例 #2
0
ファイル: data.py プロジェクト: deshi-basara/libreXC
    def run(self):
        connection = serial.Serial(port=Config.get_tty_port(), baudrate=57600)

        while True:
            # listen for bridge-commands
            try:
                line = connection.readline()

                if line:
                    print(line)
                    self.add_data(line)
            except Exception as e:
                # print exception and let Thread sleep
                print("Data-Thread Error: {}".format(e))
                time.sleep(self.socket_timeout)