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.
Modbus Function Codes
Read Functions
Write Functions
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
{
"payload": {
"function": "readHoldingRegisters",
"address": 40001,
"quantity": 10
}
} {
"payload": {
"function": "writeSingleRegister",
"address": 40001,
"value": 1250
}
} Outputs
{
"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
} {
"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).