2-4
UR FAMILY – COMMUNICATIONS GUIDE
MODBUS FUNCTION CODES
CHAPTER 2: MODBUS COMMUNICATION
2
2.2 Modbus function codes
2.2.1 Supported function codes
Modbus officially defines function codes from 1 to 127 though only a small subset is generally needed. The relay supports
some of these functions, as summarized in the following table. Subsequent sections describe each function code.
Table 2-4: Function codes
2.2.2 Read actual values or settings (function code 03/04h)
This function code allows the master to read one or more consecutive data registers (actual values or settings) from a
relay. Data registers are always 16-bit (two-byte) values transmitted with high order byte first. The maximum number of
registers that can be read in a single packet is 125. See the
Reading PMU records section on page 2-11
for the data
registers.
Since some PLC implementations of Modbus only support one of function codes 03h and 04h. The UR interpretation allows
either function code to be used for reading one or more consecutive data registers. The data starting address determines
the type of data being read. Function codes 03h and 04h are therefore identical.
The following table shows the format of the master and slave packets in Modbus RTU. Modbus TCP/IP ADUs have a MBAP
instead of slave address, and CRC is in another stack layer. The example shows a master device requesting three register
values starting at address 4050h from slave device 11h (17 decimal); the slave device responds with the values 40, 300,
and 0 from registers 4050h, 4051h, and 4052h, respectively.
Table 2-5: Master and slave device packet transmission example
Algorithm
1.
FFFF (hex) --> A
2.
0 --> i
3.
0 --> j
4.
Di (+) Alow --> Alow
5.
j + 1 --> j
6.
shr (A)
7.
Is there a carry?
No: go to 8; Yes: G (+) A --> A and continue.
8.
Is j = 8?
No: go to 5; Yes: continue
9.
i + 1 --> i
10.
Is i = N?
No: go to 3; Yes: continue
11.
A --> CRC
Function code
Modbus definition
GE Multilin definition
Hex
Dec
03
3
Read holding registers
Read actual values or settings
04
4
Read holding registers
Read actual values or settings
05
5
Force single coil
Execute operation
06
6
Preset single register
Store single setting
10
16
Preset multiple registers
Store multiple settings
Master transmission
Slave response
Packet format
Example (Hex)
Packet format
Example (Hex)
SLAVE ADDRESS
11
SLAVE ADDRESS
11
FUNCTION CODE
04
FUNCTION CODE
04
DATA STARTING ADDRESS - high
40
BYTE COUNT
06
DATA STARTING ADDRESS - low
50
DATA #1 - high
00