Modbus Addressing¶
Understanding Modbus register addressing and conventions.
Register Types¶
| Type | Full Name | Access | Typical Range | Function Codes |
|---|---|---|---|---|
| HR | Holding Register | Read/Write | 40001-49999 | 3, 6, 16 |
| IR | Input Register | Read Only | 30001-39999 | 4 |
| CS | Coil | Read/Write | 00001-09999 | 1, 5, 15 |
| IS | Input Status | Read Only | 10001-19999 | 2 |
Addressing Modes¶
1-Based (Traditional Modbus)¶
Convention: - HR 40001 = PDU address 0 - IR 30001 = PDU address 0 - CS 00001 = PDU address 0 - IS 10001 = PDU address 0
Example: - User enters: 40100 - Gateway translates to PDU: 99
0-Based (Modern/PLCs)¶
Convention: - HR 0 = PDU address 0 - IR 0 = PDU address 0
Example: - User enters: 99 - Gateway uses PDU: 99
Setting: Configure per device with "Zero-Based Addressing" checkbox
Data Types¶
Single Register (16-bit)¶
- Int16: Signed integer (-32768 to 32767)
- UInt16: Unsigned integer (0 to 65535)
- Boolean: True/False (coils)
Multi-Register¶
- Int32: 2 registers, signed 32-bit
- UInt32: 2 registers, unsigned 32-bit
- Float32: 2 registers, IEEE 754 float
- Int64: 4 registers, signed 64-bit
- Float64: 4 registers, IEEE 754 double
- String: Multiple registers, ASCII/UTF-8
Byte Order (Endianness)¶
For multi-register values, configure swap mode:
| Mode | Name | Byte Order | Example (2 regs) |
|---|---|---|---|
| 0 | None | ABCD | Default |
| 1 | Byte swap | BADC | Some PLCs |
| 2 | Word swap | CDAB | Common |
| 3 | Both | DCBA | Less common |
Testing: Use "Poll Once" to verify correct byte order.
Function Codes¶
| Code | Name | Description |
|---|---|---|
| 1 | Read Coils | Read CS (1-2000) |
| 2 | Read Discrete Inputs | Read IS (1-2000) |
| 3 | Read Holding Registers | Read HR (1-125) |
| 4 | Read Input Registers | Read IR (1-125) |
| 5 | Write Single Coil | Write one CS |
| 6 | Write Single Register | Write one HR |
| 15 | Write Multiple Coils | Write many CS |
| 16 | Write Multiple Registers | Write many HR |
Best Practices¶
- Verify addressing mode with device vendor
- Test with Poll Once before production
- Document custom byte orders
- Use register maps from device manual
- Group consecutive addresses