cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

How to start PLC Method by DataLayer or OPC UA

How to start PLC Method by DataLayer or OPC UA

arizhih
New Poster

Hi,

Is it possible to start PLC Function, Method, FB or somthing different by DataLayer or OPC UA and wait for response?

In IndraWorks I used SymbolConfiguration option "Support calls to Function, FB..."

mtx_symbol_manager.jpg

But I can't find it in PLC Engineering

ctrlx_symbol_manager.jpg

What is the best way to achieve this?

Best regards,
Andrey

13 REPLIES 13

Jochen_Mueller
Community Moderator
Community Moderator

Hello Andrey

With the V1.14 we have FBs (CXA_OpcUAClient) that can start methodes at our servers (like XM, MLC, ...)

But our ctrlX CORE OPCserver doesn't support methodes within the PLC (Symbol-Configuration). This will come end of this year.

Regards

Jochen

Hello Jochen

And what about DataLayer, is it possible to start PLC method from C++?
I'm working on C++ app and want to process some task on the PLC side and wait for result of this task. To do this I need a way to run Method or Function in the PLC.

Best regards,

Andrey

CodeShepherd
Community Moderator
Community Moderator

One easy way would be to define an interface like PLCopen. Add start and finish Booleans and an input and output variable to the Data Layer.

Hi CodeShepherd

Thanks, I'll try.

HmiGuide
Community Moderator
Community Moderator

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”

HmiGuide_0-1668178498352.png

Activate execution rights for method mCallableViaOpcUa().

Meaning of access icons:

HmiGuide_1-1668178498352.png

 

Read only

HmiGuide_2-1668178498352.png

 

Read & execute

HmiGuide_3-1668178498352.png

 

Write only

HmiGuide_4-1668178498352.png

 

Write & execute

HmiGuide_5-1668178498352.png

 

Read and write

HmiGuide_6-1668178498352.png

 

Read, write and execute

HmiGuide_7-1668178498352.png

 

Execute

 

 

Set access rights (1) for parent fbMethodCall element: “read & write” HmiGuide_8-1668178498352.png or more

HmiGuide_9-1668178498353.png

Click on “…” to open window, for setting access rights of child element method “mCallableViaOpcUa” to “execute” HmiGuide_10-1668178498353.png

HmiGuide_11-1668178498354.png

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…”

HmiGuide_12-1668178498357.png

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

HmiGuide_13-1668178498358.png

Insert your organization in the yellow marked field, keep the other defaults and press “OK”.

HmiGuide_14-1668178498360.png

Setup communication

Click on Server>Add to open window “Add Server”

HmiGuide_15-1668178498360.png

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

HmiGuide_16-1668178498362.png

  • 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”.

HmiGuide_17-1668178498364.png

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…”

HmiGuide_18-1668178498365.png

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.

HmiGuide_19-1668178498367.png

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.

HmiGuide_20-1668178498369.png

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”

HmiGuide_21-1668178498370.png

E_Stapel
Established Member

Hello @HmiGuide ,

thank you for the great documentation on how to call PLC methods via OPC UA.

I created the exact same example as you show us above to see if it´s working. I copied the same FB but the PLC-Programm identify the token METHOD as unexpectedly (see screenshot) which causes errors. 

Futhermore (without Method and errors) I can´t find the FB in the symbol configuration. I set the settings as you mentioned and pressed build. I also tried to remove the symnol configuration and insert it new. Unfortunately it didn´t work. Do you have a documentation how to set up a FB with a Method correctly?

I use the CtrlX WORKS Version 1.20.4.

I hope that you have a solution for my problem. Thanks in advance.

 

HmiGuide
Community Moderator
Community Moderator

I'm currently on a buisiness trip and not able to check your problem. As I not really use the feature daily it will take me some time, to get familiar with it and verify your problem.

E_Stapel
Established Member

Ok, do you know a contact person who is familiar with this feature? This topic is really important for us right know. Thank you!

Hello,

I tried to reproduce your method on my 1.20 system.

At first I created a new FB called "FB_updateOrder" with an input and output variable.

2023-09-28_19h02_11.png

and added a method named "mCallableViaOpcUa" and impelementet the "output = input +1" logic.

2023-09-28_19h04_59.png

I created a new GVL named "GVL_MethodTest" 

2023-09-28_19h11_24.png

and configured the symbol configuration.

2023-09-28_19h12_13.png

After a download I connected to via UA Expert and I was able to call the function/method.

2023-09-28_19h13_14.png

best regards

Christian

HmiGuide
Community Moderator
Community Moderator

Hello@E_Stapel 

there is a basic misunderstanding from your side. You can't just copy the method code into the declaration part of the FB.
To create a method within a FB right click the FB, "Add object"> "Method."

HmiGuide_0-1695933116539.png

After adding the method it is visable in the tree (see picture below)

HmiGuide_1-1695933227647.png

 

 

Hello @NoRisk4Project  and @HmiGuide ,

thank you for the great help. In the past I tried already the Method Object in the same way you did it but I couldn´t find the Method in the symbol configuration. Now, I reproduced your example method in the exactly same way. Unfortunately I still can´t find the Method / GVL in the Symbol Configuration (See attachment). I hope you can help me. Thank you so much! 

HmiGuide
Community Moderator
Community Moderator

CoDeSys has changed the display of variable lists in the symbol configuration at some point. In the past everything was always displayed. Meanwhile the GVL's are hidden, which contain the pragma "attribute symbol".

Hello,
please clean your application by selecting "Build" and "Clean all". If this is done, rebuild your application with "Generate Code".
Please check the symbol configuration after this sequence again ...

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist