0% found this document useful (0 votes)
32 views38 pages

ModbusTCP Codesys Siemens

This application note provides guidance on establishing Modbus TCP/IP communication between Siemens and Codesys PLCs. It details the necessary configurations for both controllers, including the setup of Function Blocks in Siemens PLC to facilitate communication. The document also includes step-by-step instructions for project creation, device configuration, and testing of the communication link.

Uploaded by

jmarcano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views38 pages

ModbusTCP Codesys Siemens

This application note provides guidance on establishing Modbus TCP/IP communication between Siemens and Codesys PLCs. It details the necessary configurations for both controllers, including the setup of Function Blocks in Siemens PLC to facilitate communication. The document also includes step-by-step instructions for project creation, device configuration, and testing of the communication link.

Uploaded by

jmarcano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Application Note

Modbus TCP/IP Communication


between Siemens and Codesys Con-
troller.

This application note helps the user to establish Modbus com- TCP/IP
munication between Siemens PLC and Codesys PLC.
It explains the configurations needed in both the controllers in
order to achieve Modbus communication between them.
It also explains the Function Blocks needed in Siemens PLC side
to establish Modbus communication.

100253
Title .................................................... Modbus TCP/IP Communication between Siemens and Codesys Controller
Version ............................................................................................................................................................. 1.10
Document no. .............................................................................................................................................. 100253
Original .................................................................................................................................................................en
Author ............................................................................................................................................................. Festo

Last saved ............................................................................................................................................ 22.07.2019

Copyright Notice
This documentation is the intellectual property of Festo AG & Co. KG, which also has the exclusive copyright. Any
modification of the content, duplication or reprinting of this documentation as well as distribution to third par-
ties can only be made with the express consent of Festo AG & Co. KG.
Festo AG & Co KG reserves the right to make modifications to this document in whole or in part. All brand and
product names are trademarks or registered trademarks of their respective owners.

Legal Notice
Hardware, software, operating systems and drivers may only be used for the applications described and only in
conjunction with components recommended by Festo AG & Co. KG.
Festo AG & Co. KG does not accept any liability for damages arising from the use of any incorrect or incomplete
information contained in this documentation or any information missing therefrom.
Defects resulting from the improper handling of devices and modules are excluded from the warranty.
The data and information specified in this document should not be used for the implementation of safety func-
tions relating to the protection of personnel and machinery.
No liability is accepted for claims for damages arising from a failure or functional defect. In other respects, the
regulations with regard to liability from the terms and conditions of delivery, payment and use of software of
Festo AG & Co. KG, which can be found at www.festo.com and can be supplied on request, shall apply.
All data contained in this document do not represent guaranteed specifications, particularly with regard to func-
tionality, condition or quality, in the legal sense.
The information in this document serves only as basic information for the implementation of a specific, hypo-
thetical application and is in no way intended as a substitute for the operating instructions of the respective
manufacturers and the design and testing of the respective application by the user.
The operating instructions for Festo products can be found at http://www.festo.com/sp.
Users of this document (application note) must verify that all functions described here also work correctly in the
application. By reading this document and adhering to the specifications contained therein, users are also solely
responsible for their own application.

 (Festo AG & CO. KG, D-73726 Esslingen, 2019)


Internet: http://www.festo.com
E-Mail: [email protected]
Table of contents
1 Components/Software used ....................................................................................................................... 5

2 Application description ............................................................................................................................... 6


2.1 Topology ..................................................................................................................................................... 6

3 Configuration of Festo PLC in CODESYS ..................................................................................................... 7


3.1 Creating a new project in Codesys. .............................................................................................................. 7
3.2 Adding a new gateway to the project. ......................................................................................................... 9
3.3 Detecting the actual hardware configuration of the controller. ................................................................. 11
3.4 Adding a Ethernet device to the project..................................................................................................... 13
3.5 Configuring Network Parameters of Ethernet Device. ................................................................................ 14

4 Configuration of Modbus TCP between Festo and Siemens Controller ................................................... 15


4.1 Festo Controller as Modbus TCP Master in Codesys. ................................................................................. 15
4.1.1 Adding the Modbus TCP Master. .................................................................................................. 15
4.1.2 Adding the Modbus TCP Slave. .................................................................................................... 16
4.1.3 Configuring Network Parameters of Modbus TCP Slave. ............................................................. 18
4.1.4 Configuring Modbus TCP Slave channels. ................................................................................... 18
4.2 Siemens PLC as Modbus TCP Slave. .......................................................................................................... 21
4.2.1 Integrating MB_SERVER Function Block to Program Blocks. ........................................................ 22
4.3 Testing modbus communication. .............................................................................................................. 24
4.4 Festo PLC as Modbus TCP Slave. .............................................................................................................. 26
4.4.1 Adding the Modbus TCP Slave in Codesys. .................................................................................. 26
4.4.2 Configuring the Modbus TCP Slave. ............................................................................................. 27
4.5 Configuring Siemens PLC as Modbus TCP Master. .................................................................................... 28
4.5.1 Network configuration of the ethernet port of Siemens controller. .............................................. 28
4.5.2 MB_CLIENT Function Block .......................................................................................................... 29
4.5.3 Configuration of MB_CLIENT Function Block ................................................................................ 33
4.6 Downloading and Testing. ......................................................................................................................... 37
Components/Software used

1 Components/Software used

Type/Name Version Software/Firmware Date of manufacture

Codesys V 3.5 SP10 Patch 4 --


Siemens TIA Portal V 15 --

Table 1.1: Components/Software used

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 5 of 38
Application description

2 Application description

This document explain how to communicate between Siemens PLC and Codesys controller using Modbus TCP/IP
protocol.

The application note has the description for the following:


• Siemens PLC Setup in TIA Portal.
• Festo Controller setup in Codesys.
• Modbus configurations of Festo controller in codesys.
• Modbus configuration in TIA Portal using the Function Blocks.
• Communication testing with examples.

2.1 Topology

When we want to communicate between Siemens PLC and Festo PLC the following topology must be followed.

NOTE
• The IP address of the Siemens PLC, Festo PLC and the PC used for programming the PLC must
be in the same range.

Page 6 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Festo PLC in CODESYS

3 Configuration of Festo PLC in CODESYS

3.1 Creating a new project in Codesys.

NOTE
Any Festo controller which supports Modbus TCP protocol can be used for this integration with
Siemens controller via Modbus TCP Protocol. In our case we will be using CPX-E-CEC-C1-PN con-
troller.

1. Open the Codesys software in your system.

2. Click on New Project to create a new project.

3. The project creation wizard appears as shown below.

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 7 of 38
Configuration of Festo PLC in CODESYS

4. Select CPX-E-CEC project. Give a name to the project, select the folder where the project has to be saved.
Click OK to create the project.

NOTE
• Depending on the controller type being used, select other package from the available pack-
ages.
• All the Festo Controllers available support Modbus TCP/IP communication.

NOTE
• Modbus communication is helpful in those cases where the controller chosen for the project
doesnt have a profinet module.
• In our application note we have considered CPX-E-CEC-C1-PN . The Procedere remains same for
all other Festo PLC‘s

5. Since we are using CPX-E-CEC-C1-PN as our controller, select it as the device for our project.

6. Click Ok to add the device to the project.

Page 8 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Festo PLC in CODESYS

7. Once the device has been added the project view looks as shown below.

3.2 Adding a new gateway to the project.

In order to establish any TCP communication in Codesys controller first we have to create and setup a gate-
way(network path ) for the controller.

1. Double click on the Device to open the device settings.


2. Select communication settings to open Network settings.

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 9 of 38
Configuration of Festo PLC in CODESYS

3. Click On Add Gateway.

4. Following Pop up is displayed. Click OK to add gateway.

5. The newly created gateway looks like below.

6. Double click on the Gateway to scan the network to see if any controller is connected .

Page 10 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Festo PLC in CODESYS

7. If any controller is found it will be detected as shown below image.

8. The network path is made active by double clicking on the controller found in the network.
The controller found in network gets bolded once the network path is set active.

3.3 Detecting the actual hardware configuration of the controller.

The actual hardware configuration of the controller can be found automatically by searching the controller con-
nected in the network.

1. Double click on the CPX-E-System as shown below.

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 11 of 38
Configuration of Festo PLC in CODESYS

2. The following view will be displayed .

3. Click on Actual Configuration to detect the actual hardware configuration of the controller connected in the
network.

4. Once the scan is started and if the controller is connected in the network then the detected hardware con-
figurations will be as shown below.

Page 12 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Festo PLC in CODESYS

3.4 Adding a Ethernet device to the project.

1. For Modbus TCP/IP communication first an ethernet device has to be added.

Right click on the Device. In this case CPX-E-CEC-C1-PN and then select Add Device .

2. Select the ethernet device .

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 13 of 38
Configuration of Festo PLC in CODESYS

3. Now the device tree will look as shown below.

3.5 Configuring Network Parameters of Ethernet Device.

NOTE
• The IP address of the Festo controller and Siemens PLC must be in the same range for success-
ful communication to be established.

1. Double click on the ethernet device >>> General to open the network parameters properties.

2. Choosing the ethernet interface for the device. The added network parameters must be chosen as the net-
work interface for the device.
3. Select the configured network adapter from the available options.

Page 14 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Modbus TCP between Festo and Siemens Controller

4 Configuration of Modbus TCP between Festo and Siemens Controller

There are 2 options available in Modbus communication.


• Festo Controller as Modbus TCP Master and Siemens PLC as Modbus TCP Slave.
• Festo Controller as Modbus TCP Slave and Siemens PLC as Modbus TCP Master.

4.1 Festo Controller as Modbus TCP Master in Codesys.


• In this case the Festo controller will act as the Modbus TCP master.
• Siemens controller will act as the Modbus TCP Slave.
• Festo controller being the master will request ( sending Function Codes) for reading and writing the
Holding registers, coils of the Siemens controller.

4.1.1 Adding the Modbus TCP Master.

1. Add the Modbus TCP master for the ethernet device.


Right Click on ethernet device >> Add Device.

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 15 of 38
Configuration of Modbus TCP between Festo and Siemens Controller

2. Select the Modbus TCP master.

3. Click Add Device after selecting the Modbus TCP Master.

4.1.2 Adding the Modbus TCP Slave.

In this case Siemens PLC is the Modbus slave.


1. Right Click on Modbus TCP Master >>> Add Device.

Page 16 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Modbus TCP between Festo and Siemens Controller

2. Select Modbus TCP Slave .

3. Click Add Device to finish adding the Modbus TCP Slave.


4. Once the master and slave has been added the device tree will look as shown below.

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 17 of 38
Configuration of Modbus TCP between Festo and Siemens Controller

4.1.3 Configuring Network Parameters of Modbus TCP Slave.

1. Double click Modbus TCP Slave to view its properties.

2. In the properties of the Modbus TCP Slave , under General configure the Network parameters of the slave(
Siemens PLC).

NOTE
• Port number of the slave(Siemens controller) is in general 502.

4.1.4 Configuring Modbus TCP Slave channels.

The slave channels have to be configured with appropriate Function Codes , Modbus addresses and the data
length to be communicated with the master.

Modbus TCP channels can be configured to perform following functions on the slave:
• Reading Coils
• Writing coils
• Reading the holding registers
• Writing holding registers of the slave
• Reading input registers of the slave
• Reading discrete inputs of the slave.

Page 18 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Modbus TCP between Festo and Siemens Controller

1. Double click on Modbus TCP Slave to open the properties view.


2. Select Modbus Slave Channel option.

3. Click Add channel to create a new Modbus Slave Channel as shown in above image. Once you start to add
new channel the following popup will be displayed.

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 19 of 38
Configuration of Modbus TCP between Festo and Siemens Controller

The following options are available when we want to configure a Modbus slave channel .

Name - Enter a name for the slave channel.

Access Type : This is the function code which is used for accessing the memory locations of the slave.
The following function codes are available.

Read Register – Offset : This is the starting address of the memory location of the slave from where the data
has to be read.

Read Register – Length : This is the number of words which has to be read from the offset mentioned.

Write Register – Offset : This is the starting address of the memory location of the slave to where the data has
to be written.

Write Register – Length : This is the number of words which has to be written from the offset mentioned.

4. Once the needed Function code is chosen the modbus slave channel will look as shown below.

Example1 : Reading from the holding registers of Siemens Controller

The above example is used for reading 10 words starting at the address 0000 from the holding registers .

NOTE
• If one more function is needed then create one more channel.

Example 2 : Writing to the holding Registers of Siemens Controller

In the above example 20 words starting from the address 0000 will be written to the siemens controller.

5. Select the option Modbus TCP Slave I/O Mapping to view the configured IO mapping .

Page 20 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Modbus TCP between Festo and Siemens Controller

4.2 Siemens PLC as Modbus TCP Slave.

In order to configure the Siemens PLC as Modbus TCP Slave we have to use MB_SERVER function block.
The MB_SERVER will have the following schematic look.

INPUT DATA
NAME DATA TYPE DESCRIPTION

DISCONNECT BOOL 0 – A passive connection is estab-


lished when there is no communica-
tion.
1 – Initialization of the connection
termination.
MB_HOLD_REG VARIANT Pointer to the Modbus holding reg-
ister of the "MB_SERVER" instruc-
tion.MB_HOLD_REG must always
reference a memory area that is
larger than two bytes.

The holding register contains the


values that may be accessed by a
Modbus client using the Modbus
functions 3 (read), 6 (write), 16
(multiple write) and 23 (reading and
writing in one job).

As the holding register, use either a


global data block with optimized
access or the memory area of the
bit memories.
CONNECT VARIANT Pointer to TCON_IP_v4 structure.
Refer Table 4.3 for the description
of this structure.

Table 4.1: INPUT DATA OF THE MB_SERVER Function Block

OUTPUT DATA
NAME DATA TYPE DESCRIPTION

NDR BOOL 0 – No new data


1 – New data written by Modbus Cli-
ent
DR BOOL 0 – No data read
1 – Data read from Modbus client
ERROR BOOL 0 – No error
1 – Error in modbus operation.
STATUS WORD Detailed status information of the
instruction

Table 4.2: Output Data of the MB_SLAVE Function Block

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 21 of 38
Configuration of Modbus TCP between Festo and Siemens Controller

TCON_IP_v4 Structure

Table 4.3: TCON_IP_v4 data structure.

4.2.1 Integrating MB_SERVER Function Block to Program Blocks.

1. Create a Global Data Block .


2. Add the variables in the Global Data Block as shown in the below image.

Page 22 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Modbus TCP between Festo and Siemens Controller

Important values to be given correctly to the elements of TCON_IP_v4 structure:


• Interface ID : This is the hardware ID of the local interface of the Siemens PLC. To this variable the hard-
ware ID value can be given a default value.

• ID : This value must be different if the slave is communicating with different number of masters at a
time. If its communicating with only one master then its value is 1.
• Remote address : This is the IP address of the master with which communication has to be established.

3. Call the MB_SERVER function block and assign the appropriate parameters.

In the above example 40 words starting at the memory address M1000 is used for Modbus communication.

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 23 of 38
Configuration of Modbus TCP between Festo and Siemens Controller

4.3 Testing modbus communication.

1. Create a watch table mapping the modbus holding registers considered in the program.

2. Download the program to the PLC.

3. After downloading is over, Go Online.

4. Go to the watch table created and monitor online values.

Example : Write 20 holding registers of siemens controller starting at the address 0X0000.

• At the codesys side force values to the configured Modbus TCP slave channels .

Page 24 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Modbus TCP between Festo and Siemens Controller

• Now open the watch table in TIA portal and observe that the 20 holding registers of siemens PLC have
been written with the above values from the Modbus master ( Festo PLC).

Example : Reading 20 holding registers of siemens controller starting at the address 0X0000.

• When the function code configured in codesys for reading holding registers of siemens controller is exe-
cuted the words are read as shown below.

• The data written to the Siemens PLC holding registers are properly read back as shown in above exam-
ple.

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 25 of 38
Configuration of Modbus TCP between Festo and Siemens Controller

4.4 Festo PLC as Modbus TCP Slave.


• In this case the Festo controller acts as the Modbus TCP Slave.
• Siemens controller acts as the Modbus master and will send request(Function Codes) for reading and
writing the holding registers , coils of the Festo controller.

4.4.1 Adding the Modbus TCP Slave in Codesys.

1. Right click on the Ethernet device and select Add device.

2. Select Modbus TCP Slave device.

3. Click Add Device to finish adding the Modbus TCP slave device.

Page 26 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Modbus TCP between Festo and Siemens Controller

4. After the slave device is added the device tree will look as shown below.

4.4.2 Configuring the Modbus TCP Slave.

1. Double click the added Modbus TCP Slave to open its settings.

2. Go to General to do configuration of Slave.

3. The following are the parameters to be configured:

• Slave Port : This the network port of Slave ( in this case Codesys controller).
• Unit ID : The slave ID . The same Unit ID value must be given when configuring Modbus communication
at Siemens side in TIA Portal.
• Holding Registers: The number of holding registers at the slave device configured and available for the
Master for reading and writing.
• Input Registers: The number of input registers at the slave device configured and available for the
Master for reading .
• Start Addresses : This is the address from where the Coils, discrete inputs, holding registers and input
registers will start.

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 27 of 38
Configuration of Modbus TCP between Festo and Siemens Controller

4.5 Configuring Siemens PLC as Modbus TCP Master.


NOTE
• Any Siemens PLC having profinet port and supporting Modbus TCP protocol can be used for
this integration with Festo controller.
• We have considered S7-1200 as an example to establish Modbus TCP communication with
Festo controller.

Once a new projected is created and the hardware configurations have been done in TIA Portal, the next job is to
do the network configurations of the PLC.

4.5.1 Network configuration of the ethernet port of Siemens controller.


1. Double click on the Device configuration to view the configurations of the PLC.

2. Double click on the Profinet Interface to open the Ethernet settings .

Page 28 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Modbus TCP between Festo and Siemens Controller

3. Go to Ethernet Addresses to do the network configurations of the PLC.

NOTE
• The IP address of Siemens and Festo PLC must be in same range.

4.5.2 MB_CLIENT Function Block


MB_CLIENT Function Block is used for configuring Siemens controller as Modbus TCP Master.
The below image shows the schematic representation of the Function Block.

INPUT DATA
Name Data Type Description

REQ BOOL 1 – As Long as REQ =1 the instruc-


tion sends communication re-
quests.
0 – No communication requests is
sent to the slave device.
DISCONNECT BOOL 0 – Establish communication con-
nection to the slave device.
1 – Disconnect the communication
connection.
MB_MODE USINT This is the modbus function code
used for reading or writing data to
the slave memory address.
Refer Table 4.5 for the values to be
given for this input.

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 29 of 38
Configuration of Modbus TCP between Festo and Siemens Controller

Name Data Type Description


MB_DATA_ADDR UDINT This is the starting address at the
slave device from where data has to
be accessed by the master.
Refer Table 4.5 for the values to be
given for this input.
MB_DATA_LEN UINT Number of words to be read or writ-
ten at the slave device.
CONNECT TCON_IPV4 Structure Refer Table 4.7 for detailed descrip-
tion of TCON_IPV4 structure
MB_DATA_PTR VARIANT Pointer to a data buffer for the data
to be received from the Modbus
server or to be sent to the Modbus
server.

Table 4.4: Input Data of the MB_CLIENT Function Block

MB_MODE, MB_DATA_ADDR, MB_DATA_LEN Parameters

These 3 parameters are co-related with each other. Proper values must be given in order to read or write to spe-
cific memory areas of the slave device.

The below table shows the values to be given for these parameters.

Table 4.5: MB_MODE, MB_DATA_ADDR and MB_DATA_LEN parameters

Page 30 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Modbus TCP between Festo and Siemens Controller

OUTPUT DATA
NAME DATA TYPE DESCRIPTION

DONE BOOL 1 – Last modbus job is completed


without errors
BUSY BOOL 0 – Modbus request in process
1 – Modbus request is being pro-
cessed
ERROR BOOL 0 – No error
1 – Error occured. The cause of the
error is indicated by status parame-
ter.
STATUS WORD Detailed status information of the
instruction.
Refer Table 4.8.1 , 4.8.2 and 4.8.3
to get detailed description.

Table 4.6: Output Data of MB_CLIENT FB

TCON_IPV4 Structure
The connect parameter is of the type TCON_IPV4 structure. Th below table describes this structure in detail.

Table 4.7: TCON_IPV4 structure

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 31 of 38
Configuration of Modbus TCP between Festo and Siemens Controller

ERROR STATUS

Table 4.8.1 Error Status

Table 4.8.2 Error Status

Page 32 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Modbus TCP between Festo and Siemens Controller

Table 4.8.3 Error Status

4.5.3 Configuration of MB_CLIENT Function Block


1. Drag and drop the MB_CLIENT Function Block to the program block.

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 33 of 38
Configuration of Modbus TCP between Festo and Siemens Controller

2. Create a Global data block .

• Double click on Add New Block . Select Data Block to create a global data block.
• Create a variable of the structure TCON_IPV4.
• Create variables for monitoring the status of the instruction execution.
The Global Data Block will have the following elements:

3. Assign Proper values to the input parameters of the FB which are needed to configure siemens PLC as
Modbus TCP Master.

In our example the FB was given the following values to implement Siemens Controller as Modbus TCP Master:

Example 1: Writing 10 words to the holding registers of the slave.

• Toggle the value of the variable DataBlock.ReqWrite to start sending Modbus requests to the slave de-
vice.

Page 34 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Modbus TCP between Festo and Siemens Controller

Important Values to be observed:


Name Value Reason

MB_MODE 116 This is the function code for writing


to holding registers of the slave.
MB_DATA_ADDR 0 The starting address of the slave
holding register (festo controller)to
where data has to be written.
MB_DATA_LEN 20 The number of words to be written
MB_DATA_PTR P#M1000.0 WORD 20 This is the memory address in Sie-
mens controller from where data is
sent to the slave or data is recieved
from the slave.

Table 4.6: Values given to input parameters of FB

TCON Structure values


The TCON structure has been given the following values.

Example 2: Reading 10 words from the holding registers of the slave.

MB_MODE has the value 103 as the function code for reading the holding registers is 103.
• Toggle the value of the variable DataBlock.ReqRead to start sending Modbus requests to the slave de-
vice.

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 35 of 38
Configuration of Modbus TCP between Festo and Siemens Controller

NOTE
• Always seperate the addresses considered for reading and writing data from the modbus slave.
• This ensures that data read and written do not overlap with each other.
• This is the reason in Example 1 we have considered 20 words from the address M1000 TO 1038
for writing data to modbus slave.
• In example 2 for reading 20 words from modbus slave we have considered from the address
M1040 to 1078.

4. Create a watch table as shown below. Map the addresses considered for writing data to the Modbus slave
during the configuration of MB_CLIENT function block.

5. Create a watch table as shown below. Map the addresses considered for reading data from the Modbus
slave during the configuration of MB_CLIENT function block.

Page 36 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10
Configuration of Modbus TCP between Festo and Siemens Controller

4.6 Downloading and Testing.


1. Download both the Siemens and Festo projects to the respective controllers.
2. Go Online.

Example 1: Writing 20 words to the holding registers of Festo PLC.


20 words are written to the holding registers of Festo PLC using MB_CLIENT by using the function code 116.
Data from the address M1000 to 1038 is considered for writing to the Modbus slave.

TIA portal online data.

Codesys Online values.


20 words written from Siemens PLC properly read in the codesys controller.

Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10 Page 37 of 38
Configuration of Modbus TCP between Festo and Siemens Controller

Example2 : The data which was written to the holding registers are read back using the function code 103.
The data is read back to the address starting from M1040 to 1078

Page 38 of 38 Application Note – Modbus TCP/IP Communication between Siemens and Codesys Controller – 1.10

You might also like