QuickOPC User's Guide and Reference
CallMethod Method (_EasyUAClient)
Example 



View with Navigation Tools
OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.ComTypes Namespace > _EasyUAClient Interface : CallMethod Method
Endpoint descriptor. Identifies the OPC-UA server.
Node descriptor. Identifies the node in OPC server's address space.
Method Node Id. Identifies the method node in OPC server's address space.
Array of input arguments to the method call.
Array of System.Int32, representing System.TypeCode values. The types that should be used when passing the input arguments to the server. The number of arguments and their types must conform to the method's requirements.
Calls a method with specified input arguments, using an endpoint descriptor and an object node Id.
Syntax
'Declaration
 
<ElementsCanBeNullAttribute()>
<NotNullAttribute()>
Function CallMethod( _
   ByVal endpointDescriptorString As String, _
   ByVal objectNodeDescriptorString As String, _
   ByVal methodNodeDescriptorString As String, _
   ByVal inputArguments As Object, _
   ByVal inputTypeCodes As Object _
) As Object()
 
'Usage
 
Dim instance As _EasyUAClient
Dim endpointDescriptorString As String
Dim objectNodeDescriptorString As String
Dim methodNodeDescriptorString As String
Dim inputArguments As Object
Dim inputTypeCodes As Object
Dim value() As Object
 
value = instance.CallMethod(endpointDescriptorString, objectNodeDescriptorString, methodNodeDescriptorString, inputArguments, inputTypeCodes)

Parameters

endpointDescriptorString
Endpoint descriptor. Identifies the OPC-UA server.
objectNodeDescriptorString
Node descriptor. Identifies the node in OPC server's address space.
methodNodeDescriptorString
Method Node Id. Identifies the method node in OPC server's address space.
inputArguments
Array of input arguments to the method call.
inputTypeCodes
Array of System.Int32, representing System.TypeCode values. The types that should be used when passing the input arguments to the server. The number of arguments and their types must conform to the method's requirements.

Return Value

Array of output arguments from the method call. The number of arguments and their types are given by the method.
Remarks

Hint for VB6, VBA and VBScript users: If you need to call an OPC UA method with no input arguments, use the Array() function, with no argument, to create an empty array. Alternatively, create an (empty) OpcLabs.BaseLib.Collections.ElasticVector, and convert it to an array using its OpcLabs.BaseLib.Collections.ElasticVector.ToArray Method.

Example

COM

// This example shows how to call a single method, and pass arguments to and from it.

#include "stdafx.h"    // Includes "QuickOpc.h", and other commonly used files
#include <atlsafe.h>
#include "CallMethod.h"

namespace _EasyUAClient
{
    void CallMethod::Main()
    {
        // Initialize the COM library
        CoInitializeEx(NULL, COINIT_MULTITHREADED);
        {
            CComSafeArray<VARIANT> inputs(11);
            inputs.SetAt(0, _variant_t(false));
            inputs.SetAt(1, _variant_t(1));
            inputs.SetAt(2, _variant_t(2));
            inputs.SetAt(3, _variant_t(3));
            inputs.SetAt(4, _variant_t(4));
            inputs.SetAt(5, _variant_t(5));
            inputs.SetAt(6, _variant_t(6));
            inputs.SetAt(7, _variant_t(7));
            inputs.SetAt(8, _variant_t(8));
            inputs.SetAt(9, _variant_t(9));
            inputs.SetAt(10, _variant_t(10));
            CComVariant vInputs(inputs);

            CComSafeArray<VARIANT> typeCodes(11);
            typeCodes.SetAt(0, _variant_t(TypeCode_Boolean));
            typeCodes.SetAt(1, _variant_t(TypeCode_SByte));
            typeCodes.SetAt(2, _variant_t(TypeCode_Byte));
            typeCodes.SetAt(3, _variant_t(TypeCode_Int16));
            typeCodes.SetAt(4, _variant_t(TypeCode_UInt16));
            typeCodes.SetAt(5, _variant_t(TypeCode_Int32));
            typeCodes.SetAt(6, _variant_t(TypeCode_UInt32));
            typeCodes.SetAt(7, _variant_t(TypeCode_Int64));
            typeCodes.SetAt(8, _variant_t(TypeCode_UInt64));
            typeCodes.SetAt(9, _variant_t(TypeCode_Single));
            typeCodes.SetAt(10, _variant_t(TypeCode_Double));
            CComVariant vTypeCodes(typeCodes);

            // Instantiate the client object
            _EasyUAClientPtr ClientPtr(__uuidof(EasyUAClient));

            // Perform the operation
            CComSafeArray<VARIANT> outputs;
            outputs.Attach(ClientPtr->CallMethod(
                //L"http://opcua.demo-this.com:51211/UA/SampleServer",
                L"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer",
                L"nsu=http://test.org/UA/Data/ ;i=10755",
                L"nsu=http://test.org/UA/Data/ ;i=10756",
                &vInputs,
                &vTypeCodes));
    
            // Display results
            for (int i = outputs.GetLowerBound(); i <= outputs.GetUpperBound(); i++)
            {
                _variant_t output(outputs[i]);
                _variant_t vString;
                vString.ChangeType(VT_BSTR, &output);
                _tprintf(_T("outputs(d)s\n"), i, (LPCTSTR)CW2CT((_bstr_t)vString));
            }
        }
         // Release all interface pointers BEFORE calling CoUninitialize()
        CoUninitialize();
    }
}
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also