ModPackQTModPackQT
Node-RED ExamplesResourcesSign up
HomeResourcesNode-RED ExamplesRead 32-bit Integers (INT32 / UINT32)
ReadsNode-RED Modbus Example

Read 32-bit Integers (INT32 / UINT32)

Energy counters, position feedback, and large totals often come back as 32-bit integers spread across two registers. This example reads two consecutive registers and interprets them as both UINT32 and INT32 in the two most common byte orders.

What you need

  • Node-RED v3+
  • node-red-contrib-modbus installed
  • Device with 32-bit integer registers (energy meter, counter, servo drive)

Flow Overview


Registers 20–21 on the wire:
  reg20 = 0x000F  (high word in AB-CD order)
  reg21 = 0x4240  (low word)

Combining 0x000F4240 → UINT32 = 1,000,000
                     → INT32  = 1,000,000 (positive, same)

If word-swapped (CD-AB): 0x4240000F → 1,111,638,031

Node-RED Flow JSON

Node-RED Flow JSON
[
  {"id":"inj5","type":"inject","name":"Poll 5s","repeat":"5","once":true,"wires":[["req5"]],"x":120,"y":500},
  {"id":"req5","type":"modbus-flex-getter","name":"Read 2 regs","dataType":"HoldingRegister","adr":20,"quantity":2,"server":"srv1","wires":[["fn5"],[]],"x":310,"y":500},
  {"id":"fn5","type":"function","name":"Decode INT32 / UINT32","func":"const [hi, lo] = msg.payload.data;
const buf = Buffer.alloc(4);
// AB-CD (big-endian): MSW in first register
buf.writeUInt16BE(hi, 0); buf.writeUInt16BE(lo, 2);
const uint32_ABCD = buf.readUInt32BE(0);
const int32_ABCD  = buf.readInt32BE(0);
// CD-AB (word-swap): MSW in second register
buf.writeUInt16BE(lo, 0); buf.writeUInt16BE(hi, 2);
const uint32_CDAB = buf.readUInt32BE(0);
const int32_CDAB  = buf.readInt32BE(0);
msg.payload = { raw:[hi,lo], 'UINT32-ABCD':uint32_ABCD,'INT32-ABCD':int32_ABCD,'UINT32-CDAB':uint32_CDAB,'INT32-CDAB':int32_CDAB };
return msg;","wires":[["dbg7"]],"x":540,"y":500},
  {"id":"dbg7","type":"debug","name":"32-bit values","active":true,"complete":"payload","wires":[],"x":750,"y":500},
  {"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 = {
  raw: [15, 16960],
  "UINT32-ABCD": 1000000,
  "INT32-ABCD":  1000000,
  "UINT32-CDAB": 1111572495,
  "INT32-CDAB":  1111572495
}

Common Gotchas

  • Signed (INT32) and unsigned (UINT32) share the same raw bytes — only the interpretation differs.
  • A value of 4,294,967,295 as UINT32 is −1 as INT32 (two's complement).
  • The 'high word' vs 'low word' placement is device-specific — AB-CD means hi word at lower address.
  • Some Modicon PLCs use CD-AB (low word first) for all 32-bit types, including floats.
  • Always use Buffer.readUInt32BE / readInt32BE after assembling bytes — do not just multiply hi*65536+lo if the value could be negative.

Same in ModPackQT — in 30 seconds

ModPackQT's Data Type Converter decodes any register pair as UINT32, INT32, FLOAT32, or FLOAT64 in all byte orders simultaneously — no JavaScript required.

Was this example helpful?

More Reads examples

All Node-RED Modbus Examples (30)

ModPackQT · Node-RED Modbus Examples · Updated 2026