2.3.6 - eAddresses | LabJack
« Close

Datasheets and User Guides

App Notes

Software & Driver


2.3.6 - eAddresses

Write/Read multiple values, specified by address. This function is designed to condense communication into arrays. Moreover, consecutive values can be accessed by specifying a starting address, and a number of values.


                      int Handle, 
                      int NumFrames,
                      const int * aAddresses,
                      const int * aTypes, 
                      const int * aWrites, 
                      const int * aNumValues, 
                      double * aValues,
                      int * ErrorAddress)


Handle [in]
A device handle. The handle is a connection ID for an active device. Generate a handle with LJM_Open or LJM_OpenS.
NumFrames [in]
The total number of frames to access.  A frame consists of one or more values, based on NumValues. 
aAddresses [in]
An array of addresses that specify the Modbus register(s) to write/read. To access a consecutive group of values, populate an element of aAddresses array with the starting address, and then increase the NumValues parameter according to the group size. 
aTypes [in]
An array of size NumFrames, containing the data type of each value sent/received:
Type LJM Constant Name LJM Constant Value
unsigned 16-bit integer LJM_UINT16 0
unsigned 32-bit integer LJM_UINT32 1
signed 32-bit integer LJM_INT32 2
floating point 32-bit LJM_FLOAT32 3
aWrites [in]
An array containing the desired type of access, which is either read(0) or write(1). The array size should be the same as the aAddresses array.
aNumValues [in]
An array that contains the per-address number of consecutive values.  NumValues is 1 for non-consecutive.  The array size should be the same as the aAddresses array.
aValues [in/out]
An array of values to be transferred to/from the device. The array size should be the sum of all elements in the aNumValues array. Each value will be converted to/from those defined in aTypes.
ErrorAddress [out]
If error, the address responsible for causing an error.


LJM errorcodes or 0 for no error.


LJM_eAddresses is equivalent to LJM_eNames.

LJM_eAddresses is for programs that need to write and read multiple, arbitrary values in a single function call. For example, a PID loop may read inputs and set outputs in a single function call. In this way, the communication overhead is reduced. There are simpler single value functions and simpler multiple value functions for programs that do not need such a level of communication optimization.

To use LJM_eAddresses:

  1. Create a list of values that need to be accessed.
  2. Decide how each value will be accessed: read or write.
  3. Note values which are consecutive and have the same access (read or write). Only use the first name in a consecutive group and increase the NumValues parameter according to the group size.
  4. Define NumFrames by counting all the values to access (step 1), then subtract consecutive values already accounted for in NumValues (step 3).
  5. Insert data to be written to the device at the appropriate index of aValues.
  6. Read data from aValues array after function is executed.
As an example of the above use-case, consider reading AIN0-2 (addresses 0, 2, 4), setting DAC0 (address 1000) to 4.6V, and reading the state of DIO4 (address 2004).  
  1. Addresses that need to be accessed: [0, 2, 4, 1000, 2004]
  2. Reading the first 3 values, writing to the 4th value, and reading from the 5th [R, R, R, W, R]
  3. Seeing that the first 3 values are consecutive and are all being read, the situation can be simplified.  The array size of aNames, aTypes, and aWrites is reduced.
    1. aAddresses = [0, 1000, 2004]
    2. aTypes = [LJM_FLOAT32, LJM_FLOAT32, LJM_UINT16] - LJM_FLOAT32 is 3; LJM_UINT16 is 0.
    3. aWrites = [LJM_READ, LJM_WRITE, LJM_READ] - LJM_READ is 0; LJM_WRITE is 1.
    4. aNumValues = [3, 1, 1] - The number of values is increased for the first frame only. 
  4. The number of frames is 3
  5. Set the analog output voltage to 4.6V by setting the fourth value.  aValues = [0, 0, 0, 4.6, 0]
  6. Read the first three values of aValues to get AIN0 through AIN2; read the fifth value to get FIO4


[C/C++] Read analog inputs 0 through 7, set DAC0 to 4.6V, read FIO4

int LJMError;
int errorAddress;
int aAddresses[3] = {0, 1000, 2004};
int aTypes[3] = {LJM_FLOAT32, LJM_FLOAT32, LJM_UINT16};
int aWrites[3] = {LJM_READ, LJM_WRITE, LJM_READ};
int aNumValues[3] = {3, 1, 1};
double aValues[5];
aValues[3] = 4.6;

// handle comes from LJM_Open()
LJMError = LJM_eAddresses(handle, 3, aAddresses, aTypes, aWrites, aNumValues, aValues, &errorAddress);
if (LJMError != LJME_NOERROR) {
    // Deal with error
printf("AIN0: %f\n", aValues[0]);
printf("AIN1: %f\n", aValues[1]);
printf("AIN2: %f\n", aValues[2]);
printf("FIO4: %f\n", aValues[4]);