惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
博客园_首页
GbyAI
GbyAI
罗磊的独立博客
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
U
Unit 42
V
Visual Studio Blog
F
Fortinet All Blogs
小众软件
小众软件
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
The Cloudflare Blog
T
Tor Project blog
Martin Fowler
Martin Fowler
K
Kaspersky official blog
Scott Helme
Scott Helme
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
D
DataBreaches.Net
博客园 - Franky
阮一峰的网络日志
阮一峰的网络日志
博客园 - 【当耐特】
P
Proofpoint News Feed
N
Netflix TechBlog - Medium
美团技术团队
S
Secure Thoughts
C
Cisco Blogs
M
MIT News - Artificial intelligence
L
Lohrmann on Cybersecurity
T
Tenable Blog
N
News and Events Feed by Topic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Spread Privacy
Spread Privacy
S
Security @ Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
A
Arctic Wolf
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
O
OpenAI News
V
Vulnerabilities – Threatpost

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Why Your Schneider PLC's Float32 Reads 1.4e-41 Instead of 25.5 C
Phil Yeh · 2026-05-05 · via DEV Community

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? The Modbus spec says nothing about the order.

Each PLC vendor decided independently whether to put the high word first
or the low word first. Whether to swap bytes within a word. Whether to
flip everything. The result is four different ways to encode the same
float
, and there's no in-band way to know which one you're getting.

This is why your PLC software shows 25.5°C while your Python script reads
1.4e-41 — same bytes, different decoding order.


The 4 byte orders you'll meet

A 32-bit float 25.5 in IEEE-754 is the byte sequence:

0x41 0xCC 0x00 0x00

Enter fullscreen mode Exit fullscreen mode

Now watch what happens when different PLCs put these 4 bytes into 2 Modbus
registers:

Order Register N Register N+1 Common in
ABCD (big-endian, no swap) 0x41CC 0x0000 Allen-Bradley, ABB, "clean" implementations
CDAB (word-swap) 0x0000 0x41CC Schneider M221/M241, some Siemens
BADC (byte-swap) 0xCC41 0x0000 Rare — some old controllers
DCBA (byte + word swap) 0x0000 0xCC41 Mostly legacy hardware

If you decode bytes in ABCD order when the device sent CDAB, you get
a tiny denormal float (the 1.4e-41 you're seeing), or nan, or inf,
or just nonsense.

Schneider's CDAB (word-swap) is the trap that catches most people.


Code: decode all 4 orders in Python

Pure stdlib, no dependencies. Drop this into your project:

import struct

def decode_float32(reg_high: int, reg_low: int, byte_order: str = "ABCD") -> float:
    """Decode two 16-bit Modbus registers into a float32.

    byte_order:
        ABCD - big-endian, no swap (default IEEE-754)
        CDAB - word-swap (Schneider, some Siemens)
        BADC - byte-swap within each word
        DCBA - byte + word swap
    """
    # Pack the two registers into 4 bytes (big-endian)
    raw = struct.pack(">HH", reg_high, reg_low)

    if byte_order == "ABCD":
        return struct.unpack(">f", raw)[0]
    elif byte_order == "CDAB":
        # Swap the two 16-bit words
        return struct.unpack(">f", raw[2:4] + raw[0:2])[0]
    elif byte_order == "BADC":
        # Swap bytes within each word
        return struct.unpack(">f", raw[1:2] + raw[0:1] + raw[3:4] + raw[2:3])[0]
    elif byte_order == "DCBA":
        # Reverse all 4 bytes
        return struct.unpack(">f", raw[::-1])[0]
    else:
        raise ValueError(f"Unknown byte order: {byte_order}")


# Example: read a value with pymodbus and decode all 4 ways
from pymodbus.client import ModbusTcpClient

client = ModbusTcpClient("192.168.1.10")
client.connect()

response = client.read_holding_registers(address=100, count=2)
reg_high, reg_low = response.registers[0], response.registers[1]

print(f"ABCD: {decode_float32(reg_high, reg_low, 'ABCD')}")
print(f"CDAB: {decode_float32(reg_high, reg_low, 'CDAB')}")
print(f"BADC: {decode_float32(reg_high, reg_low, 'BADC')}")
print(f"DCBA: {decode_float32(reg_high, reg_low, 'DCBA')}")

Enter fullscreen mode Exit fullscreen mode

The trick: print all four when you're integrating a new device. The
one that gives a sensible value (e.g. 25.5 when you know the temperature
is 25.5) tells you the device's encoding. Lock it in for that device.


Real-world examples by vendor

Based on years of integration work, here's what I've seen most often:

  • Schneider M221, M241, M340 → Almost always CDAB (word-swap). This is the #1 source of "my Python script is broken" tickets.
  • Siemens S7-1200, S7-1500 → Depends on how the float is stored. If exposed via Modbus TCP wrapper, often CDAB too.
  • Allen-Bradley CompactLogix → Usually ABCD when exposed through Prosoft Modbus modules. Clean.
  • Mitsubishi FX seriesABCD in most configurations.
  • Delta DVPABCD.
  • Energy meters (Schneider PM5xxx)CDAB typically.
  • VFDs (ABB ACS, Schneider Altivar) → Mixed — always test all 4.

The lesson: never assume. Even within one vendor, different product
lines pick different orders. Always do the "print all 4" test on a new
device.


Common pitfalls

1. Some libraries do the swap silently — and silently wrong

pymodbus's built-in BinaryPayloadDecoder lets you specify
byteorder=Endian.BIG, wordorder=Endian.LITTLE (which is CDAB). But
the API is confusing enough that I've seen people set both to BIG and
spend hours debugging. Decode manually with struct — it's clearer.

2. The "negative number" red flag

If your decoded value is -1.5e+38 when you expect 25.5, you've
almost certainly got the byte order wrong. Single-digit positive
temperatures don't accidentally encode as huge negative numbers under any
normal scaling.

3. int32 has the same problem

This article focuses on float32 because it's the most painful, but all
multi-register types have this issue
. int32, uint32, int64, double —
they all get split across registers and they all need the byte-order
treatment.

4. Some devices store the swap setting in a register

Annoying but real: a few high-end PLCs let the user configure
endianness. Always check the device manual for any "byte order" or "word
order" parameter before running test code.


Wrapping up

The Modbus float32 byte-swap is one of those things that looks like a
bug in your code but is actually a quirk of the protocol's history. Once
you know to test all 4 orders, you can integrate any device in a few
minutes instead of a few hours.

If this saved you time, a ⭐ on my open-source Modbus logger means a lot:
Python-Modbus-Serial-Logger-GUI
it has all 4 decoding modes built in, plus a GUI so you don't need to
keep restarting Python while testing.

If you're using this in production work and want a more polished version
with a CSV recorder and Modbus TCP support, I sell a commercial license
at pokhts.gumroad.com.


I write about industrial Python and protocol internals at
dev.to/philyeh — new article every two
weeks. If you've got a specific PLC integration story you want to read
about, drop a comment.