Documente Academic
Documente Profesional
Documente Cultură
Modbus_V2_04 (RTU)
Documentation for
PHOENIX CONTACT function blocks
PHOENIX CONTACT GmbH & Co. KG
Flachsmarktstraße 8
32825 Blomberg, Germany
Table of contents
1 Block versions/Change notes ........................................................................................10
2 Release .........................................................................................................................10
3 Function block list ..........................................................................................................11
3.1 Modbus ..................................................................................................................11
3.2 Serial Driver ...........................................................................................................12
4 Introduction ...................................................................................................................13
4.1 General ..................................................................................................................13
4.2 Modbus RTU ..........................................................................................................13
4.3 Block sequence ......................................................................................................14
4.3.1 Master functionality .........................................................................................14
4.3.2 Inline adapter ..................................................................................................15
5 Modbus function blocks .................................................................................................16
5.1 MB_RTU_Master block description ........................................................................16
5.1.1 Block data .......................................................................................................16
5.1.2 Block call .........................................................................................................16
5.1.3 Input parameters .............................................................................................17
5.1.4 Output parameters ..........................................................................................17
5.1.5 Input and output parameters ...........................................................................18
5.1.6 Diagnostics .....................................................................................................18
5.2 Supported Modbus function codes .........................................................................19
5.3 MB_RTU_FC1 block description ............................................................................20
5.3.1 Block data .......................................................................................................20
5.3.2 Block call .........................................................................................................20
5.3.3 Input parameters .............................................................................................21
5.3.4 Output parameters ..........................................................................................21
5.3.5 Input and output parameters ...........................................................................22
5.3.6 Diagnostics .....................................................................................................22
5.4 MB_RTU_FC2 block description ............................................................................23
5.4.1 Block data .......................................................................................................23
5.4.2 Block call .........................................................................................................23
5.4.3 Input parameters .............................................................................................24
5.4.4 Output parameters ..........................................................................................24
5.4.5 Input and output parameters ...........................................................................25
5.4.6 Diagnostics .....................................................................................................25
5.5 MB_RTU_FC3 block description ............................................................................26
2 Release
The direct specification of the data width on the input parameter wDatawidth of the
MB_IL_RSUNI_TRNSP_V1_00 function block is only possible for the IB IL RS UNI module
FW later 1.00.
TOP
3.1 Modbus
TOP
TOP
4 Introduction
4.1 General
Modbus is a communication protocol used for serial communication. It is a master/slave
protocol. Only one master is connected to the bus at a time. In addition, one or more slaves
(247, maximum) are connected to the same serial bus.
Modbus communication is always initiated by the master. The master sends a request, then
the slave specified in the request responds. It is possible to send a request to all slaves
(broadcast).
The slaves will never transmit data without receiving a request from the master. In addition,
the slaves do not communicate with each other. The master initiates only one Modbus
transaction at a time.
There are four data types stored in a Modbus device memory: discrete inputs (bits), coils
(bits), holding registers (16-bit registers), and input registers (16-bit registers).
Each byte is sent in an 11-bit frame, in which a start bit, stop bit, and parity bit are added.
TOP
TOP
This block controls the requests of the FC blocks and sends the Modbus request to the
Modbus network via the connected serial interface. The response is analyzed in this block
and forwarded to the requesting block.
Diagnostic information on the Modbus requests is displayed at the respective FC block.
Input parameters
Important: The function of the Auto CRC calculation from the AXL F RS UNI module with the
HW/FW 01/1.00 can be used up to a data length of 17 bytes in the Modbus protocol!
(Section: Startup instructions 'Serial driver Axioline')
Output parameters
5.1.6 Diagnostics
wDiagCode Meaning
0000hex Block is not activated.
8000hex Block is active and operating without errors.
The diagnostics shown on the block are described in section Modbus diagnostics.
The block shows also the diagnostics of the serial driver blocks.
TOP
Using this block, the request is configured and sent. Input parameters are specified for each
function code.
All FC blocks that communicate with the master (MB_RTU_Master_V2_00) also have to be
connected via the same parameter udtMBData.
Input parameters
Output parameters
5.3.6 Diagnostics
The diagnostics shown on the block are described in section Modbus diagnostics.
TOP
Input parameters
Output parameters
5.4.6 Diagnostics
The diagnostics shown on the block are described in section Modbus diagnostics.
TOP
Input parameters
Output parameters
5.5.6 Diagnostics
The diagnostics shown on the block are described in section Modbus diagnostics.
TOP
Input parameters
Output parameters
5.6.6 Diagnostics
The diagnostics shown on the block are described in section Modbus diagnostics.
TOP
Input parameters
Output parameters
5.7.6 Diagnostics
The diagnostics shown on the block are described in section Modbus diagnostics.
TOP
This function block writes a register into the memory of a Modbus slave.
Input parameters
Output parameters
5.8.6 Diagnostics
The diagnostics shown on the block are described in section Modbus diagnostics.
TOP
This function block writes multiple bits into the memory of a Modbus slave.
Input parameters
Output parameters
5.9.6 Diagnostics
The diagnostics shown on the block are described in section Modbus diagnostics.
TOP
This function block writes multiple registers into the memory of a Modbus slave.
Input parameters
Output parameters
5.10.6 Diagnostics
The diagnostics shown on the block are described in section Modbus diagnostics.
TOP
This function block writes or reads multiple bits in or from the memory of a Modbus slave.
Input parameters
Output parameters
5.11.6 Diagnostics
The diagnostics shown on the block are described in section Modbus diagnostics.
TOP
Using this block, the request is configured and sent. Details of requests vary depending on
the required function code.
The block should have the same parameter udtMBData of the MB_RTU485_Master_V1_xx
block.
The supported function codes are FC 1, 2, 3, 4, 5, 6, 15, 16, and 23.
It is possible to have more than one instance in the same program.
Further information on the configuration of the request parameter can be found in
Appendix A (Sending requests with MB_RTU_FCx_V2_00).
TOP
Input parameters
Output parameters
5.12.6 Diagnostics
The diagnostics shown on the block are described in section Modbus diagnostics.
TOP
If there is an error, this block shows the diagnostics of the master block as a text in German.
The source code of the block can be read and modified. To show the diagnostic messages in
other languages, copy the block and translate the diagnostic text into the desired language.
The text output (strDiagInfo) is limited to 80 characters.
Output parameters
TOP
If there is an error, this block shows the diagnostics of the master block as a text in English.
The source code of the block can be read and modified. To show the diagnostic messages in
other languages, copy the block and translate the diagnostic text into the desired language.
The text output (strDiagInfo) is limited to 80 characters.
Output parameters
TOP
This block configures the controller as the Modbus slave. The slave contains data fields that
can be retrieved in a Modbus network. The function codes 1, 2, 3, 4, 5, 6, 15, and 16 are
supported. A slave can be connected to only one serial interface.
Input parameters
Output parameters
5.15.6 Diagnostics
wDiagCode Meaning
0000hex Block is not activated.
8000hex Block is active and operating without errors.
The block shows the diagnostics of the serial driver blocks. (Section: Diagnostics
MB_AXL_RS_UNI_REC and MB_AXL_RS_UNI_SND).
TOP
The diagnostics contains diagnostic codes on the FC blocks of the library. Modbus errors are
indicated at the respective FC block and need to be reset there. Thus the communication in a
Modbus network is not disturbed by an error in a request to a slave. An error at the FC block
is deleted by a reset of the send input or by renewed activation of the block.
Modbus exception codes are sent by the respective slave and contain messages specific for
Modbus.
DiagCode Meaning
0000hex Block is not active
8000hex Block is active
8300hex Block executes a service.
C100hex Error during configuration (displayed on the FC block)
AddDiagCode Meaning
0001hex Slave address is outside the valid range
0002hex Number of the requested data amount invalid (iDataCount)
C110hex Error in the Modbus (displayed on the FC block)
AddDiagCode Meaning
0001hex Timeout on master block
0002hex Checksum (CRC) invalid
0003hex Function code invalid
0004hex Modbus response invalid
C120hex Modbus Exception Code (shown at the FC block)
AddDiagCode Meaning
0001hex Exception Code 1 (Illegal Function)
0002hex Exception Code 2 (Illegal Data Address)
0003hex Exception Code 3 (Illegal Data Value)
0004hex Exception Code 4 (Server Device Failure)
0005hex Exception Code 5 (Acknowledge)
0006hex Exception Code 6 (Server Device Busy)
0008hex Exception Code 8 (Memory Parity Error)
000Ahex Exception Code 10 (Gateway Path Unavailable)
000Bhex Exception Code 11 (Gateway Target Device Failed To Respond)
These diagnostic codes, as well as xError, are reset by a falling edge of xActivate or
xSendRequest on an FC block.
The block also shows the diagnostics of the master block and thus shows the serial drive
block. These errors need to be reset deactivating the affected blocks. (Section: Diagnostics
MB_AXL_RS_UNI_REC and MB_AXL_RS_UNI_SND).
TOP
This function block is used to implement a Modbus Master for the specified module type.
Accordingly the function blocks are connected inside. The required parameters have to be
parameterized on this function block. The associated parameter description refers to the
description of the included function blocks.
Input parameters
Output parameters
This function block is used to implement a Modbus Master for the specified module type.
Accordingly the function blocks are connected inside. The required parameters have to be
parameterized on this function block. The associated parameter description refers to the
description of the included function blocks.
Input parameters
Output parameters
This function block is used to implement a Modbus Master for the specified module type.
Accordingly the function blocks are connected inside. The required parameters have to be
parameterized on this function block. The associated parameter description refers to the
description of the included function blocks.
Input parameters
Output parameters
This function block is used to implement a Modbus Master for the specified module type.
Accordingly the function blocks are connected inside. The required parameters have to be
parameterized on this function block. The associated parameter description refers to the
description of the included function blocks.
Input parameters
Output parameters
This function block is used to implement a Modbus Master for the specified module type.
Accordingly the function blocks are connected inside. The required parameters have to be
parameterized on this function block. The associated parameter description refers to the
description of the included function blocks.
Input parameters
Output parameters
This function block is used to implement a Modbus Master for the specified module type.
Accordingly the function blocks are connected inside. The required parameters have to be
parameterized on this function block. The associated parameter description refers to the
description of the included function blocks.
Input parameters
Output parameters
Output parameters
This function block is used to implement a Modbus Slave for the specified module type.
Accordingly the function blocks are connected inside. The required parameters have to be
parameterized on this function block. The associated parameter description refers to the
description of the included function blocks.
Input parameters
Output parameters
This function block is used to implement a Modbus Slave for the specified module type.
Accordingly the function blocks are connected inside. The required parameters have to be
parameterized on this function block. The associated parameter description refers to the
description of the included function blocks.
Input parameters
Output parameters
This function block is used to implement a Modbus Slave for the specified module type.
Accordingly the function blocks are connected inside. The required parameters have to be
parameterized on this function block. The associated parameter description refers to the
description of the included function blocks.
Input parameters
Output parameters
This function block is used to implement a Modbus Slave for the specified module type.
Accordingly the function blocks are connected inside. The required parameters have to be
parameterized on this function block. The associated parameter description refers to the
description of the included function blocks.
Input parameters
Output parameters
This function block is used to implement a Modbus Slave for the specified module type.
Accordingly the function blocks are connected inside. The required parameters have to be
parameterized on this function block. The associated parameter description refers to the
description of the included function blocks.
Input parameters
Output parameters
This function block is used to implement a Modbus Slave for the specified module type.
Accordingly the function blocks are connected inside. The required parameters have to be
parameterized on this function block. The associated parameter description refers to the
description of the included function blocks.
Input parameters
Output parameters
Output parameters
This block adapts, in connection with the MB_Serial_Out, serial communication blocks from
the library ComSerial (Sendbuffer more than 257 byte) for Inline modules with the the
Modbus master from this library. Connect the outputs with the inputs of the serial driver
block.
Output parameters
TOP
This block adapts, in connection with the MB_Serial_In_V2_10, serial communication blocks
from the library ComSerial (Sendbuffer more than 257 byte) for Inline modules with the
Modbus master from this library. Connect the inputs with the outputs of the serial driver
block.
Input parameters
TOP
This block runs the receiving operations via the AXL F RS UNI 1H module.
The process data width for serial communication is 20 bytes. Of this, 17 bytes are reserved
for the user data.
Input parameters
Output parameters
6.15.6 Diagnostics
wDiagCode Meaning
0000hex Block is not activated.
8000hex Block is active and operating without errors.
C030hex Error when receiving.
wAddDiagCode Meaning
0010hex Timeout when receiving.
0030hex uiRcvLength is larger than the memory available in the receive
buffer
0040hex uiRcvLength <> 0 for end-to-end protocol.
0060hex Communication error when receiving.
C040hex Error in intermediate storage.
wAddDiagCode Meaning
0010hex Timeout in intermediate storage.
TOP
This block runs the sending operations via the AXL F RS UNI 1H module.
The process data width for serial communication is 20 bytes. Of this, 17 bytes are reserved
for the user data.
Input parameters
Output parameters
6.16.6 Diagnostics
wDiagCode Meaning
0000hex Block is not activated.
8000hex Block is active and operating without errors.
C020hex Error when sending
wAddDiagCode Meaning
0020hex Maximum size exceeded when sending.
0060hex Communication error when sending.
C040hex Error in intermediate storage.
wAddDiagCode Meaning
0010hex Timeout in intermediate storage.
TOP
Input parameters
Output parameters
6.17.6 Diagnostics
DiagCode Meaning
0000hex Block is not activated
8000hex Block is active and operating without errors
C010hex Incorrect terminal type connected
AddDiagCode AddDiagCode
FFFFhex FFFFhex
C020hex Incorrect parameter
AddDiagCode AddDiagCode
0010hex 0010hex
0020hex 0020hex
0030hex 0030hex
0040hex 0040hex
0050hex 0050hex
C030hex AddDiagCode
0010hex 0010hex
0020hex 0020hex
0030hex 0030hex
0040hex 0040hex
Error when Error when receiving
receiving
C040hex AddDiagCode
0010hex 0010hex
0020hex 0020hex
0030hex 0030hex
0040hex 0040hex
3964R protocol 3964R protocol error
error
C050hex AddDiagCode
0010hex 0010hex
0020hex 0020hex
Block is not Block is not activated
activated
This function block is used for parameterization of transparent mode. The parameters are
transferred over the output udtPara to the function block of specified function module.
Input parameter
Output parameters
TOP
Input parameters
Output parameters
6.19.6 Diagnostics
DiagCode Meaning
0000hex Block not active
8000hex Block is active and operating without errors
C010hex Incorrect terminal type connected
AddDiagCode Meaning
00nnhex Read terminal type
FFFFhex Terminal is not responding
C020hex Incorrect parameter
AddDiagCode Meaning
0010hex Baud rate
0020hex Data width
0030hex Protocol
0040hex Terminal configuration error
C030hex Error when sending
AddDiagCode Meaning
0010hex Timeout when sending
0020hex Maximum size when sending exceeded
0030hex uiSendLength too large
C040hex Error when receiving
AddDiagCode Meaning
0010hex Timeout when receiving
0020hex Maximum size when receiving exceeded
0030hex uiRcvLength too large
0040hex uiRcvLength <> 0 for the end-to-end, 3964R, and dual buffer
protocols
C050hex 3964R protocol error
AddDiagCode Meaning
0010hex Error when sending a 3964R telegram
0020hex Error when receiving a 3964R telegram
This function block is used for parameterization of transparent mode. The parameters are
transferred over the output udtPara to the function block of specified function module.
Input parameters
Output parameters
TOP
This function block is used to implement the specified module type. This function block is
available for different process data length.
Block name Process data length Data length for sending and reading
MB_ILRSUNI07 7 words 11 byte
MB_ILRSUNI15 15 words 27 byte
MB_ILRSUNI31 31 words 59 byte
Input parameters
Output parameters
6.21.6 Diagnostics
wDiagCode Meaning
0000hex Block is not activated
8000hex Block is active and operating without errors
C010hex Incorrect parameters
wAddDiagCode Meaning
0010hex Baud rate
0020hex Data width
0030hex Protocol
0040hex Interface
0050hex Terminal configuration error
0060hex Communication error
C020hex Error when sending
wAddDiagCode Meaning
0010hex Timeout when sending
0020hex Maximum size exceeded when sending
0060hex Communication error when sending
C030hex Error when receiving
wAddDiagCode Meaning
0010hex Timeout when receiving
0030hex uiRcvLength is larger than the field available for receipt.
0040hex uiRcvLength <> 0 for end-to-end protocol
0060hex Communication error when receiving
This function block is used for parameterization of transparent mode. The parameters are
transferred over the output udtPara to the function block of specified function module.
Input parameters
Input parameters
Output parameters
TOP
7 Startup instructions
7.1 Master or slave with integrated serial driver
The function blocks MB_IL_x_Master and MB_IL_x_Slave merge the serial drivers and the
Modbus slave or master. This „shells” are used for easy implementation of Inline function
modules as Modbus master or slave.
It is not necessary to integrate the ComSerial library. The serial driver function blocks are
already added to this library
The following communication protocols are used for the Modbus protocol:
Transparent: If the transparent protocol is used, serial data is transmitted through the
terminal in the same format it was received from the serial interface or the bus side. The
sending FIFO (first-in, first-out memory) can store 1023 bytes (1 kbyte) and the receiving
FIFO can store 4096 bytes (4 kbytes). The CRC needs to be calculated here by the master
FB.
Modbus RTU: The Modbus RTU protocol functions like the transparent protocol. The data
buffer can store only 340 bytes. This protocol supports only the master function in Modbus.
In this case, the CRC is generated automatically and checked automatically when a
message is received. The data is transferred without CRC bytes to the serial driver and is
also received without CRC bytes.
(Refer to data sheet AXL F RS UNI 1H – 2688666)
Release: The function of the Auto CRC calculation from the AXL F RS UNI module with the
HW/FW 01/1.00 can be used up to a data length of 17 bytes in the Modbus protocol.
Execution order: To process the blocks optimally and for fast Modbus communication, the
serial block for receiving has to be placed at the start of the program and the serial block for
sending has to be placed at the end of the program. In between them, the master block is
inserted, followed by the FC block.
Creating structures: The blocks of the serial interface and the Modbus master have to be
connected with each other via the same structure. The Modbus master as well as the FC
blocks are also connected with each other via a structure.(Section 1.4.1)
Instantiation: A master block may by connected to only one serial driver (here: udtSerialIF).
For a second instance, a second serial interface needs to be implemented. Every Modbus
FC can be instantiated multiple times and connected multiple times with the same Modbus
master via udtMbData.
TOP
This figure shows the cyclical sending of a Modbus message. Two FC blocks send to a slave
in alternation. Errors of a request are shown on the respective slave block.
TOP
The connection of an Inline interface is illustrated here. The blocks of the ComSerial library
are instantiated and connected with the adapter blocks. The parametrization of the serial
interface is done in the PC Worx worksheet by variables, differently than with Axioline in the
startup parametrization.
In addition to the serial interface, master and FC blocks are inserted. The execution order is
not specified.
TOP
The slave block is connected just like the master block to the serial driver via the structure
udtSerialIF.
TOP
TOP
TOP
9 FAQ
9.1 Interval between requests
The Modbus slaves need different times for the processing of requests. The time interval
between multiple requests must be adjusted to the slowest slave, in order to avoid
overlapping of received telegrams.
9.2 Cycle time and PROFINET update time for inputs and outputs
The task cycle time and the PROFINET update time for inputs and outputs should be
adjusted to each other. Generally, the PROFINET update time should be faster than the task
cycle time.
Example : task cycle time: 10 ms PROFINET update time: 8 ms
Bad example : task cycle time: 5 ms PROFINET update time: 32 ms