Back to KB
Difficulty
Intermediate
Read Time
4 min

Why Your Schneider PLC's Float32 Reads 1.4e-41 Instead of 25.5 C

By Codcompass TeamΒ·Β·4 min read

Current Situation Analysis

When connecting a Python script to a Schneider M221 (or similar PLC) and requesting a holding register pair known to contain 25.5Β°C, engineers frequently receive a denormalized float like 1.401298464324817e-45. This is not a bug in pymodbus or the Python runtime. It is a deterministic failure caused by the Modbus float32 byte-swap trap.

The root cause lies in the Modbus specification's architectural limitation: registers are strictly defined as 16-bit unsigned integers. The 1979 spec contains zero guidance on how to encode larger data types (float32, int32, double, strings). The industry workaround was to split 32-bit values across two consecutive 16-bit registers. However, vendors independently decided:

  • Whether to place the high word or low word first
  • Whether to swap bytes within each 16-bit word
  • Whether to reverse the entire 4-byte sequence

This results in four distinct encoding permutations for the same IEEE-754 float. Traditional integration methods fail because they assume a universal big-endian (ABCD) layout or rely on library defaults that silently mismatch the target PLC's firmware. The result is deterministic garbage: denormals, NaN, Inf, or massive negative values.

WOW Moment: Key Findings

Experimental validation across common industrial controllers reveals that decoding order directly dictates data integrity. Using the IEEE-754 representation of 25.5 (0x41 0xCC 0x00 0x00), the following matrix demonstrates the impact of byte-order mismatch:

ApproachDecoded ValueError SymptomTypical Vendors
ABCD (Big-Endian, No Swap)25.5None (Correct)Allen-Bradley, ABB, Delta, Clean Implementations
CDAB (Word-Swap)1.4e-45 / NaNDenormal/InvalidSchneider M221/M241, Siemens S7 (Modbus w

πŸŽ‰ Mid-Year Sale β€” Unlock Full Article

Base plan from just $4.99/mo or $49/yr

Sign in to read the full article and unlock all 635+ tutorials.

Sign In / Register β€” Start Free Trial

7-day free trial Β· Cancel anytime Β· 30-day money-back