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
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