B
B.
Using Modbus/TCP
Modbus Packets consist of a Modbus Header and a Modbus Command. Each packet type is described below.
Modbus Header
Description
Size (byte)
Example
Transaction Identifier Hi
1
0x08
Transaction Identifier Lo
1
0x01
Protocol Identifier Hi
1
0x00
Protocol Identifier Lo
1
0x01
Length
2
0x0006
Unit Identifier
1
0xFF
Modbus Command
Use this chart of standard function codes as a programming reference.…
Code (Hex)
Name
Usage
01
Read Coil Status
Read Discrete Output Bit
02
Read Input Status
Read Discrete Input Bit
03
Read Holding Registers
Read 16-bit register. Used to read integer
or floating point process data
04
Read Input Registers
05
Force Single Coil
Write data to force coil ON/OFF
06
Preset Single Register
Write data in 16-bit integer format
08
Loop-back Diagnosis
Diagnostic testing of the communication port
15
Force Multiple Coils
Write multiple data to force coil ON/OFF
16
Preset Multiple Registers
Write multiple data in 16-bit integer format
Table 5-1 Modbus Function Code
Modbus Function Code Introductions
Function Code 01
Function code 01 is used to read the discrete output’s ON/OFF status of ioPAC 8020 modules in a binary data
format.
Request message format for function code 01:
Command Body
Station
Address
Function
Code
Start Address
High Byte
Start Address
Low Byte
Requested Number of
Coil High Byte
Requested Number
of Coil Low Byte
Example: Read coil number 1 to 8 (address number 00017 to 00024) from ioPAC 8020 Modules
01 01 00 17 00 08
Response message format for function code 01: