Class WriteRequestJsonUtilities


  • @NonNullByDefault
    public final class WriteRequestJsonUtilities
    extends Object
    Utilities for converting JSON to ModbusWriteRequestBlueprint
    Author:
    Sami Salonen - Initial contribution
    • Field Detail

      • JSON_FUNCTION_CODE

        public static final String JSON_FUNCTION_CODE
        Constant for the function code key in the JSON
        See Also:
        Constant Field Values
      • DEFAULT_MAX_TRIES

        public static final int DEFAULT_MAX_TRIES
        Default maxTries when it has not been specified
        See Also:
        Constant Field Values
    • Method Detail

      • fromJson

        public static Collection<ModbusWriteRequestBlueprint> fromJson​(int unitId,
                                                                       String jsonString)
        Parse JSON string to collection of ModbusWriteRequestBlueprint JSON string should represent a JSON array, with JSON objects. Each JSON object represents a write request. The JSON object must have the following keys - functionCode: numeric function code - address: reference or start address of the write - value: array of data to be written. Use zero and one when writing coils. With registers, each number corresponds to register's 16 bit data. - maxTries: number of tries with the write in case of errors
        Parameters:
        unitId - unit id for the constructed ModbusWriteRequestBlueprint
        jsonString - json to be parsed in string format
        Returns:
        collection of ModbusWriteRequestBlueprint representing the json
        Throws:
        IllegalArgumentException - in case of unexpected function codes, or too large payload exceeding modbus protocol specification
        IllegalStateException - in case of parsing errors and unexpected json structure
        See Also:
        WriteRequestJsonUtilities.JSON_FUNCTION_CODE, WriteRequestJsonUtilities.JSON_ADDRESS, WriteRequestJsonUtilities.JSON_VALUE, WriteRequestJsonUtilities.JSON_MAX_TRIES