Join us today!
TwinCAT OPC UA Server - Ignition OPC UA Client
OPC UA (Open Platform Communications United Architecture) is a very common data exchange standard for industrial communication (machine-to-machine or PC-to-machine) and it is used widely in the automation industry. In this tutorial, we will set the TwinCAT 3 as an OPC UA Server and Ignition HMI as an OPC UA Client.
In order to use the OPC UA features in TwinCAT 3, you would need to install the TF6100|TwinCAT 3 OPC UA package. I would suggest installing all the tools available under the software and tools section.
Setting up TwinCAT OPC UA Server:
After installing TF6100, create a TwinCAT 3 project and add the TF6100 license in your project.
Create a struct in your project and name it as ST_OPCUA :
TYPE ST_OPCUA : STRUCT nMyNumber : INT; bEnable : BOOL; sMessage : STRING; END_STRUCT END_TYPE
In the MAIN program, add the following code:
PROGRAM MAIN VAR {attribute 'OPC.UA.DA':='1'} // Enables a variable for OPC UA {attribute 'OPC.UA.DA.StructuredType':='1'} //Enables StructuredType for a STRUCT or a function block stOPCUA : ST_OPCUA; {attribute 'OPC.UA.DA' := '1'} {attribute 'OPC.UA.DA.Access' := '1'} // 0 = none, 1 = read-only, 2 = write access only, 3 = read and write access (default if no tag is used) nCounter : INT; {attribute 'OPC.UA.DA' := '1'} bStart : BOOL; {attribute 'OPC.UA.DA' := '1'} {attribute 'OPC.UA.DA.Description' := 'My Test Integer Array'} //Sets a text for the OPC UA attribute "Description". aMyNumbers : ARRAY[1..5] OF INT; END_VAR
IF bStart THEN nCounter := nCounter + 1; END_IF
{attribute 'OPC.UA.DA' := '1'} enables the OPC UA access of the variable when data access device type is selected as 'Filtered'. We will explain this more about this later.
Double click on 'PLC' and go to Settings. Check the TMC File option. From the TF6100 manual:
By default, the TwinCAT OPC UA Server establishes a connection with the first PLC runtime on the local system and uses the corresponding symbol file to build the namespace. To make the symbol file available, activate the download of the symbol file in the settings of the PLC project.
Now we will add a Connectivity project into our solution. Right click on your solution, select add , then New Project.
Selet TwinCAT Connectivity and then the empty TwinCAT Connectivity Project option. Give your project a name and click OK.
Right click on the TwinCAT Connectivity project and add a new item.
Select the TwinCAT OPC UA Server Project option, name it and click OK.
Double click on TwinCAT OPC UA Server Project1 and go to UA EndPoints tab. We can configure the OPC UA server endpoints here.
After you are done with the settings, build your solution, activate the configuration and log in the PLC.
Enable the 'TwinCAT OPC UA Configurator' tool.
In this tool, select 'Edit list' to add a server.
Click Add Server and select an endpoint using the dropdown menu and click OK. We selected the first option(None,none) for this tutorial.
Select the endpoint and click OK.
Right click on 'Data Access' and select 'Add Device Type' .
Enter your PLC port number and click Create.
You can change these settings anytime in the properties section of the data access device.
In the device type section, you will see the TwinCAT 3 PLC (TMC) - Filtered option selected. If this option selected, you will need to add the {attribute 'OPC.UA.DA' := '1'} attribute for the variables which you want to use for the OPC communication. Otherwise, they won't be accessible. If you would like all variables to be available for the OPC UA communication, select 'TwinCAT 3 PLC (TMC)' - All option.
Click Connect to the Server. Since this is the first time we are connecting the OPC UA Server, it will ask us to initialize it. You can assign a username and password. We used username: user , password: user .
Server will restart after setting up the username and password. Click Connect to server again after a few seconds. Type the username(user) and password(user) and click OK.
Now we can see the server status.
Setting up Ignition OPC UA Client:
If you don't have Ignition installed already, you can download it here. You can open the Ignition gateway on your web browsing by typing localhost:8088/web .
On the Ignition gateway, select Config then OPC Connections.
Select the Create new OPC Connection.
Select OPC UA option.
Type the endpoint for the TwinCAT OPC UA Server. opc.tcp://localhost:4840
Select the found server.
Select and endpoint.
Select 'yes' to Trust Certificate option.
Confirm the settings.
Type the username(user) and password(user) that we used to connect to TwinCAT OPC UA server.
We have successfully added the TwinCAT OPC connection.
Now we will use the OPC Quick Client tool on Ignition gateway to check the variables in the plc program. Go to Config and select 'OPC Quick Client'.
Expand the TcOpcUAServer .
Under PLC1 and MAIN folders, you can see the variables that we used in our plc program. Click on the [w] option of bStart variable to set it TRUE.
Set value to 'true' and click Write.
You will receive the write successful message. You can subscribe to the variables to see their value real-time.
Read the nCounter value. In our program, we are increasing the counter by 1 as long as bStart variable is True. You can read few times to observe the counter value increase.
You can play with other variables or add new variables in your program to have a better understanding of OPC UA communication between TwinCAT 3 and Igniton.
In case you want to say thank you !)
We'd be very grateful if you could share this community with your colleagues and friends. You can also buy us a coffee to keep us fueled 😊 This is the best way to say thank you to this project and support your community.
twinControls - https://twincontrols.com/
@beckhoffsupport Is it possible for us to access the global variable list in the ignition via OPCUA?
@beckhoffsupport
Good afternoon. Is it possible to organize an OPC UA Server on TCBSD. I tried to activate the configuration, but I don't see OPC UA in TCBSD processes. I tried to connect with the client when pf (pfctl -d) is disabled, OPC is not detected either. Is there an instruction for creating an OPC UA Server on TCBSD? Thank you for any help.
Thanks for the great write up! I ran into a couple of issues that may help any future readers.
1. After installing the OPC license, save and close the project and then restart the PC or VM. On restart, the OPC server will be initialized and running as indicated by the purple symbol in the taskbar.
2. I noticed that having an OPC client (Softing) installed while doing this process caused issues with connecting to the server created in OPC Configurator. After uninstalling the client, I was able to see and connect to the endpoint in TwinCAT.
@treyem Thanks a lot for sharing your solutions! 🙌
In case you want to say thank you !)
We'd be very grateful if you could share this community with your colleagues and friends. You can also buy us a coffee to keep us fueled 😊 This is the best way to say thank you to this project and support your community.
twinControls - https://twincontrols.com/
Is it possible for us to access the global variable list in the ignition via OPCUA?
@spongebobhang Yes, its definitely possible. I haven't followed the guide above, but it looks similar to what I have used. I usually have a bunch of GVL files. Just make sure {attribute 'OPC.UA.DA':='1'} is in front of each variable that you want to access. When you do a tag import in ignition designer, your folder structure will be automatically present, and you can import everything or be very selective if you don't want to overburden the tag driver.
- 17 Forums
- 267 Topics
- 942 Posts
- 0 Online
- 722 Members