Data Model: Four Data Types

Master the four Modbus data types — coils, discrete inputs, holding registers, and input registers — and how to use the register map

Chapter Objectives

Scenario: Putting the Greenhouse's Physical World into "Lockers"

In the previous chapter we built Ms. Wang's greenhouse network: the gateway is the master and the three devices are slaves. The question now is: where exactly inside the device is slave 1's "temperature 25.6°C" stored? Where is slave 2's "fan switch"? How does the gateway read them out?

Imagine that every Modbus device contains a row of labelled lockers: some lockers have a single slot that fits exactly one "on/off" note (1 bit); some have two slots and can hold a bigger number (16 bits); some are marked "read-only, don't touch", and some can be read and written freely. Modbus specifies that all devices use the same set of locker specifications—this is its data model.

Why It Matters

When working with Modbus devices, 90% of the job is looking up "which address holds which data" in the device manual. Read the wrong locker (type) or the wrong position (address) and at best you get garbage values, at worst you corrupt the device configuration. Once you know these four lockers, every function code is just "which door to open".

Core Concepts: The Four Data Types

TypeEnglishAccessBit widthTypical useGreenhouse example
CoilCoilRead / Write1 bitSwitches, relays, indicator lampsExhaust fan switch, pump switch
Discrete inputDiscrete InputRead-only1 bitLimit switches, door contacts, buttonsDoor/window open-closed state
Holding registerHolding RegisterRead / Write16 bitsSetpoints, analog outputs, configurationHumidity target, temperature limits
Input registerInput RegisterRead-only16 bitsMeasured values, instrument readingsTemperature, humidity, light readings

Memory aid: coils and holding registers "can be changed"; discrete inputs and input registers "can only be viewed". The 1-bit types represent switches, the 16-bit types represent numbers.

Protocol Details and Byte-Level Examples

Reference Number vs Link Address: The Easiest Pair to Confuse

Device manuals often show 5-digit numbers such as 40001 or 30001. These are reference numbers, and the leading digit tells you the type:

But the address actually sent onto the wire counts from 0: reference number 40001 corresponds to link address 0x0000, and 40002 corresponds to 0x0001. The conversion formula is: link address = reference number − 40001 (for holding registers), e.g. 40001 → 0, 40005 → 4 (0x0004).

Big-Endian

A 16-bit value occupies 2 bytes. Modbus specifies that the high byte comes first—this is big-endian. In plain terms: announce the "tens" first, then the "ones". For example, 100 is stored as 00 64 (high byte 0x00, low byte 0x64), not 64 00.

A Paired Temperature Read

The gateway wants to read "temperature" from slave 1 (stored in a holding register; to match what the Lab supports, we use FC 03):

Request—read 1 holding register @0x0000:

■ RTU Address ■ Function Code ■ Data ■ CRC
Slave 1 01
FC 03: Read Holding Registers 03
Starting address 0x0000 00 00
Quantity = 1 00 01
CRC-16 84 0A
ByteValueMeaning
001Slave 1
103Function code: Read Holding Registers
2–300 00Starting address
4–500 01Quantity
6–784 0ACRC-16

Response—the slave returns 2 data bytes 00 64 (100 in decimal):

■ RTU Address ■ Function Code ■ Data ■ CRC
Slave 1 01
FC 03 echoed 03
Byte count = 2 02
Data = 100 (0x0064) 00 64
CRC-16 B9 AF
ByteValueMeaning
001Slave 1
103Function code echoed
202Byte count = 2
3–400 64Data (raw integer 100)
5–6B9 AFCRC-16

If the device manual says "temperature = raw value × 0.1 °C", then 00 64 = 100 → 100 × 0.1 = 10.0 °C. Note: Modbus only transports raw integers; the decimal point is defined by the device manual, not by the protocol.

How 32-Bit Data Is Stored (Plain-Language Version)

What if the temperature has a fractional part and a sign? Industry commonly uses a "scaling factor" (such as ×10 or ×100) to turn decimals into integers; when a larger range or a true floating-point number is needed, two adjacent 16-bit registers are combined into a 32-bit value (high word first). A string is a run of registers, one character per byte. None of these combination rules are defined by Modbus—they are all defined by the device manual. That is exactly why the "register map" exists.

Real-World Applications

Case 1: Register Map of the Greenhouse Devices (Main Storyline)

SlaveTypeReference numberLink addressMeaningConversion
Slave 1 sensorInput register300010x0000Temperature×0.1 °C
Slave 1 sensorInput register300020x0001Humidity×0.1 %
Slave 2 exhaust fanCoil000010x0000Fan switch0=off 1=on
Slave 2 exhaust fanHolding register400010x0000Speed setpoint0–100 %
Slave 3 water pumpCoil000010x0000Pump switch0=off 1=on

Ms. Wang's gateway polls according to this map: read 30001 for temperature, read 00001 for fan state, write 40001 to set the speed.

Case 2: The VFD Side Case

A variable frequency drive (VFD) for a motor in a factory also has a register map: holding register 0x0000 = target speed (RPM), input register 0x0000 = present frequency (0.01 Hz). When the host software "reads 40001" and gets 1500, it knows the motor is running toward 1500 RPM—the same routine as the greenhouse's "read 30001 → 10.0 °C": look up the map first, then convert.

Counter-Example: Using 40001 as an Address

A classic beginner mistake: the manual says "40001 is temperature", so they enter address 40001 in the software. The result is either an "illegal data address" exception or reading a completely unrelated register. Remember: 40001 is a reference number; the link address is 0x0000—in software you normally enter 0 or 0x0000.

Hands-On Lab Guide

  1. Open the Lab page, choose protocol RTU and operation "Read Holding Registers" (FC 03);
  2. Slave address 1, starting address 0x0000, quantity 1;
  3. Copy the generated hex into the "Parse" area and look at the byte-by-byte breakdown; the expected request is 01 03 00 00 00 01 84 0A;
  4. Change the quantity to 2 and watch the request become 01 03 00 00 00 02 C4 0B—read one more register and both the quantity and the CRC change.

Chapter Summary and What's Next

In this chapter you met Modbus's four "lockers": two 1-bit switches (coils and discrete inputs) and two 16-bit numbers (holding registers and input registers). You also learned how to convert a reference number into a link address, and about big-endian ordering.

Next, we learn how to "open the lockers"—using function codes to tell a slave: read the temperature, turn on the fan, write the setpoint.