« Close

Datasheets and User Guides

App Notes

Software & Driver


2.9.4 - LoadConstantsFromFile

Loads a specified file as the Modbus map and Error constants.


LJM_ERROR_RETURN LJM_LoadConstantsFromFile(
                 const char * FileName)


FileName [in]
The absolute or relative file path to load as the constants. Must null-terminate. "default" maps to the default configuration file ljm_startup_config.json in the constants file location (see Constants file parameters).


LJM errorcodes or 0 for no error.

LJME_CONSTANTS_FILE_NOT_FOUND (1292): FileName did not point to a readable file location.

LJME_INVALID_CONSTANTS_FILE (1293): The file located at FileName was not a valid constants file. LJM_ErrorToString outputs a specific error message.


LJM_LoadConstantsFromFile is an alias for executing LJM_WriteLibraryConfigStringS with LJM_CONSTANTS_FILE as the Parameter of LJM_WriteLibraryConfigStringS and FileName as the String parameter of LJM_WriteLibraryConfigStringS:

LJM_WriteLibraryConfigStringS(LJM_CONSTANTS_FILE, FileName)

To load the Modbus constants and error constants separately, use LJM_WriteLibraryConfigStringS with LJM_MODBUS_MAP_CONSTANTS_FILE or LJM_ERROR_CONSTANTS_FILE as the Parameter.


[C/C++] Load the constants file "custom_modbus_map.json"

char ErrorString[LJM_MAX_NAME_SIZE];
int LJMError;
LJMError = LJM_LoadConstantsFromFile("custom_modbus_map.json");
if (LJMError != 0) {
    LJM_ErrorToString(LJMError, ErrorString);
    printf("LJM_LoadConstantsFromFile error: %s\n", ErrorString);