Skip to Content
Modbus & RS-485Reading 64-bit registers

How to Read a 64-bit Modbus Register in Niagara 4

A 64-bit Modbus value spans four 16-bit registers. Use a 64-bit data type if your driver offers one, or read four registers and combine them in the correct word order.

Energy meters increasingly report cumulative totals as 64-bit values, because a 32-bit counter in watt-hours overflows too quickly on a large site. Niagara's Modbus drivers are most often used with 16-bit and 32-bit values, so 64-bit registers catch engineers out: the reading is zero, nonsense, or correct for a while and then wrong. This guide explains how 64-bit Modbus values are laid out, how to read them in Niagara 4, and how to avoid precision and word-order errors.

Why 64-bit values exist on Modbus devices

A Modbus register holds 16 bits. Larger numbers are spread across several consecutive registers:

Data type Registers Range
16-bit unsigned integer 1 0 to 65,535
32-bit unsigned integer 2 0 to about 4.29 billion
32-bit float (IEEE 754 single) 2 About 7 significant digits
64-bit unsigned integer (uint64) 4 0 to about 1.8 × 10¹⁹
64-bit signed integer (int64) 4 ±9.2 × 10¹⁸
64-bit float (IEEE 754 double) 4 About 15–16 significant digits

A meter counting energy in Wh as a 32-bit unsigned integer rolls over at about 4.29 GWh, which a large building can reach. A 32-bit float cannot hold a large total with useful resolution: at 10,000,000 kWh, the smallest step it can represent is about 1 kWh. Hence 64-bit registers for totals.

Step 1: Read the register map carefully

From the device's Modbus documentation, note for the value you need:

  • the starting register and whether the map uses register numbers (for example 30001) or protocol addresses (0-based)
  • the table: input registers or holding registers
  • the data type: int64, uint64 or 64-bit float (double)
  • the word order: which of the four registers holds the most significant 16 bits
  • any scaling (for example "value in 0.01 kWh")

Word order is the critical detail. Many devices send the most significant word first ("big-endian" word order), so registers N, N+1, N+2, N+3 hold bits 63–48, 47–32, 31–16 and 15–0. Others send the least significant word first. The register map should say; if it does not, you will find out by testing (see below).

Step 2: Check whether your driver supports 64-bit types directly

Modbus driver capabilities vary between Niagara releases and driver vendors. In the point's Modbus proxy extension, check the available data type options:

  • If a 64-bit integer or double type is offered, select it, set the starting address and register type, and set the device's word/byte order options to match the meter. This is the simplest and most reliable approach.
  • If no 64-bit type is offered, use the combine four registers method below.

Keep your Niagara and driver versions current; newer releases add data types and fix decoding issues.

Step 3 (if needed): Combine four registers

For 64-bit integers (int64 or uint64)

  1. Create four numeric proxy points, each reading one register as an unsigned 16-bit integer: registers N, N+1, N+2 and N+3. Use block reads so they are read in the same request.

  2. Name them clearly, for example Energy_W3 (most significant) to Energy_W0 (least significant), according to the device's word order.

  3. Combine them with logic or a Program object:

    value = W3 × 2⁴⁸ + W2 × 2³² + W1 × 2¹⁶ + W0

    where 2¹⁶ = 65,536, 2³² = 4,294,967,296 and 2⁴⁸ = 281,474,976,710,656.

  4. Apply any scaling from the register map, for example divide by 1,000 to convert Wh to kWh.

  5. For signed int64 values, if W3 is 32,768 or more the number is negative; subtract 2⁶⁴ from the result. Energy totals are almost always unsigned, so this rarely applies.

For 64-bit floats (double)

A 64-bit float cannot be reconstructed with simple arithmetic, because its bits encode a sign, exponent and fraction. Combine the four registers into a 64-bit bit pattern and convert it to a double in a Program object (in Java, Double.longBitsToDouble on the combined value). This needs someone comfortable writing Niagara program objects; alternatively, check whether the device offers the same value in another format (for example a scaled integer).

Precision: the 2⁵³ limit

Niagara numeric points hold values as 64-bit floating-point numbers (doubles). A double represents every integer exactly only up to 2⁵³ (about 9 × 10¹⁵). Above that, the last digits are rounded.

For energy totals this is rarely a problem in practice: 9 × 10¹⁵ Wh is 9 billion MWh. But it matters for:

  • counters in very small units (for example mWh or pulses) that grow very large
  • calculations that subtract two huge totals to get a small difference, where rounding can swamp the result

To keep resolution:

  • scale early: convert to kWh or MWh as part of the combination
  • calculate consumption from deltas over short periods (for example the difference between readings 15 minutes apart) using history, rather than subtracting enormous lifetime totals in logic
  • use the device's own interval or period registers if it provides them

Step 4: Test against the device

Always verify against the meter's own display or software:

  1. Note the total shown on the device.
  2. Compare it with the value in Niagara.
  3. If Niagara's value is wildly wrong (astronomically large or tiny), the word order is probably reversed. Swap the combination order (W0 ↔ W3, W1 ↔ W2) or change the word order setting.
  4. If it is close but out by a factor of 10, 100 or 1,000, the scaling is wrong.
  5. If it is consistently wrong by a small amount, check you are reading the right registers: an off-by-one address error (register 30001 vs address 0) shifts every word.

Watch the value over time. A total that suddenly jumps backwards or by a huge amount usually means the four registers were not read in the same request, so a carry between words happened between reads. Use block reads, or read the value twice and accept it only when both reads agree.

Handling meter rollovers and resets

Even 64-bit totals can reset: a meter is replaced, its memory is cleared, or a technician resets the total during commissioning. A total that suddenly drops to near zero produces a huge negative "consumption" in reports. Protect against it:

  • add logic that detects a decrease in a total that should only increase, and raises an alarm
  • in consumption calculations, ignore negative deltas and flag the period for review
  • when a meter is replaced, record the old meter's final reading and the new meter's starting reading in the site log
  • for 32-bit counters that genuinely wrap around at their maximum, add the counter's range to negative deltas

Testing with a Modbus tool first

When a 64-bit value will not decode, take Niagara out of the equation. Connect a laptop running a Modbus test tool (several free and commercial tools exist) directly to the device, read the four registers, and look at the raw values. With the raw words in front of you, try both word orders on a calculator until the result matches the meter's display. Then configure Niagara to do the same thing. This avoids guessing through repeated station edits, and gives you a record of the raw values for your notes.

Recording 64-bit totals in histories

  • Record the combined, scaled value, not the four raw words.
  • Use a numeric interval history (for example every 15 or 30 minutes) for consumption reporting.
  • Mark the history's units clearly (kWh, MWh).
  • For energy reporting, calculate consumption from deltas between interval values; tools such as tenant billing and analytics work from these.

See Niagara Tenant Billing and BMS vs BEMS for how totals are used downstream.

Worked example: a 64-bit energy total

A main incoming meter's register map lists:

Value Registers Type Units Word order
Total import active energy 30801–30804 uint64 Wh Most significant word first

The procedure:

  1. Create four NumericPoints reading input registers at protocol addresses 800, 801, 802 and 803 as unsigned 16-bit integers, grouped in one block read. Name them W3, W2, W1 and W0 in that order, because the most significant word comes first.
  2. Combine: Energy_Wh = W3 × 281,474,976,710,656 + W2 × 4,294,967,296 + W1 × 65,536 + W0.
  3. Scale: Energy_kWh = Energy_Wh ÷ 1,000.
  4. The meter display shows 1,284,507.3 kWh. Niagara shows 1,284,507.312 kWh. The values match, so the word order and addresses are right.
  5. Add a 15-minute interval history on Energy_kWh, and use it for consumption reports and tenant billing.

Had the word order been reversed, Niagara would show an absurd number in the order of 10¹⁹; swapping the order of W0–W3 in the formula would fix it.

Alternatives to 64-bit registers

If 64-bit decoding is awkward, check whether the device offers the same quantity another way:

  • 32-bit registers in larger units, for example energy in kWh or MWh rather than Wh, which may fit comfortably in 32 bits
  • resettable or period totals, such as energy this month, which stay small
  • pulse outputs counted by an I/O module, for simple consumption metering
  • a different protocol, such as M-Bus or BACnet, if the meter supports it and a gateway or driver is available

Choose the option that is reliable and easy for the next engineer to understand.

Common mistakes

Mistake Result
Reading the four registers in separate polls Occasional large jumps when a carry happens between reads
Wrong word order Huge or tiny nonsense values
Treating a 64-bit float as an integer Meaningless large numbers
Off-by-one register address All four words shifted; plausible but wrong values
Ignoring scaling Values out by a power of ten
Subtracting huge totals in logic Loss of resolution on small differences

Frequently asked questions

How many Modbus registers is a 64-bit value?

Four consecutive 16-bit registers.

Does the Niagara Modbus driver support 64-bit values?

It depends on the Niagara and driver version. Check the data type options on the point's proxy extension. If no 64-bit type is available, read four 16-bit registers and combine them.

How do I combine four Modbus registers into one value?

For integers, value = W3 × 2⁴⁸ + W2 × 2³² + W1 × 2¹⁶ + W0, with W3 the most significant word according to the device's word order. For 64-bit floats, use a Program object to convert the combined bits.

Why is my 64-bit Modbus value huge or nonsensical?

Usually reversed word order, an off-by-one register address, or a 64-bit float being decoded as an integer.

Will Niagara lose precision on 64-bit values?

Niagara numerics are doubles, exact for integers up to 2⁵³. Scale to kWh or MWh early and calculate consumption from deltas to keep resolution.

What is the difference between uint64 and int64?

uint64 is unsigned (zero and positive values only); int64 is signed and can be negative. Energy totals are almost always uint64.

Can I use a Program object to read 64-bit values?

Yes. A Program object can combine the four registers, handle sign and word order, and convert 64-bit floats, which simple math blocks cannot.

Why does my energy total occasionally jump?

The registers were read in different polls and a carry occurred between them. Read all four registers in one request.

Why does my 64-bit value read zero?

Usually the wrong register table (input vs holding), an address offset that reads unused registers, or a device that only returns 64-bit values when all four registers are requested in a single read.

Can I history a 64-bit value directly?

Yes, once it is combined into a single numeric point. Record the combined, scaled value rather than the raw registers.

Need help from a Niagara engineer?

If this guide has not solved the problem, contact the Tyrrell Products technical team on 01942 732819 or [email protected]. Tell us the controller or host type, its Niagara version and what you have already tried, and we will help you get the system running.