Menu

1 / 2

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

DEV Community·Phil Yeh·7 months ago
#hxXPujRr
#python#modbus#plc#automation#swap
Reading 0:00
15s threshold

You've connected your Python script to a Schneider M221, requested a holding

register pair where you know the temperature is 25.5°C , and you get back:

1.401298464324817e-45

Enter fullscreen mode

Exit fullscreen mode

Not 25.5. Not even close. Some weird denormal float so small it might as

well be zero.

Welcome to the Modbus float32 byte-swap trap . It's the single most

common reason engineers think pymodbus is broken when it isn't. The fix

is 5 lines of code once you know what's happening — and that's what this

article is about.

Why this happens

The Modbus specification defines registers as 16-bit unsigned integers .

Period. That's it. The spec was written in 1979 and at the time, that's

all anyone needed.

But modern PLCs need to send floats, 32-bit integers, doubles, strings.

The "solution" the industry adopted was: just split the larger value

across multiple 16-bit registers .

The problem?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.