In this tutorial, you will learn how to communicate with your hardware using Modbus TCP Protocol. If you missed it, check out the last post where we explain the most used bit logic operations and the Timers Operation.
- Siemens TIA Portal
- Radzio Master Simulator
- s7-1200 1214 DC/DC/DC PLC
To create our Modbus connection in TIA Portal we will start for add the MB_Server Block. To do that, you should go to the Instructions menu, select the Communication and Others-Modbus TCP as you can see in Figure .
After that, you can drag and drop this block in Network 1 and start to create the basic control tags as you can see in Figure .
- x_Connect – To enable the connection of Modbus Block;
- x_Disconnect – To disconnect the communication of the Modbus Block;
- x_Error – To verify in your program if the connection was an active error or not;
- s_Status – To check the status of the connection (if it is well made or not, if is sending data…);
As you can see there are more 2 tags that you need to fill in MB_Server Block.
The Connect Tag is a special tag where you will configure the IP Address, the ID, the local port, the interfaceId, the connection type, and if your connection is active or passive.
The MB_Hold_Reg is the data that you will send/receive.
To create the connect tag you should create a new Data Block as you can see in Figure .
Then in this new Data Block, you must have to create the connect tag with a data Type “TCON_IP_v4”. When you create you will notice that will appear some other configurations as you can see in Figure .
The InterfaceId in my case is the port 64 but you can check yours by following the steps in Figure .
The ID of the connection depends on your installation. Each connection should have a different ID. If in your installation, as in mine, is the first hardware connection in Modbus TCP Protocol you can select ID=1.
The ConnectionType value depends on our connection type. In My case I want to make a connection by TCP/IP so, the ConnectionType value should be 11.
The ActiveEstablished Value depends if your connection is active or passive. In My case, the PLC will open the connection and then my PC connects when i want, so the PLC is Passive. To select Passive connection you should give the ActiveEstablished tag the value false.
The RemoteAddress should be the address of the hardware that will connect to the PLC. As in my case, this hardware is my PC, I select the IP of my PC (192.168.1.122).
As my connection is Local, I will just fill the LocalPort tag with port 502. This Port must be equal on your active connection hardware ( in my case is my PC).
After Creating the connect tag you will have to add it in your MB_Server Block. To do that, go to the main, select the Data block you have created, go to details view, and drag and drop the tag to the Connect tag of MB_Server Block as you can see in Figure .
After this step, you should create another data block where you will save the data sent and received between your PLC and your Hardware. To do that you should follow the steps in Figure.
Now you should create a Tag to Transmit between hardware as you see in Figure . To do that you can create a tag named “Data” with a Data Type of “Array[0..9] of Int. It means that inside this tag you will have 10 Integer tags arranged in one array.
After Creating this tag, you have to follow the same steps that you followed to add the connect tag as you can see in Figure .
Download the program to the PLC, and activate the connect tag as you can see in Figure.
All steps are made in Tia Portal, now you will need to follow the next steps where you will configure the Radzio Modbus Simulator.
After opening the Radzio Simulator software you should create a new file and enter in setting menu as you can see in Figure .
Now you have to configure the Modbus TCP communication on the Software side as you can see in Figure .
- Connection: Modbus TCP
- IP Address: 192.168.123 ( The same IP Address of the PLC)
- TCP Port: 502 ( The Same Port you decide on PLC for Local Port)
Select the Length of the message (10 in my case because I choose an array of 10 integers) and then select Holding registers. Now that it’s all made, check the connection by pressing the connect button as you can see in Figure .
On TIA Portal, go to the Data Block you create with your data and select the online visualization. Follow the steps of the Figure  by double clicking on hand nrº 2, select the value you want in nrº 3, update the value on nrº 4, and check if the value you choose appear ins nrº 5.
This is the fifth post on Siemens TIA Portal. You have learned how to create a connection between your PLC and your hardware by Modbus TCP.
If you like this kind of post, if you want to know more about Siemens TIA Portal, or if you have doubts about the Industrial Automation area don’t forget to leave a comment.