Antpact Toolbox
中文
Home › Blog › General › Modbus Address Conversion Tutorial: 40001/30001 vs Offset Mapping So AI-Generated PLC Code Stops Misreading Registers
General

Modbus Address Conversion Tutorial: 40001/30001 vs Offset Mapping So AI-Generated PLC Code Stops Misreading Registers

Why Modbus Address Conversion Keeps Going Wrong

The Modbus protocol splits registers into four areas: coils (0x), discrete inputs (1x), input registers (3x), and holding registers (4x). PLC vendors and SCADA configurators use two notations for the same register: the protocol reference address (starting at 0) and the human-facing logical address (00001, 10001, 30001, 40001).

The single most common mistake when AI generates Modbus polling code is mixing up "40001" with offset 0, or treating offset 0 as 40000. One cell off and you are reading an adjacent or out-of-range register—debugging on the floor for hours without a clue why. In October 2026 Schneider previewed the Modicon M380 ePAC with agentic AI at SPS, Siemens brought its Eigen industrial AI agent to China, and CODESYS teamed with Intel on edge-AI PLC coding; AI-written Modbus programs are now routine, which makes address verification more important than ever.

The 4x/3x/1x/0x Mapping Rules

<ul> <li>0x Coils: logical address starts at 00001; protocol offset = logical − 1</li> <li>1x Discrete Inputs: start at 10001; offset = logical − 10001</li> <li>3x Input Registers: start at 30001; offset = logical − 30001</li> <li>4x Holding Registers: start at 40001; offset = logical − 40001</li> </ul> <p>So "40001" is the 0th holding register in the 4x area. When function code 0x03 reads it, the address field in the PDU is 0x0000; "40002" maps to offset 1, i.e. 0x0001. Conversely, if the AI hands you code that reads the holding register at offset 5, the logical address is 40006.</p>

Three Steps to Verify AI-Generated Addresses Locally

<ol> <li>Identify the area by function code: 0x01/0x05/0x0F → coils (0x); 0x02 → discrete inputs (1x); 0x04 → input registers (3x); 0x03/0x06/0x10 → holding registers (4x).</li> <li>Subtract the base to get the protocol offset: 40001→0, 30001→0, 10001→0.</li> <li>Use AntPact's Modbus address converter(https://antpact.com/modbus/modbus-address/) to convert both ways at once, so you never mistake 40001 for offset 1 by hand.</li> </ol> <p>Everything runs in your browser; address data is never uploaded, meeting the "data stays on-site" compliance expectation of industrial OT.</p>

Hands-On: Verify a Modbus TCP Frame with the Converted Offset

Once you have the AI-generated Modbus TCP poll, drop the converted offset into the PDU and use the Modbus TCP frame parser(https://antpact.com/modbus/modbus-tcp/) to check that the MBAP and function code line up. For RTU, the Modbus RTU frame parser(https://antpact.com/modbus/modbus-rtu/) verifies both the command and its CRC16(https://antpact.com/modbus/modbus-crc/) checksum. Need ASCII mode? The Modbus ASCII parser(https://antpact.com/modbus/modbus-ascii/) handles LRC. Unsure what a function code means? Check the Modbus function code reference(https://antpact.com/modbus/modbus-fc/).

Add Address Conversion to Your Local Toolkit

Whether you are untangling an AI-generated Modbus polling routine or maintaining a legacy PLC tag table by hand, AntPact's Modbus address converter(https://antpact.com/modbus/modbus-address/) maps 40001/30001 against offsets locally. It sits alongside the other parsers, checksums, and function-code tools in the AntPact Modbus toolkit(https://antpact.com/modbus/)—all processed locally, nothing uploaded, ideal for line-side debugging and OT security self-checks.

← Back to blog