Modbus: Write Node

The Modbus: Write Node allows you to write to multiple registers on Modbus-enabled PLCs. This node supports Modbus RTU and Modbus TCP. It is only available in Edge Workflows.

Modbus Write Node

Node Properties

There are two main parts of the configuration for this node.

Modbus Write Node Configuration

Address Configuration

Address Configuration contains four fields:

  • Connection Type: This field can be TCP Connection, Serial RTU Connection or Serial ASCII Connection. Depending on which type you select, different connection options will be available. For serial connections, 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 or ASCII Serial Connection Configuration

RTU Serial is only available on Gateway Edge Agent v1.10.0 and higher. ASCII Serial is only available on Gateway Edge Agent v1.46.0 and higher.

  • Path Template: (Required) A string template or path that resolves to the serial port at which values will be written.
  • Baud Rate Template: (Required) The baud rate, speed of communication over a data channel, which by default is 9600. This field can either be a integer or a template but it must resolve to a valid rate. For agent versions prior to 1.19.2 the following are the accepted baud rates: 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, 115200, 128000, 256000. As of GEA v1.19.2 you may specify any positive integer for this field.

In GEA v1.10.0 the following options are defaulted:

  • Data Bits: 8
  • Stop Bits: 1
  • Parity: none.

However, in GEA v1.11.0 and higher, you may specify these options.

  • Parity Template: The Parity is a method used to detect errors, which by default is none. This field can either be a string or a template but it must resolve to one of the following valid options: none, even, mark, odd, space.
  • Data Bits Template: The Data Bits is the number of bits each character can be, which by default is 8. This field can either be a integer or a template but it must resolve to one of the following valid data bits: 5, 6, 7, 8.
  • Stop Bits Template: 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. This field can either be a integer or a template but it must resolve to a valid stop bit. The only valid stop bits are 1 and 2.

ASCII Serial Connection has one additional option.

  • Start of Frame Character Template: The ASCII character that is the starting bit of the frame. This field defaults to :.

Common Configuration

  • Unit ID: (Required) A string template or integer for the Unit ID at the specified host and port. Defaults to 1.
  • Timeout Template: A string template or integer for the numbers of milliseconds to wait before a timeout will occur while waiting for write results. Defaults to 30000 milliseconds.

Write Instructions

Write Instructions can be given in two ways, either is required.

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

    • Address: (Required) A string template or integer for the address at which to write. This should resolve to an integer between 0 and 65535 inclusive.
    • Register Type: (Required) - Holding Register: (default) Present single register (FC=06) - Coils: Present single coil (FC=05) - Holding Registers: Present multiple registers (FC=16)
    • Value: (Required) A string template or integer or path, depending on the register type, to specify the value to write to the address. If the register type is Holding Register then this should resolve to an integer between 0 and 65535 otherwise if the type is Coils the value should be a single bit. If the register type is Holding Registers then this value expects a path to an array on your payload of integer values to write to the registers.
  • Result Key: (Optional) A key on the destination path to note the result of this write instruction. If a key is not specified, it will default to addr-${Number(address)}. Data will only be available if the destination path is also set. The value at this key will always be a boolean, true for success, and false for failure. Note If you are reading from the same address on different types, it’s possible to overwrite one of your keys, which could result in unexpected behavior.
  • Payload Path: (edge version 1.9.0 and above) Give a payload path that will resolve to an array of write 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: holding-register, holding-registers, or coil.
    • address: (Required) An integer or array of integers for the address at which to write. This integer(s) must be between 0 and 65535.
    • value: (Required) An integer value to write to the specified address.
  • key: (Optional) The key on the destination path to note the result of this write instruction. This data will only be available if destination path is also set. The value at this key will always be a boolean, true for success, and false for failure. If the key is missing, it will default to addr-${Number(address)}.

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

[
  {
    "type": "coil",
    "address": 3,
    "value": 0,
    "key": "coil-3"
  },
  {
    "type": "holding-register",
    "address": 3,
    "value": 0,
    "key": "hReg-3"
  },
  {
    "type": "holding-register",
    "address": 1,
    "value": 3
  },
  {
    "type": "holding-registers",
    "address": 5,
    "value": [1, 2, 3, 4, 5]
  }
]

Destination Path

Modbus Write Node Result

The Destination Path (a payload path) is optional, but if you want to confirm that the write was successful, the path should be set. If set, the result of write instruction will be at a key in the format of addr-${Number(address)}, successful writes will have a value of true, and failures will have a value of false.

If any errors occurred, there will be an errors key in the object at your path defining each error that occurred. The only time you will get a single error for multiple writes is if the connection could never be made to the Modbus itself.

Node Examples

For example, say we want to write to two addresses (one at 23, and the other at 80), where address 80 has a key of foo, and we set our Destination Path to destination.output. If all write instructions were successful, the output will look like the following:

"destination": {
  "output": {
    "addr-23": true,
    "foo": true
  }
}

Node Errors

If an error occurred the output will look like the following:

"destination": {
  "output": {
    "errors": [
      { "type": "MODBUS_WRITE_ERROR", "message": "Some error occurred at 23" },
      { "type": "MODBUS_WRITE_ERROR", "message": "Some error occurred at 80" },
    ],
    "addr-23": false,
    "foo": false
  }
}

If an error occurred for one write instruction, that does not mean all writes were unsuccessful. If one is successful and the other is not the output might look like the following:

"destination": {
  "output": {
    "errors": [
      { "type": "MODBUS_WRITE_ERROR", "message": "Some error occurred at 23" },
    ],
    "addr-23": false,
    "addr-80": true
  }
}

Was this page helpful?


Still looking for help? You can also search the Losant Forums or submit your question there.