ModPackQTModPackQT
Node-RED ExamplesResourcesSign up
HomeResourcesNode-RED ExamplesWrite a Single Register (FC06)
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

Node-RED Flow JSON
[
  {"id":"inj7","type":"inject","name":"Write setpoint","payload":"1500","payloadType":"num","wires":[["fn7"]],"x":120,"y":700},
  {"id":"fn7","type":"function","name":"Build write msg","func":"msg.payload = { value: msg.payload, address: 40, quantity: 1, unitid: 1, fc: 6 };
return msg;","wires":[["req7"]],"x":320,"y":700},
  {"id":"req7","type":"modbus-flex-write","name":"FC06 Write","server":"srv1","wires":[["dbg9"],[]],"x":530,"y":700},
  {"id":"dbg9","type":"debug","name":"Write response","active":true,"wires":[],"x":730,"y":700},
  {"id":"srv1","type":"modbus-client","name":"My Slave","clienttype":"tcp","tcpHost":"192.168.1.100","tcpPort":502,"unit_id":1}
]

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

All Node-RED Modbus Examples (30)

ModPackQT · Node-RED Modbus Examples · Updated 2026