WritesNode-RED Modbus Example
Write a Single Register (FC06)
Writing a single holding register (FC06) is how you send setpoints, configuration values, or commands to a Modbus device. This example writes a speed setpoint to register 40 on a trigger, then confirms by reading it back.
What you need
- Node-RED v3+
- node-red-contrib-modbus installed
- Modbus TCP device that accepts writes to holding registers
Flow Overview
┌────────────────────┐ ┌───────────────────┐ ┌──────────────────────────┐
│ Inject │──▶│ Function │──▶│ Modbus Flex Write │──▶ Debug
│ payload: 1500 (num)│ │ build write msg │ │ FC06 · addr:40 · val:1500│
└────────────────────┘ └───────────────────┘ └──────────────────────────┘
│
Slave echoes
the request back
Node-RED Flow JSON
To import: open Node-RED → Hamburger menu → Import → paste this JSON → Deploy.
Expected Output
// modbus-flex-write response (echo of FC06 request):
msg.payload = {
success: true,
data: { address: 40, value: 1500 }
}Common Gotchas
- FC06 can only write one register — use modbus-flex-write with fc:16 for multiple registers.
- The value must be a 16-bit integer (0–65535 for UINT16; 0–32767 for positive INT16).
- Writing a FLOAT32 requires FC16 across 2 registers — FC06 cannot write floats.
- The slave echoes the request as confirmation; a different response means an exception occurred.
- Always validate that the target register is writable — writing to a read-only register returns exception 02.
Same in ModPackQT — in 30 seconds
ModPackQT lets you write to any holding register directly from the table — click the value, type a new one, press Enter. FC06 vs FC16 is selected automatically.
Was this example helpful?
More Writes examples