Ejemplo n.º 1
0
    def get_register(self):
        if register.iterated:
            data_len = chr((register.byte_size * self.loop_count) & 0xff)
        else:
            data_len = chr(register.byte_size & 0xff)

        tran_id = self._transaction.next()
        message = make_message_header(
            self.source, self.destination,
            1, tran_id
            ) + str(register.byte_location) + str(data_len)

        check = self._checksum(message)

        msg = message.replace("\x10", "\x10\x10")
        packet = "\x10\x02%s\x10\x03%s" % (msg, check)

        msg_back = None
        with self.ser as port:
            if not port.isOpen():
                port.open()
            msg_back = do_command(port, packet)

        if not msg_back:
            raise AttributeError("Cannot read attribute from controller")

        returned_data = disect_packet(msg_back)

        clean_data = returned_data.replace("\x10\x10", "\x10")

        # actually marshall
        return register.to_python(clean_data)
Ejemplo n.º 2
0
    def set_register(self, value):
        # XXX: Needs testing
        data = register.from_python(value)

        message = make_message_header(
            self.source, self.destination,
            8, self._transaction.next()
            ) + register.byte_location + data

        check = self._checksum(message)

        msg = message.replace("\x10", "\x10\x10")
        packet = "\x10\x02%s\x10\x03%s" % (msg, check)

        msg_back = None
        with self.ser as port:
            if not port.isOpen():
                port.open()
            msg_back = do_command(port, packet)

        if not msg_back:
            raise AttributeError("Cannot write attribute to controller.")