« Close

Datasheets and User Guides

App Notes

Software & Driver

 

2.3.8 - eReadAddressByteArray

Read consecutive byte values, specified by an address.

Syntax

LJM_ERROR_RETURN LJM_eReadAddressByteArray(
                      int Handle,
                      int Address,
                      int NumBytes,
                      char * aBytes,
                      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.
Address [in]
The address that specifies the Modbus register(s) to read.  Addresses can be found throughout the device datasheet or in the Modbus Map.
NumBytes [in]
The number of consecutive bytes.
aBytes [out]
An array of bytes transferred from the device. The array size should be equal to NumBytes.
ErrorAddress [out]
If error, the address responsible for causing an error.

Returns

LJM errorcodes or 0 for no error.

Remarks

The Name version of this function is LJM_eReadNameByteArray.

This function will append a 00 byte to aBytes for odd-numbered NumBytes.

If NumBytes is large enough, these functions will automatically split reads into multiple packets based on the current device's effective data packet size. Using both non-buffer and buffer registers in one function call is not supported.

Examples

[C] Read Lua output from LUA_DEBUG_DATA

int byteIter, err;
double numBytes;
char * aBytes;
int errorAddress;
numBytes = 0;

// handle comes from LJM_Open()
err = LJM_eReadName(handle, "LUA_DEBUG_NUM_BYTES", &numBytes);
if (err != LJME_NOERROR) {
    // Deal with error
}
aBytes = malloc(sizeof(char) * (int)numBytes);
errorAddress = -2; // Something impossible for a Modbus address
err = LJM_eReadAddressByteArray(
    handle,
    6024, // LUA_DEBUG_DATA
    numBytes,
    aBytes,
    &errorAddress
);
if (err == LJME_NOERROR) {
    printf("LUA_DEBUG_DATA: ");
    for (byteIter = 0; byteIter < numBytes; byteIter++) {
        printf("%c", aBytes[byteIter]);
    }
    printf("\n");
}
free(aBytes);
if (err != LJME_NOERROR) {
    // Deal with error
}