IMDHMIControls LibraryShop main store

Explainer

Why a BRX PLC needs an even first word to read a Modbus Float32

PLC programming Published 6 min read By IMDHMI controls team

Short answer

Cast the first word of the pair with :R, for example V0:R or DLV1510:R, when the two Modbus words are consecutive, the first sits at an even offset and the byte and word order already match the BRX real view; odd first words such as V5 or DLV1511 fail the cast. When the layout cannot move, or the order must be fixed during acquisition, SUBSCRIBE handles ordering, alignment and conversion in one data path.

On this page
  1. Two registers, one 32-bit pattern
  2. The three conditions for the :R cast
  3. Why V5 and DLV1511 fail
  4. Example: decoding a 100.1 °C pair stored at V0 and V1
  5. When SUBSCRIBE is the right tool
  6. Prove it before the machine runs on it
  7. Questions asked

You already have the two 16-bit Modbus words in the BRX, and an external polling client shows the correct value on those registers when it is set to big-endian Float32 — so the payload is good and the failure is in how the PLC reinterprets it. The fix is a real-number cast on the first word: V0:R or DLV1510:R. That cast works under three conditions: the two words sit in consecutive locations, the first word of the pair is at an even offset, and the byte and word order in PLC memory already matches the BRX real view. V5 and DLV1511 are odd offsets, which is exactly why those attempts failed. Where the layout cannot move, or the order has to be corrected during acquisition, the SUBSCRIBE instruction does the ordering, alignment and conversion for you.

Two registers, one 32-bit pattern #

A Modbus Float32 is a single IEEE-754 number split across two consecutive 16-bit registers: one sign bit, eight exponent bits and 23 fraction bits make the 32 bits, and each register carries 16 of them. The words are not two measurements to convert one at a time, and they are not the high and low halves of an integer. They are one bit pattern cut in two — which is why the usual repairs fail. Copying each word into a real location converts two separate numbers, and rebuilding the value with arithmetic rungs re-derives fields you never needed to touch.

Your polling client is the proof the payload is usable: with big-endian Float32 selected on those two registers it displays the correct engineering value. Keep that setup as the reference for everything that follows. Decoding one signed 16-bit register is a different job, covered in converting an unsigned 16-bit Modbus word to a signed integer.

The three conditions for the :R cast #

The BRX real cast takes 32 bits that already sit in memory and reads them as a real number. It succeeds when all three of these hold:

  1. The two received words occupy consecutive locations.
  2. The first word of the pair is at an even offset.
  3. The byte and word ordering in PLC memory matches what the BRX real view expects.

Then reference only the first word: the pair in V0 and V1 reads as V0:R, and the pair in DLV1510 and DLV1511 reads as DLV1510:R. Use that expression directly wherever a rung takes a real operand. The cast moves nothing and changes no bits; it is a typed view of storage that is already there, which is also why building a custom two-word data type and trying to move it into R memory leads nowhere.

Why V5 and DLV1511 fail #

Both failed locations share one fault: the first word of the pair sits at an odd offset. The original pair in DLV1511 and DLV1512 begins at 1511. Relocating it to V5 and V6 preserved the fault, because 5 is odd too — swapping memory areas never touched the alignment condition. The cast needs an even first word, so move the pair to V0 and V1, to DLV1510 and DLV1511, or to DLV1512 and DLV1513, then cast the first of the two with :R: V0:R for the V pair, DLV1510:R for the first DLV pair, and the same cast form on DLV1512 for the second.

If the map cannot be relocated — the polling configuration writes the words where it writes them — that is the case for SUBSCRIBE, not for more ladder.

Example: decoding a 100.1 °C pair stored at V0 and V1 #

Inputs. A transmitter is read over Modbus, and its Float32 displays correctly in an external client set to big-endian Float32. The example pair, chosen so you can check every step by hand, is a high word of 17096 (hex 42C8) in the first register and a low word of 13107 (hex 3333) in the second; together they encode a process temperature of 100.1 °C. The high word is stored in V0 and the low word in V1, an even-aligned pair.

Rule. Store the two words consecutively, first word even, in the order the device sends them, then cast the first word with :R. The cast reinterprets the 32 bits as IEEE-754: value = (1 + fraction ÷ 8388608) × 2^(exponent field − 127), negative when the sign bit is set.

Arithmetic. Combine the words high-first: 17096 × 65536 + 13107 = 1,120,403,456 + 13,107 = 1,120,416,563, which is 0x42C83333. The sign bit is 0. The exponent field is 133, so the scale is 2^(133 − 127) = 2^6 = 64. The fraction field is 4,731,699, so the fraction is 4,731,699 ÷ 8,388,608 = 0.5640625. The value is (1 + 0.5640625) × 64 = 1.5640625 × 64 = 100.1.

Result. V0:R displays 100.1 — 100.09999847 before display rounding, the nearest Float32 to 100.1 — with no swap instruction and no arithmetic rung anywhere in the program.

Decision. The pair qualifies for the cast because its first word is even, and the cast alone is the whole fix. The even first word is the make-or-break threshold: the same two words at V5 and V6 fail the cast, and any map that forces an odd first word moves the fix to SUBSCRIBE.

When SUBSCRIBE is the right tool #

Use SUBSCRIBE when the pair cannot be relocated to an even first word, or when byte order, word order or conversion belongs in the acquisition layer rather than in ladder. Define the remote source as the same two registers that produced the correct value in your client, choose a 32-bit floating-point destination, and set the instruction's ordering to reproduce the raw word sequence you recorded. Write the converted result to a real destination, and let this be the only place the order is fixed: correcting it once in communications and again in logic leaves two places to break it. Change one ordering control at a time and compare the raw pair and the converted result after each change. The Do-more help covers both paths — the BRX user manual points to Help topic DMD0309 for casting, and the help file carries the SUBSCRIBE instruction page. PUBLISH is the outbound counterpart when the BRX sends a formatted value to a client.

Prove it before the machine runs on it #

Test at least three stable process points; one plausible reading proves nothing. At each point compare the BRX value against the client configured for the known-working big-endian Float32 interpretation, and confirm the value tracks the process in the right direction without turning negative, huge or nonnumeric. A value wrong at every stable point points at ordering; a value that is right when stable and wild only in motion points at a torn sample. Either way, a swapped pair can display a believable but wrong process value, so do not feed an unverified conversion into alarm or permissive logic. After any tag edit or map change, confirm the first word is still even, and write the first register, the second register, the required ordering, the cast expression and the destination type next to the communications logic. No display-format change repairs a wrong 32-bit pattern. Scaling a correct Float32 to engineering units, such as a 4-20 mA loop, is a separate step covered in scaling Modbus floating point values to 4-20 mA outputs.

Questions asked

Can I build a custom two-word data type and move it into R memory instead of casting?

No. The :R cast is a typed view of storage that already exists, so there is nothing to move, and a numeric move converts each 16-bit word as its own number instead of reinterpreting one 32-bit pattern. Put the two received words in consecutive locations whose first offset is even, then reference that first word with the cast wherever the logic needs a real operand. The cast is the conversion; the storage layout is the only thing you arrange.

My polling tool calls the format big-endian. Does that settle the word order for the PLC?

Not by itself. Software packages label byte order for two-register values differently, so a label that works in one tool is not a specification for the next. What the working display proves is that the two registers hold a usable floating-point pattern. Write down both raw 16-bit values and their register order while the tool shows the correct value, and use that recorded pair as the reference when you set the ordering in the PLC.

Why does the converted value jump to a huge or tiny number only while the process is changing?

The device may update its two registers in separate operations, so the PLC can pair one new word with one stale word — a torn sample that decodes to a wild value. Where the device and instruction support it, read both registers in a single transaction so the pair always comes from the same update. A value that is wrong at every stable point is an ordering problem; a value that is right when stable and wild only in motion is a torn read.

Can SWAPB correct a wrong word order?

Yes, once the raw-word comparison proves the order is wrong. SWAPB begins at the first source location, swaps the bytes and/or words, and stores the result at the first destination location, so it can normalize the pair before the cast. Use it in one place only: fix the order either in the communications setup or in logic, never both, or a correct payload gets swapped back into a believable but wrong value.

What do I use when the BRX sends a Float32 out instead of receiving one?

PUBLISH is the outbound counterpart to SUBSCRIBE: where SUBSCRIBE brings remote registers in with ordering, alignment and conversion, PUBLISH formats a PLC-side value for the registers a client reads. Apply the same discipline — record the raw words the client accepts, change one ordering control at a time, and verify at stable points before the machine depends on the value.

Keep reading

  • Troubleshooting

    Why S7-1500 Modbus_Comm_Load needs MODE 4 for RS485 two-wire

    Set the MODE input of Modbus_Comm_Load to 4 for an RS485 two-wire circuit on an S7-1500 CM PtP. MODE 1 describes a full-duplex four-wire point-to-point circuit, so the load never completes: STATUS briefly shows 16#7001, falls back to 16#7000, DONE stays false and the master or slave block reports 16#8282. Code that ran with MODE 1 on an S7-1200 does not transfer that setting to the 1500 port.

    PLC programming

  • How-to

    How to read Factory I/O REAL and INT tags in CODESYS Modbus TCP

    Factory I/O multiplies each Float sensor value by 100 and sends it as a 16-bit Word, and its Int tags cross as 32-bit values. In CODESYS, receive the Word, convert it to REAL, divide by 100.0, and declare each Int tag as a DInt; BOOL tags pass straight through the Modbus TCP slave mapping you already have.

    PLC programming

  • How-to

    How to run two TwinCAT PLC programs on one laptop

    Merge both PLC projects into one TwinCAT XAE system configuration and activate it once. The XAE assigns each PLC project its own ADS port (851 to the first, 852 to the next by default numbering), and both programs reach RUN on the local runtime. Changing the port in one of two separate XAE projects does not work, because one activation replaces the other.

    PLC programming