예제 #1
0
    def getRead(self, address, data, remote_id=None):
        """Reads Pozyx register data either locally or remotely.

        Args:
            address: The register address
            data: A ByteStructure - derived object that is the container of the read data.

        Kwargs:
            remote_id: Remote ID for remote read.

        Returns:
            POZYX_SUCCESS, POZYX_FAILURE, POZYX_TIMEOUT

        Example:
            >>> who_am_i = SingleRegister()
            >>> self.getRead(PozyxRegisters.WHO_AM_I, who_am_i)
            >>> print(who_am_i)
            67
        """
        if not is_reg_readable(address):
            if not self.suppress_warnings:
                warn("Register 0x%0.02x isn't readable" % address,
                     stacklevel=3)
        if remote_id is None:
            return self.regRead(address, data)
        else:
            return self.remoteRegRead(remote_id, address, data)
예제 #2
0
파일: core.py 프로젝트: Tsuchimiya/pozyx
    def remoteRegRead(self, destination, address, data):
        """
        Performs regRead on a remote Pozyx device.

        Args:
            destination: Network ID of destination device. integer ID or NetworkID(ID).
            address: Register address to start the read operation from.
            data: Container for the read data. ByteStructure-derived object.

        Returns:
            POZYX_SUCCESS, POZYX_FAILURE, POZYX_TIMEOUT
        """
        if dataCheck(destination):
            destination = destination[0]
        if is_reg_readable(address) == 0:
            return POZYX_FAILURE
        if len(data) > MAX_BUF_SIZE:
            return POZYX_FAILURE
        if destination == 0:
            return POZYX_FAILURE

        send_data = Data([0, address, data.byte_size])
        status = self.regFunction(POZYX_TX_DATA, send_data, Data([]))
        if status == POZYX_FAILURE:
            return status

        self.regRead(POZYX_INT_STATUS, SingleRegister())
        params = Data([destination, 0x02], 'HB')
        status = self.regFunction(POZYX_TX_SEND, params, Data([]))
        if status == POZYX_FAILURE:
            return status

        status = self.checkForFlag(POZYX_INT_STATUS_FUNC, 1)
        if status == POZYX_SUCCESS:
            rx_info = Data([0, 0], 'HB')
            self.regRead(POZYX_RX_NETWORK_ID, rx_info)
            if rx_info[0] == destination and rx_info[1] == data.byte_size:
                status = self.readRXBufferData(data)
                return status
            else:
                return POZYX_FAILURE
        return status