This course explains the steps to create PLC tags and enable OPCUA communication between the Simumatik Gateway and PLCSIM Advanced or the physical PLC in a local network. This will allow you to run the code programed in TIA Portal against a Simumatik system.
Versions of the programs are: – TIA Portal V16.0 – PLCSIM Advanced V3.0
In this example the data that will be transfered is:
‘inputs’: A PLC input byte addressed to %IB10.
‘outputs’: A PLC output byte addressed to %QB6.
The PLC chosen for this example is:
Short designation: CPU 1512C-1 PN
Article number: 6ES7 512-1CK00-0AB0
Firmware version: V2.8
The chosen system in Simumatik for this example is “PLC Tutorial 5: Turning Conveyor”.
TIA Portal Project Configuration
The first step is to create a project in TIA Portal and configure the hardware. In this tutorial we are going to use the 1512C-1 PN PLC.
Some configuration needs to be done in TIA Portal in order to enable OPCUA features. In the project tree, right click on the title of the project, and select “properties”.
In the “Protection” tab of the pop-up window, enable the option “Support simulation during block compilation”
In the project tree, right click on the PLC, and select “Properties”
In the structure on the left, you can find the I/O modules added previously, click on I/O addresses for each module and set the process image of inputs and outputs to none in both modules. Thus, you have to set “none” in 4 different squares. Remember to do this in every I/O module you have in the PLC.
Select “OPC UA” in the structure on the left, then click “Server” and enable the option “Activate OPC UA server”.
In the structure on the left, scroll down until the end where you will find the “Runtime licenses” tab, click on “OPC UA” and select the type of purchased license as “Medium”.
IO communication (optional)
In order to achieve a better response from the changes in the inputs and outputs you can change the following parameters:
PLC / Properties / OPC UA / Server / Options / Subscriptions
- Minimum sampling interval: 100 ms.
- Minimum publishing interval: 500 ms.
PLC / Properties / Profinet interface / Advanced options / Real time settings / IO communication
- Send clock: 0.5 ms
The “PLC 8DIO” component in Simumatik has an I/O module of 1 byte (0-7) for the inputs called “inputs” and an I/O module of 1 byte (0-7) for the outputs called “outputs”. In the “port” tab, the addresses of the inputs and outputs are listed. For example in this system, the sensor 2 is in the bit 1 of the inputs module.
Thus, in the “device configuration” tab, 2 I/O modules should be added to the PLC, one for the inputs and the other for the outputs as it is shown in the images below.
Open the tag table and declare the variables ‘inputs’ and ‘outputs’ in the corresponding addresses. Then, individual signals can be declared to be used in the program, each one properly mapped according to the connections in the model:
- The addresses of I/O list must be equal in the hardware (I/O modules)
PLC SIM ADVANCED CONFIGURATION
This section goes through the steps to be performed in the PLCSIM Advanced simulator. If you are using a physical CPU you can skip on to “Simumatik Settings”.
Create an instance
First, you have to know the IP of your PLC in TIA Portal, go to the PLC properties panel and click on “PROFINET interface [X1]”/“Ethernet addresses” and there you have all the data needed. In our case the IP address is 192.168.0.1 and the subnet mask 255.255.255.
Open PLCSIM Advanced and configure it as:
- PLCSIM Virtual Eth. Adapter. If you can´t do it, NPF may have to be started on the command line. Open Command Prompt as administrator and write “net start npf”.
- TPC/IP communication with:
- Instance name: random name
- IP Address: the same IP you have in the PLC in TIA Portal, in our case is 192.168.0.1
- Subnet mask: 255.255.255.0
- PLC type: The type of your PLC, in our case is CPU 1500
- CLICK START
After this, a yellow light will be activated.
IP Address Setting
An appropriate IP address must be assigned to that virtual Ethernet adapter. To do so, click on the Windows symbol and go to “settings” and click on “Network & Internet”
Next, click on “Network and Sharing Center”
Click on “Change adapter settings”
Look for the “Siemens PLCSIM Virtual Adapter”. In the “Properties” of this network, access the “Internet Protocol version 4 (TCP/IPv4)” and assign an IP address of the same range as the IP address of the PLC in TIA Portal and PLCSIM Advanced (it means that the IP Address differs in the last digit, for example 192.168.0.2) and set the subnet mask to 255.255.255.0.
Download to device
Select the PLC and compile its program, as shown below in the icon “1”.
Now, the project will be transferred (not simulated) to the PLC (using the “2” icon, next to the previous). In the pop-up window shown below, select “Siemens PLCSIM Virtual Ethernet Adapter” and start search. Select the PLC and load the program.
After this, a green light will be activated in PLCSIM Advanced. You might need to manually set the PLC in RUN mode to get the green light.
Let’s make sure that the connection to Simumatik is working properly. Start by loading the “PLC Tutorial 5: Turning conveyor” system. Then make sure that the Gateway is connected by pressing the “Connect Gateway” icon in the toolbar. For information about how to configure the gateway, please refer to our Gateway installation guide.
Select the PLC component (in the “Control” assembly), and change the url in setup_params so that it refers to the IP address that we configured in PLCSIM Advanced (192.168.0.1 in our case). Make sure that the driver_type is set to opcua_client.
Now all you need to do is press Play to start the emulation, and the status of the PLC should be set to Running. In the image below, a simple program makes the turning conveyor rotate back and forth.
Here is an image showing the ladder diagram, if you want to try the same thing.
All connections are already set up in Simumatik so at this point you can create the program in TIA Portal, download it to the PLC instance, and see it run in the Simumatik workspace.
Run the model
Included in the system assets is a TIA Portal v16 project archive containing a program that is ready to run the tutorial system. Open in i TIA Portal v16 and download to the PLCSIM Advanced instance. The model will then run the system like below, so that small boxes goes to conveyor 4 turns to the right and big boxes coninues straight forward.
Close the PLC instance
Once the simulation is finished, PLCSIM Advanced can be closed by following these steps:
“Turn off” the instance, acting on the button “1” shown below, then the light will switch to grey.
“Remove” the instance, acting on the button “2”.
Otherwise, the IP address of the instance will remain registered and can give problems in future simulations with other addresses.