Call PLC methods via Opc UA
Introduction
When you want to call a method of a PLC FB via Opc UA, there are some restrictions:
ctrlX Engineering 1.16.0 (RM 22.07.0) or newer
Input/Output parameters of method are limited:
1 input parameter of basic data type (eg. INT, REAL, BOOL) no STRUCT, no ARRAYS
1 output parameter of basic data type (eg. INT, REAL, BOOL) no STRUCT, no ARRAYS
Correct setup of “Symbol Configuration”
Basic example for FB
create object GVL
//Elements are available via OPCUA even when they are not used in program
{attribute 'linkalways'}
//set access rights to read & write for all variables within VAR_GLOBAL
{attribute 'symbol' := 'readwrite'}
VAR_GLOBAL
fbMethodCall: FB_METHOD;
END_VAR
create object Function Block
FUNCTION_BLOCK FB_METHOD
VAR
///counts the number of calls
uliCntMethodCall: ULINT;
END_VAR
Add method to Function Block
METHOD mCallableViaOpcUa : INT
VAR_INPUT
iIn: INT; // currently only 1 input param supported
END_VAR
VAR_OUTPUT
iOut: INT; // currently only 1 output param supported
END_VAR
// Implementation
// counts the number of method call
uliCntMethodCall := uliCntMethodCall + 1;
iOut := iIn + 1; // increase input by 1
mCallableViaOpcUa := iOut; // return iOut
Setup of “Symbol Configuration”
Press “Build” to update the “Symbol Configuration”, than activate the options:
“Support OPC UA features”
“Support calls to Functions, FBs, Methods and Programs”
When this option is not available, check version of PLC
Remove and reinsert “Symbol Configuration”
Activate execution rights for method mCallableViaOpcUa().
Meaning of access icons:
Read only
Read & execute
Write only
Write & execute
Read and write
Read, write and execute
Execute
Set access rights (1) for parent fbMethodCall element: “read & write” or more
Click on “…” to open window, for setting access rights of child element method “mCallableViaOpcUa” to “execute”
Click “Online> Login” to PLC with a download. You might have to do a “Build> Clean” before.
Test method call with “UA Expert”
Ua Expert is a well-known OpcUA test client. It can be used to verify if the method is correctly written into the symbol configuration. See “chapter Install & Start UaExpert” for installation and first start documenatation.
Install & start Ua Expert
Configure it, as describe below
Define connection to the ctrlX CORE.
Browse symbol configuration
Right click mCallableViaOpcUa & selet “Call…”
When it fails:
Check the settings of the access rights
Check if you have max. only 1 input and 1 output parameter of a base data type
In Plc Engineering: Execute “Build> Clear” or “Build> Clean all”
Download and start the project
Install & Start UaExpert
Ua Expert is a well-known OpcUa testclient. You can download it from: https://www.unified-automation.com/downloads.html Start the installation program; use the default settings on every page select next installation page until installation is finished.
First Start of UaExpert
Starting the UaExpert the first time, a message is shown that a certificate must be created.
Insert your organization in the yellow marked field, keep the other defaults and press “OK”.
Setup communication
Click on Server>Add to open window “Add Server”
Provide “CtrlX” as configuration name (red mark)
<“Double click to Add server…> in branch “Custom Discovery” (yellow mark)
Provide URL: opc.tcp://192.168.1.2:4840 (green mark). Replace the IP address by the IP address of your control.
When the communication to the server can be established, the branches are shown (see cyan mark) otherwise the communication is not established. => Verify IP-address and OpcUa server is running.
Click “OK”. Now (at first connection) the certificates between CtrlX and UaExpert are exchanged. The certificate of CtrlX is displayed and you have to click on button “Trust Server Certificate” and button “Continue”.
HINT: The UA Expert sometimes replaces the IP address with the name of ctrlX, then the communication sometimes could not be established. To check this, right click the server item and select “Properties…”
Replace the name in the Endpoint Url with your IP-address. opc.tcp://192.168.1.1:4840. Press “OK” to close the window. To connect or disconnect select in menu: Server/Connect or Server/Disconnect.
Trust UaExpert certificate on CtrlX CORE (1.16.0)
Start ctrlX CORE web page. Login
Default user: boschrexroth
Default password: boschrexroth
Goto “Settings/Certificates & Keys/OPC UA Server”. Click on “…” and “Trust” the certificate.
Quit UaExpert (File>Quit) and restart it.
Select “Server>Start” Select the connection previously defined.
When the connection is successfully established the available OpcUa nodes are displayed in the window “Address Slave”. The screen shoot below shows the location of the PLC symbols. “Root>Objects>datalayer>plc>app>Application>sym”
... View more