Skip to content
You Start with one site
Amounts in Start with one site
Control, Measurement & Energy · Course

Register Maps, Data Types and Scaling

Lesson 3 of 10 25 min read
Found this useful?

An energy report says a compressor used 16 million kilowatt-hours in seven months, and the finance office asks who will pay. The meter is correct, the cable is correct and every frame has a good CRC. The fault is two register words joined in the wrong order. Modbus carries 16-bit words and says nothing about what they mean, so the meaning comes from the maker’s register map and from you. This lesson shows how to read that map, decode each data type, and test the result before anyone trusts it. #Modbus #RegisterMap #DataTypes

Learning Objectives

By the end of this lesson, you will be able to:

  1. Convert a register number in a manual into the address that is sent on the wire
  2. Decode signed and unsigned 16-bit registers with their scaling factors
  3. Join two registers into a 32-bit integer or an IEEE 754 float32 in the stated word order
  4. Read single bits out of a status word
  5. Test a decoded value for plausibility before it enters a record

Real-World System Problem: An energy meter that reports the wrong total



A three-phase energy meter sits on the feeder of a compressor. It is a Modbus RTU server at address 5. A gateway reads it over RS-485 and passes the readings upward. Its numbers divide the energy bill between departments, and later they are the proof that a saving is real.

The response to a read is a row of bytes. Nothing in the frame says “this is a voltage” or “this is half of a 32-bit counter”, and the CRC proves only that the bytes arrived as sent. Which register holds which quantity, whether it is signed, how two registers join, and what one count is worth are in the maker’s register table. Read that table wrongly when you configure the gateway, and the bus works without one error while the record is false.

Some false values are easy to see, for example a voltage of 6,553.5 V. Others look reasonable: a power of 8.40 kW where the true value is 24.15 kW.

Gateway(client)CompressorfeederMeter Aaddress 5RS-485, Modbus RTUreads registersraw wordsmeasures0x00BC 0x614Eregister map:type, word order, scale123,456.78 kWh
From raw words to an engineering value

Fundamental Theory: From a register word to a value



What a register is

A holding register is one 16-bit word inside the server. On the wire it travels as two bytes, high byte first. As a plain number it lies between 0 and 65,535, or in hexadecimal between 0x0000 and 0xFFFF. This plain number is called the raw value, or the count.

Five decisions stand between the raw value and the quantity:

  1. which address to ask for,
  2. whether the word is signed or unsigned,
  3. whether it stands alone or is part of a larger value, and in which order,
  4. what one count is worth (the scaling factor),
  5. whether the word is a number at all, or a set of separate bits.

Register numbers and addresses

Manuals name holding registers with numbers that begin at 40001; the frame carries an address that begins at 0, like a building whose wall signs start at floor 1 and whose lift buttons start at 0. The leading 4 is not sent at all: it only says “holding register”, and the function code already carries that.

Register number to address

Holding register 40001 is address 0x0000. Holding register 40007 is address 6, which is 0x0006.

With six-digit numbers, subtract 400001. Input registers are numbered from 30001, are read with function 04, and give address = register number − 30001.

Many energy meters keep their readings in input registers, not holding registers. A read of 30007 with function 03 does not reach it: the server answers exception 02, or returns holding register 40007, which may hold something else. Match the function code to the leading digit in the table.

Register4000140002...4000740008(manual)Address0x00000x0001 ...0x00060x0007(wire)QuantityV L1-NV L2-NPowerPowerfactor
The number in the manual and the address on the wire

The register map of meter A, used through this course, is:

RegisterAddressQuantityTypeScaling
400010x0000Voltage L1-Nuint160.1 V per count
400020x0001Voltage L2-Nuint160.1 V per count
400030x0002Voltage L3-Nuint160.1 V per count
400040x0003Current L1uint160.01 A per count
400050x0004Current L2uint160.01 A per count
400060x0005Current L3uint160.01 A per count
400070x0006Total active powerint160.01 kW per count
400080x0007Power factorint160.001 per count
400090x0008Frequencyuint160.01 Hz per count
40011 to 400120x000AActive energy importuint32, high word first0.01 kWh per count
40013 to 400140x000CActive power, precisefloat32, high word firstkW

Register 40010 is not in the table. Maps often have such gaps. Some servers answer an exception when a read includes an address they do not define, so read 40001 to 40009 as one block and 40011 to 40014 as another.

Scaling

A register holds whole numbers only. To carry 240.3 V, the meter stores 2,403 and the table says that one count is 0.1 V.

Scaling

The first form decodes a reading. The second form prepares a value for a write.

The scaling factor also fixes the largest value the register can hold. An unsigned register at 0.1 V per count ends at . A signed register at 0.01 kW per count ends at . A meter for a larger load must use a coarser scale or a wider type.

Tables write the same scaling in several ways: “0.1 V per count”, “multiplier 0.1”, “divide by 10” or “one decimal place”. They mean the same thing.

Signed and unsigned 16-bit

An unsigned 16-bit word (uint16) covers 0 to 65,535. A signed word (int16) uses the same 16 bits in two’s complement, the usual way computers store negative whole numbers: raw values from 32,768 to 65,535 stand for −32,768 to −1. It covers −32,768 to 32,767. The bits on the wire are identical. Only the reading differs.

Signed 16-bit from a raw word

For raw values up to 32,767 the two readings agree, so a wrong choice stays hidden while the quantity is positive. It shows on the day the quantity becomes negative. Take a power factor register that holds 0xFCB8:

  • read as unsigned: , which is impossible for a power factor,
  • read as signed: , and .

The signed reading is right. The maker’s manual says what the sign means.

A 32-bit integer across two registers

An energy counter at 0.01 kWh per count does not fit in 16 bits. An unsigned word would reach its end at 655.35 kWh, which this compressor uses in about 27 hours. The meter therefore uses a 32-bit unsigned integer (uint32) spread over two registers that follow each other.

Let be the word that carries the upper 16 bits and the word that carries the lower 16 bits.

Joining two words

Modbus fixes the byte order inside one register: high byte first. It does not fix which register carries the upper half. Both orders are in use:

  • high word first, often written ABCD or “big-endian”: the first register is ,
  • low word first, often written CDAB or “word-swapped”: the first register is .
400120x00BC400110x614E400120x614E400110x00BCValue 12,345,678 = 0x00BC614EHigh word first (ABCD)Low word first (CDAB)bytes 00 BC 61 4Ebytes 61 4E 00 BC
One 32-bit value, two possible layouts

Meter A uses high word first, and its table says so. Many tables do not say, and then you find the order by test, as Application 1 shows. Read a 32-bit value in one request: if the two halves come from two requests, the counter can step between them and the halves no longer belong together.

A float32 across two registers

A float32 is the 32-bit floating point format of IEEE 754. Its 32 bits are a sign bit , an 8-bit exponent and a 23-bit fraction .

IEEE 754 float32

For 24.15 the four bytes are 41 C1 33 33. The sign bit is 0, the exponent is , so the factor is , and the fraction gives 1.509375. The product is .

A float32 needs no scaling factor, because it carries its own exponent. It keeps about seven significant digits, so the stored number is 24.1499996 and not exactly 24.15. It has the same word order question as the 32-bit integer.

Some devices, and some gateway settings, also swap the two bytes inside each word (written BADC, or DCBA when both swaps are made). Most of the wrong orders give absurd values, but not all: the bytes of 24.15 kW read as BADC give −12.07 kW, wrong yet not impossible. So test all four orders, and keep the one that agrees with a second source.

Bit fields in status words

Some registers are not numbers. Each bit is a separate yes or no. Bit 0 is the lowest bit, with a weight of 1. Bit has a weight of .

Reading and setting one bit

In code this is (word >> n) & 1. To set bit in a word that you will write, use word | (1 << n).

1001000000000000bit1514131211109876543210faultrunning
Status word 0x0009 of drive B

Some manuals count bits from 1 and not from 0, so “bit 1” in one manual is bit 0 in another. And never scale a status word: 0x0009 is not “9 of something”, it is two separate facts.

The checks that catch a wrong map

A CRC cannot find a wrong map. A plausibility check can find most of them. Before a new point enters the record, ask these questions.

  • Is the value inside the range that the equipment can physically produce? A phase voltage of 6,553.5 V on a 240 V system is the raw value 0xFFFF. A power factor of 32.768 is the raw value 0x8000. Values at the exact end of a type are almost never measurements. They are a wrong type, a wrong address, or a marker the maker uses for “no value”.
  • Does the value agree with a second source: the meter’s own display, or another register that should give the same quantity?
  • Do related quantities agree with each other? Power should be close to the sum of voltage times current times power factor.
  • Does it change sensibly from one poll to the next? An energy counter must rise slowly and never fall.

Application 1: Decode the energy and the precise power of meter A



Step 1: Take the register words out of the response

Click to reveal the four words
  1. Check the header. The first byte is the address, 05. The second is the function code, 03. The third is the byte count, 08, which is four registers of two bytes each. ✅

  2. Split the data into words. Each register is two bytes, high byte first.

    RegisterBytesWord
    4001100 BC0x00BC
    4001261 4E0x614E
    4001341 C10x41C1
    4001433 330x3333

    The last two bytes, 8C 76, are the CRC and are not data. ✅

Step 2: Decode the energy in both word orders

Click to reveal the two energy values
  1. High word first. The first register is the upper half: and .

    The energy is 123,456.78 kWh. ✅

  2. Low word first. Now the first register is taken as the lower half: and .

    The same four bytes now read as 16.3 million kWh. ✅

  3. Test against the load. At 24.15 kW without a stop, the first value needs

    which fits a meter that is seven months old. The second value needs 676,000 hours, which is 77 years. Only high word first is possible. ✅

Step 3: Decode the precise power in both word orders

Click to reveal the two power values
  1. High word first. The four bytes in order are 41 C1 33 33. The sign bit is 0. The exponent is , so the factor is . The fraction is .

    The power is 24.15 kW. ✅

  2. Low word first. The four bytes become 33 33 41 C1. Python gives

    which is 42 millionths of a watt. No compressor feeder carries that. ✅

  3. Cross-check with the 16-bit register. Register 40007 holds the same power as an int16 at 0.01 kW per count. In the example readings it holds 2,415 counts, which is 24.15 kW. The float32 with high word first agrees with it. ✅

Step 4: Confirm with a second reading

A single reading can mislead when both halves of a value are small. Two readings a short time apart settle the question.

Click to reveal the second reading and the script check
  1. Expected change in one minute. At 24.15 kW, one minute adds

    The counter should rise by 0.40 kWh. ✅

  2. High word first. The new words are 0x00BC and 0x6176. The lower word rose from 0x614E to 0x6176, which is 40 counts. The energy is 123,457.18 kWh, a rise of 0.40 kWh. ✅

  3. Low word first. The word that changed is now treated as the upper half, so each of its counts is worth 65,536.

    That is a power of 1.57 million kW through a compressor feeder. The wrong order shows itself as a counter that jumps. ✅

  4. Check with the script. The Python script below builds the response with struct, decodes it both ways and prints 123,456.78 kWh and 16,325,019.48 kWh, then 24.15 kW and 4.17365e-08 kW, and the two steps of 0.40 kWh and 26,214.40 kWh. All values agree with the hand calculation. ✅

Application 2: Read the status of drive B and write a speed reference



Step 1: Decode the status block

Click to reveal the decoded block
  1. Output frequency. Register 40201 holds 0x0DAC, which is 3,500 counts.

    The drive output is 35.00 Hz. ✅

  2. Output current. Register 40202 holds 0x00A2, which is 162 counts, so the current is . ✅

  3. Status word. Register 40203 holds 0x0009. In binary this is 0000 0000 0000 1001. Since , bit 3 and bit 0 are set and every other bit is clear. ✅

  4. Meaning. Bit 0 set: the drive is running. Bit 3 set: the drive reports a fault. Both are true at the same moment. ✅

  5. Fault code. Register 40204 holds 0x0004, fault code 4. The number alone means nothing. Its meaning is in the fault table of the maker’s manual for this drive. ✅

Step 2: Build the write request

Click to reveal the request, byte by byte
  1. Convert the value to counts.

    The value fits in 16 bits. ✅

  2. Convert the register number to an address. . ✅

  3. Assemble the frame. Function 06 writes one holding register. The frame is the address, the function code, the register address and the value, each 16-bit field with its high byte first.

    FieldBytes
    Server address (10)0A
    Function code06
    Register address00 64
    Value10 9A
    CRC, low byte first44 C5

    The request is 0A 06 00 64 10 9A 44 C5. ✅

  4. The response. For function 06 a server that accepts the write returns the request unchanged: 0A 06 00 64 10 9A 44 C5. An exception response, with function code 0x86, means the drive refused the write. ✅

Step 3: Decide, then check the frame

Click to reveal the decision and the check
  1. Do not send it yet. The status word shows a fault. A drive that reports a fault needs a person at the machine before anyone changes its speed from a distance. The correct action for the gateway is to record the status and the fault code and to raise an alert. ✅

  2. After the fault is cleared and the permit is given, send the write, then read register 40101 again. It must return 0x109A. Then read 40201 over the next seconds: the output frequency should move from 35.00 Hz toward 42.50 Hz along the drive’s own ramp. ✅

  3. Check with the script. The Python script builds the same frame with struct.pack('>BBHH', 10, 6, 0x0064, 4250), adds the CRC and prints 0A 06 00 64 10 9A 44 C5. It also decodes the status block and prints 35.00 Hz, 16.2 A, status 0x0009 and fault code 4. ✅

Verify It in Python



The script builds each response with the struct module, checks its CRC and decodes it: the energy and the precise power in both word orders, 0xFCB8 signed and unsigned, the off-by-one with the readings of meter A, the status block of drive B, and the write request. The plot shows ten polls of the energy registers, one minute apart, decoded in both word orders.

register_decode.py
"""Decode Modbus register words: word order, float32, signed values and bit fields."""
import struct
import matplotlib.pyplot as plt
def crc16(data):
"""CRC-16/MODBUS: polynomial 0xA001, initial value 0xFFFF, low byte first."""
crc = 0xFFFF
for byte in data:
crc ^= byte
for _ in range(8):
crc = (crc >> 1) ^ 0xA001 if crc & 1 else crc >> 1
return struct.pack("<H", crc)
def hexs(data):
return " ".join(f"{b:02X}" for b in data)
def words_from_response(frame):
"""Check the CRC of a function 03 response and return its register words."""
assert crc16(frame[:-2]) == frame[-2:], "CRC error"
count = frame[2]
return list(struct.unpack(f">{count // 2}H", frame[3:3 + count]))
def u32(w0, w1, high_first=True):
hi, lo = (w0, w1) if high_first else (w1, w0)
return struct.unpack(">I", struct.pack(">HH", hi, lo))[0]
def f32(w0, w1, high_first=True):
hi, lo = (w0, w1) if high_first else (w1, w0)
return struct.unpack(">f", struct.pack(">HH", hi, lo))[0]
def s16(word):
return struct.unpack(">h", struct.pack(">H", word))[0]
assert hexs(crc16(bytes.fromhex("01030000000A"))) == "C5 CD"
# ---------- Application 1: meter A, registers 40011 to 40014 ----------
request = struct.pack(">BBHH", 5, 3, 0x000A, 4)
print("Meter A, energy and precise power")
print(" request :", hexs(request + crc16(request)))
body = struct.pack(">BBB", 5, 3, 8) + struct.pack(">I", 12345678) + struct.pack(">f", 24.15)
response = body + crc16(body)
print(" response:", hexs(response))
w = words_from_response(response)
print(" words :", " ".join(f"0x{x:04X}" for x in w))
for name, high_first in (("high word first", True), ("low word first ", False)):
counts = u32(w[0], w[1], high_first)
print(f" energy, {name}: {counts:>10d} counts = {counts * 0.01:,.2f} kWh")
for name, high_first in (("high word first", True), ("low word first ", False)):
print(f" power, {name}: {f32(w[2], w[3], high_first):.6g} kW")
wrong = u32(w[0], w[1], False) * 0.01
print(f" years at 24.15 kW to reach the wrong value: {wrong / 24.15 / 8760:.1f}")
print(f" years before the uint32 counter rolls over: "
f"{0xFFFFFFFF * 0.01 / 24.15 / 8760:.0f}")
# ---------- Signed against unsigned, and the off-by-one ----------
print("Signed and unsigned")
print(f" 0xFCB8 unsigned: {0xFCB8} counts = {0xFCB8 * 0.001:.3f}")
print(f" 0xFCB8 signed : {s16(0xFCB8)} counts = {s16(0xFCB8) * 0.001:.3f}")
regs = [2403, 2398, 2411, 4012, 3987, 4031, 2415, 840, 5002] # 40001 to 40009
print("Off-by-one")
print(f" address 6 (register 40007): {regs[6]} counts = {regs[6] * 0.01:.2f} kW")
print(f" address 7 (register 40008): {regs[7]} counts = {regs[7] * 0.01:.2f} kW (wrong)")
volts = [r * 0.1 for r in regs[0:3]]
amps = [r * 0.01 for r in regs[3:6]]
p_check = sum(v * i for v, i in zip(volts, amps)) * regs[7] * 0.001 / 1000.0
print(f" power from volts, amps and power factor: {p_check:.2f} kW")
# ---------- Application 2: drive B ----------
print("Drive B")
body = struct.pack(">BBB4H", 10, 3, 8, 3500, 162, 0x0009, 4)
response = body + crc16(body)
print(" status block:", hexs(response))
freq, amp, status, fault = words_from_response(response)
print(f" output {freq * 0.01:.2f} Hz, {amp * 0.1:.1f} A, "
f"status 0x{status:04X} = {status:016b}, fault code {fault}")
print(f" bit 0 running: {status & 1}, bit 3 fault: {(status >> 3) & 1}")
setpoint = round(42.50 / 0.01)
write = struct.pack(">BBHH", 10, 6, 0x0064, setpoint)
write += crc16(write)
print(f" 42.50 Hz = {setpoint} counts = 0x{setpoint:04X}")
print(" write request :", hexs(write))
print(" write response:", hexs(write), "(echo)")
# ---------- Plot: ten polls, one minute apart, both word orders ----------
minutes = list(range(10))
right, swapped = [], []
for m in minutes:
counts = 12345678 + round(24.15 / 60.0 / 0.01 * m)
hi, lo = counts >> 16, counts & 0xFFFF
right.append(u32(hi, lo, True) * 0.01)
swapped.append(u32(hi, lo, False) * 0.01)
print("One minute later")
print(f" high word first: {right[1]:,.2f} kWh (step {right[1] - right[0]:.2f} kWh)")
print(f" low word first : {swapped[1]:,.2f} kWh (step {swapped[1] - swapped[0]:,.2f} kWh)")
fig, ax = plt.subplots(2, 1, figsize=(8, 6), sharex=True)
ax[0].plot(minutes, right, "o-")
ax[0].set_ylabel("energy (kWh)")
ax[0].set_title("High word first: the counter climbs 0.40 kWh per minute")
ax[0].ticklabel_format(useOffset=False, style="plain")
ax[1].plot(minutes, swapped, "s-", color="tab:red")
ax[1].set_ylabel("energy (kWh)")
ax[1].set_xlabel("poll (minutes)")
ax[1].set_title("Low word first: the same registers decoded in the wrong order")
ax[1].ticklabel_format(useOffset=False, style="plain")
fig.tight_layout()
fig.savefig("register_decode.png", dpi=120)
print("Saved register_decode.png")

Expected output

Meter A, energy and precise power
request : 05 03 00 0A 00 04 65 8F
response: 05 03 08 00 BC 61 4E 41 C1 33 33 8C 76
words : 0x00BC 0x614E 0x41C1 0x3333
energy, high word first: 12345678 counts = 123,456.78 kWh
energy, low word first : 1632501948 counts = 16,325,019.48 kWh
power, high word first: 24.15 kW
power, low word first : 4.17365e-08 kW
years at 24.15 kW to reach the wrong value: 77.2
years before the uint32 counter rolls over: 203
Signed and unsigned
0xFCB8 unsigned: 64696 counts = 64.696
0xFCB8 signed : -840 counts = -0.840
Off-by-one
address 6 (register 40007): 2415 counts = 24.15 kW
address 7 (register 40008): 840 counts = 8.40 kW (wrong)
power from volts, amps and power factor: 24.29 kW
Drive B
status block: 0A 03 08 0D AC 00 A2 00 09 00 04 35 78
output 35.00 Hz, 16.2 A, status 0x0009 = 0000000000001001, fault code 4
bit 0 running: 1, bit 3 fault: 1
42.50 Hz = 4250 counts = 0x109A
write request : 0A 06 00 64 10 9A 44 C5
write response: 0A 06 00 64 10 9A 44 C5 (echo)
One minute later
high word first: 123,457.18 kWh (step 0.40 kWh)
low word first : 16,351,233.88 kWh (step 26,214.40 kWh)
Saved register_decode.png

Look at the “Off-by-one” lines. A client that wants register 40007 and sends address 7 receives 840 counts, the power factor. Scaled as power, that is 8.40 kW. The value is inside the physical range, so a range check passes it. The cross-check does not: the three voltages, the three currents and the power factor give 24.29 kW, close to the true 24.15 kW and far from 8.40 kW.

Common Mistakes



  • Sending the register number without converting it. Register 40007 is address 6. If the result looks reasonable but disagrees with the display, read one address lower and one higher and compare.
  • Reading a signed register as unsigned. It works for months while the value is positive, then shows 64.696 or 655.35 on the day the value becomes negative. Take the type from the table, not from the first reading.
  • Assuming the word order of a 32-bit value. The standard does not fix it. Take it from the table, or watch which word changes between two polls.
  • Reading the two halves of a 32-bit value in two separate requests. Read both registers in one request so that they belong to the same instant.
  • Treating the echo of a write as proof that the machine obeyed. Read the measured result.

Summary



  • A register is a 16-bit word with no meaning of its own. The register map gives the address, the type, the word order and the scaling.
  • The address on the wire is the register number minus 40001. A wrong address returns a neighbour without any error.
  • Signed and unsigned readings differ only for raw values of 32,768 and above. A signed value is the raw value minus 65,536 in that range.
  • A 32-bit integer or a float32 uses two registers. The word order is the maker’s choice, so state it and test it.
  • A status word is a set of bits. Read each bit by its position and never scale the word.
  • A good CRC does not prove a good value. Range, cross-check and change between polls do.

Exercises



1. Give the address, in decimal and in hexadecimal, that is sent for holding registers 40013 and 40204. Then give the register number for address 0x0064.

Answer

and . Address 0x0064 is 100, so the register is .

2. On a site with solar panels, the total active power register of a meter (int16, 0.01 kW per count) returns 0xFB1E. Give the power. Then give the value that a client shows if it reads the register as unsigned.

Answer

0xFB1E is 64,286, which is above 32,767, so the signed value is counts, or (power flows the other way). Read as unsigned it shows 642.86 kW.

3. A second meter returns 0x0096 and 0xB43F for its energy registers (uint32, 0.01 kWh per count). Decode the energy with high word first and with low word first. The meter serves a 30 kW load and is one year old. Which order is right?

Answer

High word first: counts, which is 98,765.43 kWh. Low word first: counts, which is 30,240,277.98 kWh. A 30 kW load can use at most kWh in a year, so high word first is right.

4. Two registers hold 0x4366 and 0x8000. The table says float32, high word first, in volts. Decode the value by hand. Then say what the bytes give with the words swapped.

Answer

The bytes are 43 66 80 00. The sign is 0, the exponent is 134, so the factor is . The fraction is 0x668000, which is 6,717,440, and . The value is . With the words swapped the bytes are 80 00 43 66, which struct.unpack('>f', ...) decodes as about , plainly not a voltage.

5. Drive B (address 10) later returns a status word of 0x0008. State what the drive is doing. Then build the complete function 06 request, with CRC, that sets its speed reference (register 40101) to 30.00 Hz, and say what must be true before it is sent.

Answer

0x0008 has only bit 3 set: a fault is present and the drive is not running. The value is and the address is 0x0064, so the frame is 0A 06 00 64 0B B8 plus its CRC, CE 2C: 0A 06 00 64 0B B8 CE 2C. It is sent only after the fault has been examined and cleared at the machine, and under the site’s permit and lock-out rules.

References



  • Modbus Organization, MODBUS Application Protocol Specification V1.1b3, 2012.
  • Modbus Organization, MODBUS over Serial Line Specification and Implementation Guide V1.02, 2006.
  • IEEE, IEEE Standard for Floating-Point Arithmetic, IEEE Std 754-2019.


© 2021-2026 SiliconWit®. All rights reserved.
GatewayclientMeter Aaddress 5RS-485, Modbus RTUreads registersmeasuresCompressorfeederraw words0x00BC 0x614Eregister map:type, word order, scale123,456.78 kWh
From raw words to an engineering value
Registerin the manualAddresson the wireQuantity400010x0000V L1-N400020x0001V L2-N400070x0006Power400080x0007Powerfactor......
The number in the manual and the address on the wire
Value 12,345,678 = 0x00BC614EHigh word first (ABCD)400110x00BC400120x614Ebytes 00 BC 61 4ELow word first (CDAB)400110x614E400120x00BCbytes 61 4E 00 BC
One 32-bit value, two possible layouts
bit15014013012011010090807060504031201001faultrunning
Status word 0x0009 of drive B
Predict first

A meter sends its energy counter in two registers, 0x00BC and then 0x614E, at 0.01 kWh per count. The true value is 123,456.78 kWh. A gateway joins the two words in the wrong order. What does its record show?

See it: two words, read four ways
The four bytes on the wire

First word alone, 16 bits

Second word alone, 16 bits

Unsigned 32-bit, high word first (ABCD)

Unsigned 32-bit, low word first (CDAB)

Float32, high word first (ABCD)

Float32, low word first (CDAB)

The two words are the same in every card. Only the reading changes. A whole number is multiplied by the scaling. A float32 carries its own exponent, so no scaling is applied to it. The three buttons load words from the lesson, and then each card says whether its value is possible for the lesson's compressor, which takes about 24 kW and has a meter about seven months old. For your own words the page cannot know the machine, so the cards give the general test. A float32 is decoded by the browser from the four bytes, in the order shown in each card.

Check yourself

Three questions. Each wrong choice is a mistake people really make, so read the note after you answer.

1. On a site with solar panels, the total active power register of a meter (int16, 0.01 kW per count) returns 0xFF38, which is 65,336 as a plain number. What is the power?

2. A client wants the total active power of the lesson's meter, register 40007, and sends address 7. The meter holds 2,415 counts in register 40007 and 840 counts in register 40008. Both are scaled by 0.01 kW in the client. What does the client show?

3. A table gives an energy counter as uint32 in two registers and does not state the word order. One poll returns 0x00BC and 0x614E. A minute later the poll returns 0x00BC and 0x6176. Which register is the low word?

manualwire 40006400074000840009 5678 Send 7: you read 40008, the neighbour. No error.
high word firstlow word first 00BC614E614E00BC 123,456.78 kWh 16,325,019.48 kWh
Watch it build: four bytes become 24.15
41 C1 C1 41 33 33 33 33 01000001110000010011001100110011 sE: 8 bitsF: 23 bits 32 bits: sign, exponent, fraction(−1)^s × (1 + F/2^23) × 2^(E−127) s = 0, E = 131, so × 16 1.509375 × 16 = 24.15 stored: 24.1499996about 7 digits, no scaling factor read as BADC: −12.07 kWwrong, yet not impossibletest all four orders
  1. A float32 is 32 bits: 1 sign bit, an 8-bit exponent E and a 23-bit fraction F.
  2. 41 C1 33 33: sign 0, E = 131 so the factor is 16, fraction 1.509375. The value is 24.15.
  3. No scaling factor is needed. About seven digits are kept: the stored number is 24.1499996.
  4. The same bytes with each word's two bytes swapped (BADC) give −12.07 kW: wrong, yet not impossible.
Found this useful?

Discussion

    Comments show your name. Be kind, stay on the topic.