Modbus Functions
General Description
The Modbus protocol offers a number of functions that are used to read or write data over the Modbus network. The Modbus protocol also offers diagnostic and network-management functions.
Only the Modbus functions handled by the ATSE are described here.
Read Functions
The following read functions are available:
Function Code |
Subfunction Code |
Name |
Description |
---|---|---|---|
3 (0x03) |
– |
Read holding registers |
Read n output or internal registers |
43 (0x2B) |
14 (0x0E) |
Read device identification |
Read the identification data of the server |
43 (0x2B) |
15 (0x0F) |
Get date and time |
Read the date and time of the server |
Read Register Example
The following table shows how to read the SI voltage in register 2000. The address of register 2000 is 2000-1=1999 = 0x07CF. The Modbus address of the Modbus server is 47 = 0x2F.
Client Request |
Server Reply |
||
---|---|---|---|
Field Name |
Example |
Field Name |
Example |
Modbus server address |
0x2F |
Modbus server address |
0x2F |
Function code |
0x03 |
Function code |
0x03 |
Address of the register to read (MSB) |
0x07 |
Data length in bytes |
0x02 |
Address of the register to read (LSB) |
0xCF |
Register value (MSB) |
0x02 |
Number of registers (MSB) |
0x00 |
Register value (LSB) |
0x2B |
Number of registers (LSB) |
0x01 |
CRC (MSB) |
0xXX |
CRC (MSB) |
0xXX |
CRC (LSB) |
0xXX |
CRC (LSB) |
0xXX |
– |
Get Date and Time Example
The following table shows how to get the date and time of a Modbus server. The Modbus address of the Modbus server is 47 = 0x2F.
client Request |
Server Reply |
||
---|---|---|---|
Field Name |
Example |
Field Name |
Example |
Modbus server address |
0x2F |
Modbus server address |
0x2F |
Function code |
0x2B |
Function code |
0x2B |
Subfunction code |
0x0F |
Subfunction code |
0x0F |
Reserved |
0x00 |
Reserved |
0x00 |
– |
– |
Date and time |
Refer to the DATETIME data type |
Set Date and Time Example
The following table shows how to set date and time of a Modbus server. The Modbus address of the Modbus server is 47 = 0x2F, the new date is October 2, 2014, and the new time is 2:32:03:500 p.m.
client Request |
Server Reply |
||
---|---|---|---|
Field Name |
Example |
Field Name |
Example |
Modbus server address |
0x2F |
Modbus server address |
0x2F |
Function code |
0x2B |
Function code |
0x2B |
Subfunction code |
0x10 |
Subfunction code |
0x10 |
Reserved1 |
0x00 |
Reserved1 |
0x00 |
Not used |
0x00 |
Not used |
0x00 |
Year = 2014 |
0x0E |
Year = 2014 |
0x0E |
Month = October |
0x0A |
Month = October |
0x0A |
Day Of Month = 2 |
0x02 |
Day Of Month = 2 |
0x02 |
Hour = 14 |
0x0E |
Hour = 14 |
0x0E |
Minutes = 32 |
0x20 |
Minutes = 32 |
0x20 |
3 sec. 500 ms |
0x0DAC |
3 sec. 502 ms |
0x0DAE |
The normal response is an echo of the request, returned after the date-time has been updated in the remote device. If the date-time structure content is not consistent with a true date-time (that is, an invalid date-time), the value returned in the Date-Time field is set to 0 by the device.
In case of 24 VDC power loss, the date and time of the Modbus servers without battery is not refreshed anymore. It is therefore mandatory to set date and time for all Modbus servers after recovering the 24 VDC power supply.
Furthermore, due to the clock drift of each Modbus server, it is mandatory to set date and time for all Modbus servers periodically. Recommended period is at least every 15 minutes.
Scattered Holding Register Read Function
The scattered holding register read function is available:
Function |
Subfunction Code |
Name |
Description |
---|---|---|---|
100 (0x64) |
4 (0x04) |
Read scattered holding register |
Read n non-contiguous registers |
The scattered holding register read function enables the user to:
-
avoid reading a large block of contiguous registers when only few registers are needed
-
avoid multiple use of functions 3 and 4 in order to read non-contiguous registers
Read Scattered Holding Register Example
The following table shows how to read the addresses of the register 1022 (address 0x03FD) and register 1100 (address 0x044B) of a Modbus server. The Modbus address of the Modbus server is 47 = 0x2F.
Client Request |
Server Reply |
||
---|---|---|---|
Field Name |
Example |
Field Name |
Example |
Modbus server address |
0x2F |
Modbus server address |
0x2F |
Function code |
0x64 |
Function code |
0x64 |
Data length in bytes |
0x06 |
Data length in bytes |
0x06 |
Subfunction code |
0x04 |
Subfunction code |
0x04 |
Transmission number(1) |
0xXX |
Transmission number(1) |
0xXX |
Address of first register to read (MSB) |
0x03 |
Value of the first register read (MSB) |
0x12 |
Address of first register to read (LSB) |
0xFD |
Value of the first register read (LSB) |
0x0A |
Address of second register to read (MSB) |
0x04 |
Value of the second register read (MSB) |
0x74 |
Address of second register to read (LSB) |
0x4B |
Value of the second register read (LSB) |
0x0C |
CRC (MSB) |
0xXX |
CRC (MSB) |
0xXX |
CRC (LSB) |
0xXX |
CRC (LSB) |
0xXX |
(1) The client gives the transmission number in the request. The server returns the same number in the reply. |
Write Functions
The following write functions are available:
Function Code |
Subfunction Code |
Name |
Description |
---|---|---|---|
6 (0x06) |
– |
Preset single register |
Write 1 register |
16 (0x10) |
– |
Preset multiple registers |
Write n registers |
43 (0x2B) |
16 (0x10) |
Set date and time |
Write the date and time of the server |