Beispiel #1
0
def send_scpi_command(command, Aardvark_in_use, dec_addr):
    """
    Function to send a SCPI command to the slave device
    
    @param[in]    command:         the command to send (string)
    @param[in]    Aardvark_in_use: The Aaardvark to use to read the data
                                   (aardvark_py.aardvark)
    @param[in]    dec_addr:        the decimal address to write to (int)
    """  
    
    # convert the data into a list of bytes and append the terminator
    write_data = list(command)
    write_data = [ord(item) for item in write_data]
    write_data.append(0x0a)
    
    # convert to an array to be compiant with the aardvark
    data = array('B', write_data)  
    
    
    # Write the data to the slave device
    aardvark_py.aa_i2c_write(Aardvark_in_use, dec_addr, 
                             aardvark_py.AA_I2C_NO_FLAGS, data)
    
    # print what was done
    if 'TEL?' in command:
        # there is data to follow
        print 'Read:\t\t' + command
    else:
        # there is not
        print 'Write:\t\t' + command
Beispiel #2
0
def send_raw_command(command, Aardvark_in_use):
    """
    Function to send a <RAW> command to a slave device.
    
    @param[in]    command:         The command to send (string).
    @param[in]    Aardvark_in_use: The Aaardvark to use to send the command
                                   (aardvark_py.aardvark)
    """
    
    # determine if it is a valid raw command
    if pySCPI_config.is_valid_raw(command):
        # it is so extract the data to write
        write_data = command[:-1].split(' ')
        
        # extract the address to write to
        raw_addr = int(write_data[1][:-1],16)
        
        # convert all of the data specified in the string to integers
        int_write_data = [int(item,16) for \
                          item in write_data[2:]]
        
        # add the terminator
        int_write_data.append(0x0a)
        
        # convert the data to an array to be compatible with the aardvark
        data = array('B', int_write_data)  
        
        # Write the data to the slave device
        aardvark_py.aa_i2c_write(Aardvark_in_use, raw_addr,
                                 aardvark_py.AA_I2C_NO_FLAGS, 
                                 data)
        # write output
        print 'Raw Write:\t\t[' + \
              ' '.join([str(item) for item in write_data[2:]]) + \
              '] to address ' + write_data[1][:-1]
    def read_register(self, sensor, register, length=1):
        sad = self._sensortable[sensor]
        # todo check write status first
        aa.aa_i2c_write(self._handle, sad, aa.AA_I2C_NO_STOP,
                        array('B', [register]))  # write address
        (count, data_in) = aa.aa_i2c_read(self._handle, sad,
                                          aa.AA_I2C_NO_FLAGS,
                                          length)  # read data
        if count != length:
            raise BusException(
                'No response from I2C slave at address 0x%x for sensor %s' %
                (sad, sensor))

        return data_in
def PMBus_Group_Write(ADM1266_Address, write_data):
    a = array('B')
    for i in write_data:
        a.append(i)

    for x in range(len(ADM1266_Address)):
        device_address = ADM1266_Address[x]
        if (x < len(ADM1266_Address)):
            num = aardvark_py.aa_i2c_write(Aardvark_Handle, device_address,
                                           aardvark_py.AA_I2C_NO_STOP, a)
        else:
            num = aardvark_py.aa_i2c_write(Aardvark_Handle, device_address,
                                           aardvark_py.AA_I2C_NO_FLAGS, a)

    if num != len(write_data):
        raise Exception(
            'Failed to write i2c device @{0:02X}.'.format(device_address))
def PMBus_Write(device_address, write_data, stop=True):
    a = array('B')
    for i in write_data:
        a.append(i)

    num = aardvark_py.aa_i2c_write(Aardvark_Handle, device_address,
                                   aardvark_py.AA_I2C_NO_FLAGS, a)

    if num != len(write_data):
        raise Exception(
            'Failed to write i2c device @{0:02X}.'.format(device_address))
Beispiel #6
0
 def write(self, addr, data):
   """Writes an array of bytes to the addressed I2C device.
   
   Keyword arguments:
   addr -- I2C Slave Address (0x00 - 0x7F)
   data -- Bytes to send
   """
   if type(data) is not array:
     data = array('B', data)
   result = api.aa_i2c_write(self._handle, addr, api.AA_I2C_NO_FLAGS, data)
   return _check_result(result)
Beispiel #7
0
 def write(self, addr, data):
     """Writes an array of bytes to the addressed I2C device.
 
 Keyword arguments:
 addr -- I2C Slave Address (0x00 - 0x7F)
 data -- Bytes to send
 """
     if type(data) is not array:
         data = array('B', data)
     result = api.aa_i2c_write(self._handle, addr, api.AA_I2C_NO_FLAGS,
                               data)
     return _check_result(result)
def write(handle, data_out):
    """This function sends a command to the SHA204 device."""
    log_write(data_out)
    res = aa_i2c_write(handle, I2C_ADDRESS, AA_I2C_NO_FLAGS, data_out)
    if (res < 0):
        print "error: %s" % (aa_status_string(res))
        return res

    if (res == 0):
        print "error: slave device %02X not found" % (I2C_ADDRESS)

    return res
    def hw_i2c_write_no_stop(self, data_out):
        myException = Exception()

        with self.activityLock :
            if self.handle == None :
                myException.message = "hw_i2c_write_no_stop failure: attempting to write to null handle\n" 
                raise myException

            # Call the appropriate I2C hardware interface to write data
            # (write with start condition but no stop condition)
            if self.HW_INTERFACE == config.AARDVARK:
                aardvark_py.aa_i2c_write(self.handle, self.DEVICE_I2C_ADDR, aardvark_py.AA_I2C_NO_STOP, data_out)
            elif self.HW_INTERFACE == config.FTDI:
                flags = ftdi.I2C_TRANSFER_OPTIONS_START_BIT
                ftdi.ftdi_i2c_write (self.handle, self.DEVICE_I2C_ADDR, flags, data_out)
            elif self.HW_INTERFACE == config.USB_TO_ANY:
                myException.message = 'USB_TO_ANY hardware interface hw_interface_init not implemented\n'  
                raise myException
            else:
                myException.message = 'Invalid hardware interface selected in config.py\n'   
                raise myException
Beispiel #10
0
	def read(self, address, offset, length):
                res = None
                while (not res):
                        #zero byte write to set the read pointer
                        aa_py.aa_i2c_write(self.aa,
                                           address,
                                           aa_py.AA_I2C_NO_FLAGS,
                                           array('B', [offset & 0xff])
                                   )
                        (count, res) = aa_py.aa_i2c_read(self.aa, address, aa_py.AA_I2C_NO_FLAGS, length)
                        if (count < 0):
                                print "error: %s" % aa_py.aa_status_string(count)
                                res = None
                        elif (count == 0):
                                print "error: no bytes read"
                                print "  are you sure you have the right slave address?"
                                res = -999999999
                        elif (count != length):
                                print "error: read %d bytes (expected %d)" % (count, length)
                                res = -999999999
                
		return res
Beispiel #11
0
 def send_SCPI(self, command, address):
     """
     Function to send a SCPI command to the slave device
     
     @param[in]    command:         the command to send (string)
     @param[in]    address:         the decimal address to write to (int)
     """  
     
     # convert the data into a list of bytes and append the terminator
     write_data = list(command)
     write_data = [ord(item) for item in write_data]
     write_data.append(0x0a)
     
     # convert to an array to be compiant with the aardvark
     data = array('B', write_data)  
     
     
     # Write the data to the slave device
     aardvark_py.aa_i2c_write(self.port, int(address, 16), 
                              aardvark_py.AA_I2C_NO_FLAGS, data)
     
     # pause
     aardvark_py.aa_sleep_ms(100)
    def write_register(self, sensor, register, data):
        if isinstance(data, int):
            length = 2
            data_out = array('B', [register, data])
        elif isinstance(data, list) or isinstance(data, tuple):
            data = list(data)
            length = 1 + len(data)
            data_out = array('B', [register] + data)
        elif data is None:
            # special case : one byte write
            length = 1
            data_out = array('B', [register])
        else:
            raise BusException('Datatype "%s" not supported.' % type(data))

        sad = self._sensortable[sensor]
        res = aa.aa_i2c_write(self._handle, sad, aa.AA_I2C_NO_FLAGS, data_out)

        if res != length:
            raise BusException(
                'Unable write to I2C slave at address 0x%x for sensor %s' %
                (sad, sensor))