Skip to main content
Skip table of contents

LoadConstantsFromString [LJM User's Guide]

Loads a string as the Modbus map and/or Error constants.

Syntax

LJM_ERROR_RETURN LJM_LoadConstantsFromString( const char * JsonString)

Parameters

JsonString [in]

A string in JSON format containing the constants to load. Must null-terminate. If JsonString contains a JSON array named "registers", that array is loaded as the new Modbus map constants and the previous Modbus map constants are unloaded. If JsonString contains a JSON array named "errors", that array is loaded as the new Error constants and the previous Error constants are unloaded.

Returns

LJM errorcodes or 0 for no error.

LJME_INVALID_CONSTANTS_FILE (1293): The constants in JsonString was not a valid constants file. LJM_ErrorToString outputs a specific error message.

Remarks

To load constants from a file, see LJM_LoadConstantsFromFile.

Example

Load a small constants string

C
char ErrorString[LJM_MAX_NAME_SIZE];
int LJMError = LJM_LoadConstantsFromString(
    "{"
    "  \"registers\":"
    "  ["
    "    {\"address\":600, \"name\":\"STRING_AIN#(0:254)\", \"type\":\"FLOAT32\","
    "      \"devices\":[{\"device\":\"T7\", \"fwmin\":1.0001}],"
    "      \"readwrite\":\"R\", \"tags\":[\"AIN\"], \"altnames\":[\"\"]},"
    "    {\"address\":4321, \"name\":\"STRING_SERIAL_NUMBER\", \"type\":\"UINT32\","
    "      \"devices\":[{\"device\":\"T7\", \"fwmin\":1.0001}],"
    "      \"readwrite\":\"R\", \"tags\":[\"CONFIG\"], \"altnames\":[\"\"]}"
    "  ],"
    "  \"errors\":"
    "  ["
    "    {\"error\":0, \"string\":\"SUCCESS\"},"
    "    {\"error\":3900, \"string\":\"UNKNOWN_APPLICATION_ERROR\"}"
    "  ]"
    "}"
);
if (LJMError != 0) {
    LJM_ErrorToString(LJMError, ErrorString);
    printf("LJM_LoadConstantsFromString error: %s\n", ErrorString);
}
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.