def aa_i2c_write_ext (aardvark, slave_addr, flags, data_out):
    """usage: (int return, u16 num_written) = aa_i2c_write_ext(Aardvark aardvark, u16 slave_addr, AardvarkI2cFlags flags, u08[] data_out)

    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."""

    if not AA_LIBRARY_LOADED: return AA_INCOMPATIBLE_LIBRARY
    # data_out pre-processing
    (data_out, num_bytes) = isinstance(data_out, ArrayType) and (data_out, len(data_out)) or (data_out[0], min(len(data_out[0]), int(data_out[1])))
    if data_out.typecode != 'B':
        raise TypeError("type for 'data_out' must be array('B')")
    # Call API function
    return api.py_aa_i2c_write_ext(aardvark, slave_addr, flags, num_bytes, data_out)
Beispiel #2
0
def aa_i2c_write_ext (aardvark, slave_addr, flags, data_out):
    """usage: (int return, u16 num_written) = aa_i2c_write_ext(Aardvark aardvark, u16 slave_addr, AardvarkI2cFlags flags, u08[] data_out)

    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."""

    if not AA_LIBRARY_LOADED: return AA_INCOMPATIBLE_LIBRARY
    # data_out pre-processing
    (data_out, num_bytes) = isinstance(data_out, ArrayType) and (data_out, len(data_out)) or (data_out[0], min(len(data_out[0]), int(data_out[1])))
    if data_out.typecode != 'B':
        raise TypeError("type for 'data_out' must be array('B')")
    # Call API function
    return api.py_aa_i2c_write_ext(aardvark, slave_addr, flags, num_bytes, data_out)
Beispiel #3
0
 def write(self, wata, config=I2CConfig.AA_I2C_NO_FLAGS):
     '''write ata to slave address
     ata can be byte or array of byte
     '''
     if (type(wata) == int):
         ata_out = array('B', [wata])
         length = 1
     elif (type(wata) == list):
         ata_out = array('B', wata)
         length = len(wata)
     else:
         raise TypeError("i2c ata to be written is not valid")
     (ret, num_written) = api.py_aa_i2c_write_ext(self.handle,
                                                  self.slave_addr, config,
                                                  length, ata_out)
     if (ret != 0):
         api.py_aa_i2c_free_bus(self.handle)
         raise_i2c_ex(ret)
     if (num_written != length):
         raise_aa_ex(-103)
Beispiel #4
0
 def write(self, wata, config=I2CConfig.AA_I2C_NO_FLAGS):
     '''write ata to slave address
     ata can be byte or array of byte
     '''
     if(type(wata) == int):
         ata_out = array('B', [wata])
         length = 1
     elif(type(wata) == list):
         ata_out = array('B', wata)
         length = len(wata)
     else:
         raise TypeError("i2c ata to be written is not valid")
     (ret, num_written) = api.py_aa_i2c_write_ext(self.handle,
                                                  self.slave_addr,
                                                  config,
                                                  length,
                                                  ata_out)
     if(ret != 0):
         api.py_aa_i2c_free_bus(self.handle)
         raise_i2c_ex(ret)
     if(num_written != length):
         raise_aa_ex(-103)