Skip to main content

modbus-tcp

Connect to Modbus TCP devices to read and write holding registers, input registers, coils, and discrete inputs over Ethernet.

Overview

The modbus-tcp node enables communication with Modbus TCP/IP devices over Ethernet. It supports all standard Modbus function codes (FC1-FC16) for reading and writing holding registers, input registers, coils, and discrete inputs. Operates as both client and server for maximum flexibility.

FC1-FC16
Functions
502
Default Port
247
Max Devices
TCP/IP
Transport

Modbus Function Codes

Read Functions

FC1 - Read Coils 0x01
FC2 - Read Discrete Inputs 0x02
FC3 - Read Holding Registers 0x03
FC4 - Read Input Registers 0x04

Write Functions

FC5 - Write Single Coil 0x05
FC6 - Write Single Register 0x06
FC15 - Write Multiple Coils 0x0F
FC16 - Write Multiple Registers 0x10

Properties

Property Type Required Default Description
host string Yes - Modbus server IP address or hostname
port number No 502 TCP port number
unitId number No 1 Slave/unit identifier (1-247)
function string Yes - Modbus function code (e.g., "readHoldingRegisters")
address number Yes - Starting register/coil address
quantity number No 1 Number of registers/coils to read
pollInterval number No 1000 Polling interval in milliseconds
timeout number No 5000 Connection timeout in milliseconds

Inputs

Read Holding Registers
{
  "payload": {
    "function": "readHoldingRegisters",
    "address": 40001,
    "quantity": 10
  }
}
Write Single Register
{
  "payload": {
    "function": "writeSingleRegister",
    "address": 40001,
    "value": 1250
  }
}

Outputs

Read Response
{
  "payload": {
    "unitId": 1,
    "function": "readHoldingRegisters",
    "address": 40001,
    "values": [1250, 3200, 980, 0, 512],
    "buffer": "<Buffer 04 e2 0c 80 03 d4 ...>"
  },
  "host": "192.168.1.100",
  "port": 502
}
Write Confirmation
{
  "payload": {
    "unitId": 1,
    "function": "writeSingleRegister",
    "address": 40001,
    "value": 1250,
    "success": true
  }
}

Use Cases

PLC Data Reading

Read process variables, status registers, and alarm states from PLCs on the factory floor in real time.

Energy Meter Polling

Poll power meters and energy analyzers to track consumption, demand, and power quality metrics.

VFD Control

Control variable frequency drives by writing speed setpoints and reading motor status parameters.

Multi-device Polling

Configure multiple unit IDs to poll several Modbus devices through a single TCP gateway connection.

Example: Read Temperature Registers

Poll temperature values from a Modbus TCP sensor module every 2 seconds.

[
  {
    "id": "modbus-reader",
    "type": "modbus-tcp",
    "host": "192.168.1.100",
    "port": 502,
    "unitId": 1,
    "function": "readInputRegisters",
    "address": 30001,
    "quantity": 4,
    "pollInterval": 2000
  },
  {
    "id": "scale-values",
    "type": "function",
    "func": "msg.payload.values = msg.payload.values.map(v => v / 10); return msg;"
  },
  {
    "id": "display",
    "type": "debug",
    "name": "Temperature Data"
  }
]

Tips & Best Practices

Polling Intervals: Keep poll intervals above 100ms. Rapid polling can overwhelm devices and cause timeout errors.

Error Handling: Implement retry logic with exponential backoff. Handle exception codes (0x01-0x06) to diagnose communication issues.

Connection Pooling: Reuse TCP connections where possible. Opening and closing connections for each request adds latency and overhead.

Register Addressing: Modbus uses 0-based addressing internally. Register 40001 maps to address 0 for holding registers (FC3).

Related Nodes