Join us today!

TwinCAT OPC UA Serv...
 
Notifications
Clear all

TwinCAT OPC UA Server - Ignition OPC UA Client

7 Posts
6 Users
3 Likes
2,398 Views
TwinControls
Posts: 71
Admin
Topic starter
(@beckhoffsupport)
Member
Joined: 2 years ago

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. 

tf6100

Setting up TwinCAT OPC UA Server:

After installing TF6100, create a TwinCAT 3 project and add the TF6100 license in your project. 

license

 

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.

tmc

 

Now we will add a Connectivity project into our solution. Right click on your solution, select add , then New Project. 

addconnectivityproject

 

Selet TwinCAT Connectivity and then the empty TwinCAT Connectivity Project option. Give your project a name and click OK. 

addempty

 

Right click on the TwinCAT Connectivity project and add a new item. 

addopc

 

Select the TwinCAT OPC UA Server Project option, name it and click OK. 

selectopcua

 

Double click on TwinCAT OPC UA Server Project1 and go to UA EndPoints tab. We can configure the OPC UA server endpoints here.

doubleclickopcuaserverproject

 

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. 

enableconfigurator

In this tool, select 'Edit list' to add a server. 

editlist

 

Click Add Server and select an endpoint using the dropdown menu and click OK. We selected the first option(None,none) for this tutorial. 

addserver

 

Select the endpoint and click OK. 

selectendpoint

 

Right click on 'Data Access' and select 'Add Device Type' . 

dataaccess

 

Enter your PLC port number and click Create. 

portnumber

 

You can change these settings anytime in the properties section of the data access device. 

properties

 

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. 

tmcfilteredvsall

 

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 . 

connect1

 

password

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.

connect

Now we can see the server status. 

serverrunning

 

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. 

config

 

Select the Create new OPC Connection. 

createnewconnection

 

Select OPC UA option. 

opcua

 

Type the endpoint for the TwinCAT OPC UA Server.  opc.tcp://localhost:4840

selectserver

 

Select the found server. 

selectserver

 

Select and endpoint. 

selectendpoint

 

Select 'yes' to Trust Certificate option. 

trust

 

Confirm the settings. 

confirm

 

 

Type the username(user) and password(user) that we used to connect to TwinCAT OPC UA server. 

user

 

We have successfully added the TwinCAT OPC connection. 

success

 

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'. 

quickclient

 

Expand the TcOpcUAServer . 

twincatserver

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. 

vars

Set value to 'true' and click Write. 

write

 

You will receive the write successful message. You can subscribe to the variables to see their value real-time. 

success

 

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. 

read

 

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. 

 

Reply
6 Replies
2 Replies
(@spongebobhang)
Joined: 5 months ago

New Member
Posts: 2

@beckhoffsupport Is it possible for us to access the global variable list in the ignition via OPCUA?

Reply
(@davidklaus)
Joined: 5 months ago

New Member
Posts: 1

@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.

Reply
Posts: 16
Moderator
(@treyem)
Member
Joined: 2 years ago

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.

Reply
1 Reply
twinControls
Admin
(@twincontrols)
Joined: 2 years ago

Member
Posts: 114

@treyem Thanks a lot for sharing your solutions! 🙌

Reply
Posts: 2
(@spongebobhang)
New Member
Joined: 5 months ago

Is it possible for us to access the global variable list in the ignition via OPCUA?

Reply
1 Reply
(@phill-wright)
Joined: 4 months ago

New Member
Posts: 2

@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.

Reply
Share: