
- 32 -
4.1 Modbus Code Composition and Analysis
Modbus adapter can be used as client, also can be used as server as shown in Figure 4.1 Modbus TCP receiving
mechanism.
Modbus answer PDUn
Modbus answer PDUi
Modbus request PDUn
Modbus answer PDU1
Modbus request PDUi
Modbus request PDU1
ACK K+1
SYK,ACK J+1
SYN J
close(fd2)
send(fd2)
send(fd2)
recv(fd2)
send(fd2)
recv(fd2)
recv(fd2)
fd2=accept(fd1)
listen(fd1)
bind(fd1,n)
fd1=socket()
recv(fd)
recv(fd)
send(fd)
send(fd)
close(fd)
recv(fd)
connect(fd,server,502)
send(fd)
bind(fd,n)
fd=socket()
Figure 4.1 Modbus TCP Receiving and Sending Mechanism
Modbus function code as shown in 4.1.
Table 4.1 Function code
Function code
Name of function
Function
0x03
Read hold register
Continuous reading
0x10
Write hold register
Continuous writing
4.1.1 Modbus RTU Code Composition
Modbus protocol defines a simple protocol data unit [PDU] which has nothing to do with basic communication, the
Modbus protocol mapping of specific bus or network is able to introduce some additional fields on the application data unit
[ADU], as shown in Figure 4.2.
ADU
PDU
CRC check (CRC16)
Data
Function code
Additional address
Figure 4.2 General Modbus frame data
4 Air Conditioner Monitoring