How to Fix Modbus Float Byte and Word Order
A flow rate that should read 42.7 comes back as 3.4 times ten to the twentieth, or as a tiny fraction, or as a negative number that makes no physical sense. The communication is clean, the two registers arrive every poll, and yet the float is nonsense. This is an endianness problem: the four bytes of the IEEE-754 value are being reassembled in an order the device did not use. This guide is the fix procedure - the specific sequence of trying word swap, then byte swap, then both, against a known reference until the number is right.
Fix Modbus float endianness in one line: A garbled Modbus float is almost always a byte or word order mismatch: the device packed the four bytes of the IEEE-754 value in one order and your driver is reassembling them in another. Fix it by comparing the decoded value to a known reference, then trying the four permutations in order - as-is, word-swapped, byte-swapped, and both swapped - and selecting the one setting that makes the number match. Set that word order per device, not globally.
Confirm the Comms Are Clean First
Before touching endianness, make sure the bytes are actually arriving intact, because a decode fix cannot repair corrupted data. A float that changes wildly poll to poll, or that comes and goes, points at line problems rather than word order - check for the pattern behind Modbus RTU CRC errors first. A float that is consistently and repeatably wrong, the same garbage value every poll for a steady process, is the signature of an endianness mismatch, because the same good bytes are being misassembled the same way every time.
The distinction matters because the two faults look similar on a trend but need opposite fixes. Intermittent garbage is a physical-layer problem you solve with termination, grounding, and baud rate. Steady, repeatable garbage is a decode problem you solve entirely in software by changing the data type and word order. The broader menu of decode faults - sign, scaling, and split values as well as endianness - is laid out in the guide to fixing a Modbus wrong register value; this page zooms in on the byte and word order piece.
Get a Known Reference Value
You cannot fix an ordering you cannot check against a truth, so the first real step is establishing what the number should be. The best reference is a local display on the device itself - a flow computer's front panel showing 42.7 while you poll the same register. Failing that, use a physical known: a transmitter reading a calibrated pressure, a totalizer you can zero and pulse, or a value the process makes obvious such as ambient temperature. Write down that reference number before you start swapping, because the swaps only mean something relative to it.
Understanding why one float needs two registers makes the swapping intuitive rather than trial-and-error. A 32-bit IEEE-754 float does not fit in one sixteen-bit register, so it spans two consecutive registers, as explained under a 32-bit float across two Modbus registers. Each register holds two bytes, giving four bytes total - call them A, B, C, D from most to least significant. The device sent them in some order; your job is to find which of the four legal arrangements reproduces the sign, exponent, and fraction the device intended.
Try Word Swap, Then Byte Swap, Then Both
Work the permutations in a fixed order so you never lose track. Start with the driver's default and read the value. If it is wrong, enable word swap, which exchanges the two registers so the high word and low word trade places - this is the single most common mismatch, because vendors disagree about which register comes first. Read again. If still wrong, turn word swap off and enable byte swap, which exchanges the two bytes inside each register. Read again. If still wrong, enable both word swap and byte swap together. One of these four settings will reproduce your reference value.
The reason there are exactly four is that byte order and word order are independent choices, giving two by two combinations, commonly labeled ABCD, BADC, CDAB, and DCBA. The same four permutations apply to 32-bit integers, and the mechanism is identical - the integer case is worked through under a Modbus swapped 32-bit integer. For floats the payoff of the right order is dramatic: a wrong word order can turn 42.7 into an astronomically large or vanishingly small number, because the exponent bits land in the wrong place, so when the number suddenly becomes physically plausible you have found it.
Lock the Order Per Device and Re-Verify
Once a permutation reproduces the reference, set that word order on the tag and, ideally, as the device-level default so every float from that device inherits it. Do not apply it globally across your whole SCADA, because a different device model on the same network may use a different order, and a global setting will fix one device while breaking another. Word order is a property of the device, so it belongs at the device level in your configuration.
Verify with a second, different value if you can, because a single reference can occasionally match by coincidence. If the front panel shows 42.7 at offset 100 and 118.3 at offset 102, confirm both decode correctly with the chosen order. Then watch the tag over a live process change - a float that tracks the real flow up and down, in sensible engineering units, is proof the order is right. The underlying byte layout, if you want the full picture of what each of the four bytes carries, is described under Modbus register byte order.
Frequently Asked Questions
Why does my Modbus float read a huge or tiny number?
The word order is almost certainly swapped. In an IEEE-754 float the exponent bits sit near the top, so joining the two registers in the wrong order lands the exponent in the wrong place and scales the value by an enormous factor. The fix is to enable word swap on the tag and re-read; if that is not enough, try byte swap, then both together, until the decoded value matches a known reference.
What is the difference between byte swap and word swap in Modbus?
Word swap exchanges the two sixteen-bit registers that hold a 32-bit value, so the high word and low word trade places. Byte swap exchanges the two bytes inside each individual register. They are independent, which is why there are four possible arrangements. Most float problems are solved by word swap alone; byte swap addresses the less common case where the device orders bytes within a register differently than your driver assumes.
Should I set Modbus word order globally or per device?
Per device. Word order is a property of the specific device model and its firmware, not of your whole network, so a global setting will fix one vendor's devices while breaking another's. Set the order at the device or tag level once you have confirmed it against a known value, and let all floats from that device inherit it, while other devices keep their own order.
Sources and verification
This page references the protocol specifications published by the organizations below. Editions, product capabilities, and documentation change over time - confirm current requirements and specifications directly with the source.
- Modbus Application Protocol Specification - Modbus Organization
Merobix is not affiliated with, endorsed by, or sponsored by these organizations; their names are used only to identify the standards and products discussed.
Automation services
Need help turning this into a working system?
Merobix integrates SCADA, programs Allen-Bradley and Siemens PLCs, and designs and fabricates industrial control panels.
Meeting requests are reviewed before confirmation.