6- ModBus
6- ModBus
The Modbus RTU message consists of the address of the SlaveID device, the
function code, and the special data, depending on the function code and the
CRC of the checksum.
MODBUS RTU defines four types of registers, each serving distinct purposes in industrial
automation:
Coils (Discrete outputs): Coils represent binary outputs that can be controlled by the
master device. They have two states: ON (1) and OFF (0). Coils are read and written by
the master, allowing it to control various industrial processes.
Discrete inputs: Discrete inputs provide binary input data to the master device. These
registers are read-only for the master and typically represent the status of sensors or
switches.
Input registers: Input registers store analog data or data received from sensors. These
registers are read-only for the master and provide valuable information about the
external environment.
REGISTER REGISTER
TYPE NAME Symbol
NUMBER ADDRESS
For example, the first register of AO Holding Register has the number 40001,
but its address is 0000.
Each table has its own offset, respectively: 1, 10001, 30001 and 40001.
11 03 00 6B 00 03 76 87
11 03 06 AE 41 56 52 43 40 49 AD
The AE 41 HEX value is 16 bits 1010 1110 0100 0001, which can take a different
value, depending on the type of representation.
The value of register 40108 when combined with register 40109 gives a 32-bit
value.
An example of a representation.
Example in In decimal
View type Value Range
HEX form
-2,147,483,648 to -
32-bit signed integer AE41 5652
2,147,483,647 1,371,449,774
The PDU request specifies the start address of the first DO register and the
subsequent number of required DO values. In the PDU, the DO values are
addressed starting from zero.
The DO values in the response are in one byte and correspond to the value of
the bits.
If less than eight DO values were requested, the remaining bits in the response
will be filled with zeros (in the direction from the low to high byte). Byte
Count The number of bytes further indicates the number of full bytes of data in
the response.
Example of a DO query
11 01 00 13 00 25 0E 84
11 01 05 CD 6B B2 0E 1B 45 E6
The output states of DO 27-20 are shown as the values of the byte CD hex, or in
the binary system 1100 1101.
In register DO 56-52, 5 bits on the right were requested, and the remaining bits
are filled with zeros to the full byte (0001 1011).
Channels - - - DO 56 DO 55 DO 54 DO 53 DO 52
Bits 0 0 0 1 1 0 1 1
Hex 1B
Example of a DI request from the registers from # 10197 to 10218 for the
device's SlaveID address 17. The address of the first register will be 00C4 hex =
196, because the Account is maintained from 0 address.
REQUEST RESPONSE
(Hex) Field name (Hex) Field name
11 Device address 11 Device address
02 Functional code 02 Functional code
00 Address of the first register Hi bytes 03 Number of bytes more
C4 Address of the first register Lo bytes AC Register value DI 10204-10197 (1010 1100)
00 Number of registers Hi bytes DB Register value DI 10212-10205 (1101 1011)
16 Number of registers Lo bytes 35 Register value DI 10218-10213 (0011 0101)
BA Checksum CRC 20 Checksum CRC
A9 Checksum CRC 18 Checksum CRC
REQUEST ANSWER
(Hex) Field name (Hex) Field name
11 Device address 11 Device address
03 Functional code 03 Functional code
00 Address of the first register Hi bytes 06 Number of bytes more
6B Address of the first register Lo bytes AE Register value Hi #40108
00 Number of registers Hi bytes 41 Register value Lo #40108
03 Number of registers Lo bytes 56 Register value Hi #40109
76 Checksum CRC 52 Register value Lo #40109
87 Checksum CRC 43 Register value Hi #40110
40 Register value Lo #40110
49 Checksum CRC
AD Checksum CRC
Example of an AI request from the register # 30009 for the SlaveID of the
device address 17. The address of the first register is 0008 hex = 8, because
Account is maintained from 0 address.
REQUEST RESPONSE
(Hex) Field name (Hex) Field name
11 Device address 11 Device address
04 Functional code 04 Functional code
00 Address of the first register Hi bytes 02 Number of bytes more
08 Address of the first register Lo bytes 00 Register value Hi #30009
00 Number of registers Hi bytes 0A Register value Lo #30009
01 Number of registers Lo bytes F8 Checksum CRC
B2 Checksum CRC F4 Checksum CRC
98 Checksum CRC
Back to contents
An example of a DO record with register # 173 for the SlaveID address of the
device 17. The register address will be 00AC hex = 172, because Account is
maintained from 0 address.
REQUEST RESPONSE
(Hex) Field name (Hex) Field name
11 Device address 11 Device address
05 Functional code 05 Functional code
00 Address of the first register Hi bytes 00 Address of the first register Hi bytes
AC Address of the first register Lo bytes AC Address of the first register Lo bytes
FF Value of Hi bytes FF Value of Hi bytes
00 Value of Lo bytes 00 Value of Lo bytes
4E Checksum CRC 4E Checksum CRC
8B Checksum CRC 8B Checksum CRC
REQUEST RESPONSE
(Hex) Field name (Hex) Field name
11 Device address 11 Device address
06 Functional code 06 Functional code
00 Address of the first register Hi bytes 00 Address of the first register Hi bytes
01 Address of the first register Lo bytes 01 Address of the first register Lo bytes
00 Value of Hi bytes 00 Value of Hi bytes
03 Value of Lo bytes 03 Value of Lo bytes
9A Checksum CRC 9A Checksum CRC
9B Checksum CRC 9B Checksum CRC
REQUEST RESPONSE
(Hex) Field name (Hex) Field name
11 Device address 11 Device address
0F Functional code 0F Functional code
00 Address of the first register Hi bytes 00 Address of the first register Hi bytes
13 Address of the first register Lo bytes 13 Address of the first register Lo bytes
00 Number of registers Hi bytes 00 Number of recorded registers Hi bytes
0A Number of registers Lo bytes 0A Number of recorded registers Lo bytes
02 Number of bytes more 26 Checksum CRC
CD Byte Value DO 27-20 (1100 1101) 99 Checksum CRC
01 Byte Value DO 29-28 (0000 0001)
BF Checksum CRC
0B Checksum CRC
REQUEST RESPONSE
(Hex) Field name (Hex) Field name
11 Device address 11 Device address
10 Functional code 10 Functional code
00 Address of the first register Hi bytes 00 Address of the first register Hi bytes
01 Address of the first register Lo bytes 01 Address of the first register Lo bytes
00 Number of registers Hi bytes 00 Number of recorded registers Hi bytes
02 Number of registers Lo bytes 02 Number of recorded registers Lo bytes
04 Number of bytes more 12 Checksum CRC
00 Value Hi 40002 98 Checksum CRC
0A Value Lo 40002
01 Value Hi 40003
02 Value Lo 40003
C6 Checksum CRC
F0 Checksum CRC
Example:
IT WAS IT BECOME
FUNCTIONAL CODE IN REQUEST Functional error code in response
01 (01 hex) 0000 0001 129 (81 hex) 1000 0001
02 (02 hex) 0000 0010 130 (82 hex) 1000 0010
03 (03 hex) 0000 0011 131 (83 hex) 1000 0011
04 (04 hex) 0000 0100 132 (84 hex) 1000 0100
05 (05 hex) 0000 0101 133 (85 hex) 1000 0101
06 (06 hex) 0000 0110 134 (86 hex) 1000 0110
15 (0F hex) 0000 1111 143 (8F hex) 1000 1111
16 (10 hex) 0001 0000 144 (90 hex) 1001 0000
REQUEST RESPONSE
(Hex) Field name (Hex) Field name
0A Device address 0A Device address
01 Functional code 81 Functional code with changed bit
04 Address of the first register Hi bytes 02 Error code
A1 Address of the first register Lo bytes B0 Checksum CRC
00 Number of registers Hi bytes 53 Checksum CRC
01 Number of registers Lo bytes
AC Checksum CRC
63 Checksum CRC