Edge 1.0.0

Modbus: Read Node

The Modbus: Read Node allows you to read multiple registers from Modbus-enabled PLCs. This node supports Modbus RTU and Modbus TCP. It 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 five fields:

  • Connection Type: This field will either be TCP Connection or Serial RTU Connection. Depending on which type you select, different connection options will be available. For serial connection, we only support RTU, and not ASCII. Here is more information on the difference between RTU and ASCII.

TCP Connection Configuration

  • Host Template (Required): A string template for the IP address at which the register(s) resides.
  • Port Template (Required): A string template or integer for the HTTP port.

Modbus RTU Serial Connection Configuration

RTU Serial is only available only on Edge Agent versions 1.10.0 and higher.

  • Path Template (Required): A string template or path that resolves to the serial port at which values will be read.
  • Baud Rate (Required): The baud rate, speed of communication over a data channel, which by default is 9600. The following are the accepted baud rates: 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 128000, 256000.

In the Edge Agent versions 1.10.0 the following options are defaulted: Data Bits: 8, Stop Bits: 1, Parity: None. However in versions 1.11.0 and higher you may specify these options.

  • Parity: The Parity is a method used to detect errors, which by default is None. The following are valid options: None, Even, Mark, Odd, Space.
  • Data Bits: The Data Bits is the number of bits each character can be, which by default is 8. The following are valid data bits: 5, 6, 7, 8.
  • Stop Bits: The Stop Bits is the bit sent at the end of ever character to signify the end of a character, by default this is 1. The only valid stop bits are 1 and 2.

Common Configuration

  • Unit ID Template (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 65535 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-register, discrete-input or coil.
    • address (Required): An integer for the address at which to read. This integer must be between 0 and 65535.
    • 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."
        }
      ]
    }
  }
}