ModPackQTModPackQT
Node-RED ExamplesResourcesSign up
HomeResourcesNode-RED ExamplesRead a String Register (Device Name / Firmware Version)
ReadsNode-RED Modbus Example

Read a String Register (Device Name / Firmware Version)

Some Modbus devices expose text — serial numbers, firmware strings, model names — in consecutive registers, two ASCII characters per register. This example reads 8 registers and assembles them into a human-readable string.

What you need

  • Node-RED v3+
  • node-red-contrib-modbus installed
  • Device that exposes string registers (check datasheet for character registers)

Flow Overview


registers 100–107:
  0x4D6F → "Mo"   0x6462 → "db"   0x7573 → "us"   0x2044 → " D"
  0x6576 → "ev"   0x6963 → "ic"   0x6520 → "e "   0x0000 → ""

Assembled: "Modbus Device"

Node-RED Flow JSON

Node-RED Flow JSON
[
  {"id":"inj6","type":"inject","name":"Read once","once":true,"wires":[["req6"]],"x":120,"y":600},
  {"id":"req6","type":"modbus-flex-getter","name":"Read 8 regs","dataType":"HoldingRegister","adr":100,"quantity":8,"server":"srv1","wires":[["fn6"],[]],"x":310,"y":600},
  {"id":"fn6","type":"function","name":"Decode ASCII string","func":"const regs = msg.payload.data;
const chars = [];
for (const reg of regs) {
  const hi = (reg >> 8) & 0xFF;
  const lo = reg & 0xFF;
  if (hi) chars.push(String.fromCharCode(hi));
  if (lo) chars.push(String.fromCharCode(lo));
}
msg.payload = chars.join('').replace(/\x00/g, '').trim();
return msg;","wires":[["dbg8"]],"x":530,"y":600},
  {"id":"dbg8","type":"debug","name":"Device string","active":true,"wires":[],"x":730,"y":600},
  {"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

msg.payload = "Modbus Device v1.4"
// A human-readable string extracted from 8 holding registers

Common Gotchas

  • Some devices store strings low-byte-first (lo = first char) — swap hi and lo if you get reversed text.
  • Null-terminated strings stop at the first 0x00 byte; pad-terminated strings fill unused space with spaces (0x20).
  • Register count = ceil(string_length / 2) — a 14-character string needs 7 registers.
  • Some devices use FC04 (input registers) for device information strings.
  • Always trim and filter null bytes — Buffer.toString('ascii') works too if you assemble a Buffer instead.

Same in ModPackQT — in 30 seconds

ModPackQT displays register values as hex, decimal, or ASCII — switch format in the row dropdown. String decoding requires no custom function node.

Was this example helpful?

More Reads examples

All Node-RED Modbus Examples (30)

ModPackQT · Node-RED Modbus Examples · Updated 2026