eReadNameByteArray [LJM User's Guide]
Read a device register that returnsconsecutive byte values, the register specified by a name.
Syntax
LJM_ERROR_RETURN LJM_eReadNameByteArray(
int Handle,
const char * Name,
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.
Name [in]
The name that specifies the Modbus register(s) to read. Names 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
LJM_eWriteNameByteArray is the reverse of LJM_eReadNameByteArray
.
The Address version of this function is LJM_eReadAddressByteArray.
This function will append a 0x00
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.
Example
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_eReadNameByteArray(
handle,
"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
}