The Modbus RTU protocol is implemented in the AC500 processor modules. Modbus is a master-slave (client-server) protocol. The client sends a request to the server and receives the responses.
The Modbus operating mode of a serial interface is set in the PLC configuration ⮫ “Configuring Modbus RTU on serial interface”.
To use the PLC as a Modbus RTU client two possible programming methods can be used:
-
ModRtuMast
-
ModRtuToken with Read/Write function blocks
ModRtuMast
With this method the Modbus client function block ModRtuMast is used to program all read and/or write jobs in a sequence. If more than one ModRtuMast function block is used, e.g. for several sever connections, the sequence must take care that only one of those ModRtuMast function blocks is active at a time.
A summary of the function codes that are supported for Modbus RTU communication with an AC500 PLC is given in the application example ⮫ Modbus RTU and function block ModRtuMast.
ModRtuToken with Read/Write function blocks
With this method the function block ModRtuToken
is used along with ModRtuRead
and/or ModRtuWrite
and/or ModRtuReadWrite23
.
Instead of programming a sequence a simple connection via structure variables between the function blocks is necessary to ensure the sequencial functionality of Modbus RTU.
A sample project for Modbus client and server in order to enable Modbus RTU communication with an AC500 PLC is given in the application example ⮫ Modbus RTU and function block ModRtuMast.
To use Modbus RTU protocol on an AC500-eCo PLC, the processor module must be equipped with an option board for COMx serial communication TA5141-RS232I, TA5142-RS485 or TA5142-RS485I option board. The type of the option board adapter must be selected according to the type of physical serial interface needed.
According to the CPU type, up to 3 option boards for COMx serial communication can be used⮫ “Attach an option board for COMx serial communication”.
Modbus RTU can be used for communication between an AC500-eCo PLC and a control panel. The connection principle is described using the CP604 control panel as an example: ⮫ CP604 connection via Modbus RTU.
Modbus client
In this operating mode, the telegram traffic with the server(s) is handled via the function block ModRtuMast.
This function block sends Modbus request telegrams to the server(s) via the set interface and receives Modbus response telegrams from the server(s) via this interface.
The Modbus blocks transferred by the server contain the following information:
-
Modbus address of the interrogated server (1 byte)
-
Function code that defines the request of the client (1 byte)
-
Data to be exchanged (n bytes)
-
CRC16 control code (2 bytes)
Modbus server
In this operating mode, no function block is required for Modbus communication. Sending and receiving Modbus telegrams is performed automatically.
The AC500 CPUs process the following Modbus operation codes:
Function code |
Description |
|
---|---|---|
DEC |
HEX |
|
01 or 02 |
01 or 02 |
Read n bits |
03 or 04 |
03 or 04 |
Read n words |
05 |
05 |
Write one bit (encoded in one word) |
06 |
06 |
Write one word |
15 |
0F |
Write n bits (encoded in one byte) |
16 |
10 |
Write n words |
22 |
16 |
Mask write |
23 |
17 |
Read/write multiple words in one telegram |
The following restrictions apply to the length of the data to be sent:
Function code |
Max. length |
|
---|---|---|
DEC |
HEX |
|
01 or 02 |
01 or 02 |
2000 bits |
03 or 04 |
03 or 04 |
125 words / 62 double words |
05 |
05 |
1 bit |
06 |
06 |
1 word |
15 |
0F |
2000 bits |
16 |
10 |
123 words / 61 double words |
22 |
16 |
Write: 1 word |
23 |
17 |
Read: 125 words / 62 double words Write: 121 words / 60 double words |