.NET Based OPC UA Client/Server SDK
3.0.4.468
|
A session with the server must be established.
The following dialog shows an example implementation of the Call service which invokes a Method on an Object. Press the button “Show Code” to display the corresponding code, and the button “Help” to show this documentation page.
Press the button “...” to open a browse window and select an object on which a method is defined.
After selecting an object, the drop down box Method will be filled with the available methods for the object.
After selecting a method, the parameter list for the Request will be filled with the input arguments of the selected method.
Double-click on a parameter to edit it.
Check the box in front of “Use Asynchronous Pattern” to call “BeginCall” instead of “Call”.
The method call is executed by clicking the “Call” button. The output arguments will be displayed in the parameter list of the response.
The sample code can be found in the CallMethodDlg class. You can open the file from the sample dialog with the “Show Code” button or you can open the complete solution via Examples → GettingStarted. The CallMethodDlg.cs file can be found in the Method folder of the Getting Started solution.
A method in OPC UA is called with
The method returns
If the method is well known, it can be called with the known list of arguments. The data types of the arguments and the number of arguments must match the method definition in the OPC UA server.
If the method is not known, the information about the method arguments can be requested from the OPC UA server. Sample code for getting information about a method and available methods can be found in the following section.
In a first step the request parameters for the method call are prepared. The object NodeId is parsed from the Object text box in the dialog. The method NodeId is extracted from the reference description attached to the Method drop down box in the dialog. The list of input argument values is collected from the list box in the dialog.
Used SDK classes are
In a second step the method is called on the server
Used SDK classes and methods are
In a third step the result code of the method is checked and the output arguments are filled into the response list box.
In this section the NodeId of the Method and the descriptions of the method arguments are not well known. It is shown how to request the needed information for the method call from the SDK.
The following sample code shows how Browse can be used to get the list of Methods of an Object.
The list of method input and output arguments can be requested using the helper function GetMethodDescription.
The corresponding sample code can be found in CallMethodDlg::MethodCB_SelectedIndexChanged. It is used to display the list of input and output arguments in the dialog.
The following self contained code connects to the .NET Demo Server and calls a method with one input argument and one output argument.