Edge 1.0.0

Modbus: Read

The Modbus: Read Node allows you to read multiple registers from your Modbus. This node is only available in edge workflows.

Modbus Read Node

Node Properties

There are three main parts of the configuration for this node …

Modbus Read Node Configuration

Address Configuration

Address Configuration contains four fields:

  • Host (Required): A string template for the IP address at which the register(s) resides.
  • Port (Required): A string template or integer for the HTTP port.
  • Unit ID (Required): A string template or integer for the Unit ID at the specified host and port. Defaults to 0.
  • Convert to signed or unsigned integers: The conversion of integer results to either signed or unsigned integers. Defaults to convert to signed integers.
  • Timeout Template: A string template or integer for the numbers of seconds to wait before a timeout will occur while waiting for read results. Defaults to 30 seconds.
  • Endianness: The endianness, or sequential order of bytes. Defaults to “Big”.

Modbus Read Node Instructions

Read Instructions

Read Instructions can be specified in two ways, either is required.

  • Array of Template Strings: For each read instruction, fill out the following input configuration fields, all of which can utilize templates. You must define at least one instruction.

    • Register Type (Required):

      • Input Registers: Read Input Registers (FC=04)
      • Holding Registers: Read Holding Registers (FC=03)
      • Coils: Read Coil Status (FC=01)
      • Discrete Input: Read Input Status (FC=02)
    • Address (Required): A string template or integer for the address at which to read. This should resolve to an integer between 0 and 65534 inclusive.
    • Length: The length for this read instruction. This field is optional, but if set, it should resolve to an integer greater than 0. Otherwise, the length defaults to 1.
    • Result Key (Required): The key at which to store the result of this read operation. This key will exist on the Destination Path defined below the instructions. This can resolve to any string except errors, since that key is reserved for any errors that occur during reads. The value at this key is read as an signed integer.
  • Payload Path: (edge version 1.9.0 and above) Give a payload path that will resolve to an array of read instructions to be run on this node. The following are the object properties that each object in the array should contain for successful attempts:

    • type (Required): one of the following types: input-registers, holding-registers, discrete-input or coil.
    • address (Required): An integer for the address at which to read. This integer must be between 0 and 65534 inclusive.
    • length: An integer for the number of addresses to read, starting at the given address. This integer must be greater than 0. Otherwise, the length defaults to 1.
    • key (Required): The key (Result Key) at which to store the result of this read operation. This key will exist on the Destination Path defined below the instructions. This can resolve to any string except errors, since that key is reserved for any errors that occur during reads. The value at this key is read as an signed integer.

The following is an example of an array that you could pass in:

[
  {
    "type": "holding-register",
    "address": 8,
    "length": 3,
    "key": "holdRegResults"
  }
]

Destination Path

Modbus Read Node Result

The results of each read instruction will be placed in an object at the Destination Path (a payload path) at each instruction’s Result Key. Each result is returned as an array. It is important that each key is named uniquely so the node does not overwrite another read result.

If the key is not present, it means the read failed, and there will be a list of errors at the Destination Path under the key errors. For this reason, this node restricts Result Keys to not resolve to the path errors. If one read fails, it does not mean that all reads will fail; rather, the reads will continue until finished. The only time you will get a single error for multiple reads is if the connection could never be made to the Modbus itself.

Node Example

The following is an example of a successful read, where an instruction’s Result Key is threeCoils, and the Destination Path is destination.modbusOutput:

{
  "destination": {
    "modbusOutput": {
      "threeCoils": [1, 0, 1]
    }
  }
}

Processing Successful Results

The following is an example of using the function node to combine two Modbus read results and making them into one 32-bit float:

const modbus = payload.modbus
const buffer = new ArrayBuffer(4)
const view = new DataView(buffer)
view.setInt16(0, modbus.systemPressure[0], false)
view.setInt16(2, modbus.systemPressure[1], false)
payload.state = {
  systemPressure: view.getFloat32(0, false),
}

Node Errors

The following is an example of a failure to read, where a resultKey should have been threeCoils, and the destination path is destination.modbusOutput:

{
  "destination": {
    "modbusOutput": {
      "errors": [
        {
          "type": "MODBUS_READ_ERROR",
          "message": "Something useful to help you fix the issue."
        }
      ]
    }
  }
}