LJM ByteArray Functions

LJM ByteArray Functions - LabJack

If you need to send or receive bytes to or from an LJM-supported device, consider using the LJM ByteArray functions.

These functions automatically split writes or reads into multiple packets, if necessary. Because of this, you can write or read a large number of bytes without worrying about what the maximum packet size of the connection is. This is especially useful for buffer registers. For example:

Name versions:

Address versions:

Example

[C/C++] Use LJM_eWriteNameByteArray to write a Lua script to device

int LJMError;
int ErrorAddress;
const char * luaScript =
    "LJ.IntervalConfig(0, 1000)\n"
    "while true do\n"
    "  if LJ.CheckInterval(0) then\n"
    "    print(LJ.Tick())\n"
    "  end\n"
    "end\n"
    "\0";
const unsigned scriptLength = strlen(luaScript) + 1;

// handle comes from LJM_Open()
LJMError = LJM_eWriteAddressByteArray(
    handle,
    LUA_SOURCE_WRITE_ADDRESS,
    scriptLength,
    luaScript,
    &ErrorAddress
);
if (LJMError != LJME_NOERROR) {
    // Deal with error
}

See the LJM C/C++ examples download for a full example.

Related Tags: