eAddresses [LJM User's Guide]
Write/Read multiple d, 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.
Syntax
LJM_ERROR_RETURN LJM_eAddresses(
int Handle,
int NumFrames,
const int * aAddresses,
const int * aTypes,
const int * aWrites,
const int * aNumValues,
double * aValues,
int * ErrorAddress)
Parameters
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 | Integer Value |
---|---|
LJM_UINT16 | 0 |
LJM_UINT32 | 1 |
LJM_INT32 | 2 |
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. An entry in the array should be set to 1
for frames without consecutive regsiter accesses. 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.
Returns
LJM errorcodes or 0
for no error.
Remarks
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
Create a list of values that need to be accessed.
Decide how each value will be accessed: read or write.
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.Define
NumFrames
by counting all the values to access (step 1), then subtract consecutive values already accounted for inNumValues
(step 3).Insert data to be written to the device at the appropriate index of
aValues
.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
).
Addresses that need to be accessed:
[0, 2, 4, 1000, 2004]
Reading the first 3 values, writing to the 4th value, and reading from the 5th [R, R, R, W, R]
Seeing that the first 3 values are consecutive and are all being read, the situation can be simplified. The array size of
aNames
,aTypes
, andaWrites
is reduced.aAddresses = [0, 1000, 2004]
aTypes = [LJM_FLOAT32, LJM_FLOAT32, LJM_UINT16]
-LJM_FLOAT32
is3
;LJM_UINT16
is0
.aWrites = [LJM_READ, LJM_WRITE, LJM_READ]
-LJM_READ
is0
;LJM_WRITE
is1
.aNumValues = [3, 1, 1]
- The number of values is increased for the first frame only.The number of frames is
3
Set the analog output voltage to 4.6V by setting the fourth value.
aValues = [0, 0, 0, 4.6, 0]
Read the first three values of
aValues
to get AIN0 through AIN2; read the fifth value to get FIO4
Example
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]);