예제 #1
0
def aa_i2c_read_ext (aardvark, slave_addr, flags, data_in):
    """usage: (int return, u08[] data_in, u16 num_read) = aa_i2c_read_ext(Aardvark aardvark, u16 slave_addr, AardvarkI2cFlags flags, u08[] data_in)

    All arrays can be passed into the API as an ArrayType object or as
    a tuple (array, length), where array is an ArrayType object and
    length is an integer.  The user-specified length would then serve
    as the length argument to the API funtion (please refer to the
    product datasheet).  If only the array is provided, the array's
    intrinsic length is used as the argument to the underlying API
    function.

    Additionally, for arrays that are filled by the API function, an
    integer can be passed in place of the array argument and the API
    will automatically create an array of that length.  All output
    arrays, whether passed in or generated, are passed back in the
    returned tuple."""

    if not AA_LIBRARY_LOADED: return AA_INCOMPATIBLE_LIBRARY
    # data_in pre-processing
    __data_in = isinstance(data_in, int)
    if __data_in:
        (data_in, num_bytes) = (array_u08(data_in), data_in)
    else:
        (data_in, num_bytes) = isinstance(data_in, ArrayType) and (data_in, len(data_in)) or (data_in[0], min(len(data_in[0]), int(data_in[1])))
        if data_in.typecode != 'B':
            raise TypeError("type for 'data_in' must be array('B')")
    # Call API function
    (_ret_, num_read) = api.py_aa_i2c_read_ext(aardvark, slave_addr, flags, num_bytes, data_in)
    # data_in post-processing
    if __data_in: del data_in[max(0, min(num_read, len(data_in))):]
    return (_ret_, data_in, num_read)
예제 #2
0
def aa_i2c_read_ext (aardvark, slave_addr, flags, data_in):
    """usage: (int return, u08[] data_in, u16 num_read) = aa_i2c_read_ext(Aardvark aardvark, u16 slave_addr, AardvarkI2cFlags flags, u08[] data_in)

    All arrays can be passed into the API as an ArrayType object or as
    a tuple (array, length), where array is an ArrayType object and
    length is an integer.  The user-specified length would then serve
    as the length argument to the API funtion (please refer to the
    product datasheet).  If only the array is provided, the array's
    intrinsic length is used as the argument to the underlying API
    function.

    Additionally, for arrays that are filled by the API function, an
    integer can be passed in place of the array argument and the API
    will automatically create an array of that length.  All output
    arrays, whether passed in or generated, are passed back in the
    returned tuple."""

    if not AA_LIBRARY_LOADED: return AA_INCOMPATIBLE_LIBRARY
    # data_in pre-processing
    __data_in = isinstance(data_in, int)
    if __data_in:
        (data_in, num_bytes) = (array_u08(data_in), data_in)
    else:
        (data_in, num_bytes) = isinstance(data_in, ArrayType) and (data_in, len(data_in)) or (data_in[0], min(len(data_in[0]), int(data_in[1])))
        if data_in.typecode != 'B':
            raise TypeError("type for 'data_in' must be array('B')")
    # Call API function
    (_ret_, num_read) = api.py_aa_i2c_read_ext(aardvark, slave_addr, flags, num_bytes, data_in)
    # data_in post-processing
    if __data_in: del data_in[max(0, min(num_read, len(data_in))):]
    return (_ret_, data_in, num_read)
예제 #3
0
 def read(self, length, config=I2CConfig.AA_I2C_NO_FLAGS):
     '''read 1 byte from slave address
     '''
     # read 1 byte each time for easy
     #         length = 2
     ata_in = array_u08(length)
     (ret, num_read) = api.py_aa_i2c_read_ext(self.handle, self.slave_addr,
                                              config, length, ata_in)
     if (ret != 0):
         api.py_aa_i2c_free_bus(self.handle)
         raise_i2c_ex(ret)
     if (num_read != length):
         raise_aa_ex(-102)
     val = ata_in
     return val
예제 #4
0
    def read(self, length, config=I2CConfig.AA_I2C_NO_FLAGS):
        '''read 1 byte from slave address
        '''
        # read 1 byte each time for easy
#         length = 2
        ata_in = array_u08(length)
        (ret, num_read) = api.py_aa_i2c_read_ext(self.handle,
                                                 self.slave_addr,
                                                 config,
                                                 length,
                                                 ata_in)
        if(ret != 0):
            api.py_aa_i2c_free_bus(self.handle)
            raise_i2c_ex(ret)
        if(num_read != length):
            raise_aa_ex(-102)
        val = ata_in
        return val