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



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.ComTypes Namespace > _EasyUAClient Interface : CallMethod Method
Endpoint descriptor. Identifies the OPC-UA server.

The value represents an OPC UA endpoint descriptor string. Any string can be passed to this parameter (i.e. will not cause System.ArgumentException), but not all values make sense and will work when an operation using them is attempted. The OPC UA endpoint descriptor string is typically the URL of the server endpoint.

The value of this parameter can be null (Nothing in Visual Basic).

Node descriptor. Identifies the node in OPC server's address space.

The value of this parameter can be null (Nothing in Visual Basic).

Method Node Id. Identifies the method node in OPC server's address space.

The value of this parameter can be null (Nothing in Visual Basic).

Array of input arguments to the method call.

The value of this parameter cannot be null (Nothing in Visual Basic).

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.

The value of this parameter can be null (Nothing in Visual Basic).

Calls a method with specified input arguments, using an endpoint descriptor and an object node Id.
Syntax
'Declaration
 
<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.

The value represents an OPC UA endpoint descriptor string. Any string can be passed to this parameter (i.e. will not cause System.ArgumentException), but not all values make sense and will work when an operation using them is attempted. The OPC UA endpoint descriptor string is typically the URL of the server endpoint.

The value of this parameter can be null (Nothing in Visual Basic).

objectNodeDescriptorString
Node descriptor. Identifies the node in OPC server's address space.

The value of this parameter can be null (Nothing in Visual Basic).

methodNodeDescriptorString
Method Node Id. Identifies the method node in OPC server's address space.

The value of this parameter can be null (Nothing in Visual Basic).

inputArguments
Array of input arguments to the method call.

The value of this parameter cannot be null (Nothing in Visual Basic).

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.

The value of this parameter can be null (Nothing in Visual Basic).

Return Value

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

This method never returns null (Nothing in Visual Basic).

The individual elements of the returned value can be null (Nothing in Visual Basic).

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.

This member or type is for use from COM. It is not meant to be used from .NET or Python. Refer to the corresponding .NET member or type instead, if you are developing in .NET or Python.

Example

COM

// This example shows how to call a single method, and pass arguments to and from it.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

#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();
    }
}
// This example shows how to call a single method, and pass arguments to and
// from it.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

class procedure CallMethod.Main;
var
  Client: EasyUAClient;
  I: Cardinal;
  Inputs: OleVariant;
  Outputs: OleVariant;
  TypeCodes: OleVariant;
begin
  Inputs := VarArrayCreate([0, 10], varVariant);
  Inputs[0] := False;
  Inputs[1] := 1;
  Inputs[2] := 2;
  Inputs[3] := 3;
  Inputs[4] := 4;
  Inputs[5] := 5;
  Inputs[6] := 6;
  Inputs[7] := 7;
  Inputs[8] := 8;
  Inputs[9] := 9;
  Inputs[10] := 10;

  TypeCodes := VarArrayCreate([0, 10], varVariant);
  TypeCodes[0] := TypeCode_Boolean;
  TypeCodes[1] := TypeCode_SByte;
  TypeCodes[2] := TypeCode_Byte;
  TypeCodes[3] := TypeCode_Int16;
  TypeCodes[4] := TypeCode_UInt16;
  TypeCodes[5] := TypeCode_Int32;
  TypeCodes[6] := TypeCode_UInt32;
  TypeCodes[7] := TypeCode_Int64;
  TypeCodes[8] := TypeCode_UInt64;
  TypeCodes[9] := TypeCode_Single;
  TypeCodes[10] := TypeCode_Double;

  // Instantiate the client object
  Client := CoEasyUAClient.Create;

  // Perform the operation
  TVarData(Outputs).VType := varArray or varVariant;
  TVarData(Outputs).VArray := PVarArray(Client.CallMethod(
    //'http://opcua.demo-this.com:51211/UA/SampleServer',
    'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer',
    'nsu=http://test.org/UA/Data/ ;i=10755',
    'nsu=http://test.org/UA/Data/ ;i=10756',
    PSafeArray(TVarData(Inputs).VArray),
    PSafeArray(TVarData(TypeCodes).VArray)));

  // Display results
  for I := VarArrayLowBound(Outputs, 1) to VarArrayHighBound(Outputs, 1) do
      try
        WriteLn('outputs(', I, '): ', Outputs[I]);
      except
        on EVariantError do WriteLn('*** Error displaying the value');
      end;
end;
// This example shows how to call a single method, and pass arguments to and
// from it.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in Object Pascal (Delphi) on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-OP .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

class procedure CallMethod.Main;
var
  Client: OpcLabs_EasyOpcUA_TLB._EasyUAClient;
  I: Cardinal;
  Inputs: OleVariant;
  Outputs: OleVariant;
  TypeCodes: OleVariant;
begin
  Inputs := VarArrayCreate([0, 10], varVariant);
  Inputs[0] := False;
  Inputs[1] := 1;
  Inputs[2] := 2;
  Inputs[3] := 3;
  Inputs[4] := 4;
  Inputs[5] := 5;
  Inputs[6] := 6;
  Inputs[7] := 7;
  Inputs[8] := 8;
  Inputs[9] := 9;
  Inputs[10] := 10;

  TypeCodes := VarArrayCreate([0, 10], varVariant);
  TypeCodes[0] := TypeCode_Boolean;
  TypeCodes[1] := TypeCode_SByte;
  TypeCodes[2] := TypeCode_Byte;
  TypeCodes[3] := TypeCode_Int16;
  TypeCodes[4] := TypeCode_UInt16;
  TypeCodes[5] := TypeCode_Int32;
  TypeCodes[6] := TypeCode_UInt32;
  TypeCodes[7] := TypeCode_Int64;
  TypeCodes[8] := TypeCode_UInt64;
  TypeCodes[9] := TypeCode_Single;
  TypeCodes[10] := TypeCode_Double;

  // Instantiate the client object
  Client := CoEasyUAClient.Create;

  // Perform the operation
  try
    TVarData(Outputs).VType := varArray or varVariant;
    TVarData(Outputs).VArray := PVarArray(Client.CallMethod(
      //'http://opcua.demo-this.com:51211/UA/SampleServer',
      //'https://opcua.demo-this.com:51212/UA/SampleServer/',
      'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer',
      'nsu=http://test.org/UA/Data/ ;i=10755',
      'nsu=http://test.org/UA/Data/ ;i=10756',
      Inputs,
      TypeCodes));
  except
    on E: EOleException do
    begin
      WriteLn(Format('*** Failure: %s', [E.GetBaseException.Message]));
      Exit;
    end;
  end;

  // Display results
  for I := VarArrayLowBound(Outputs, 1) to VarArrayHighBound(Outputs, 1) do
      WriteLn('outputs(', I, '): ', Outputs[I]);

   VarClear(Outputs);
   VarClear(TypeCodes);
   VarClear(Inputs);

end;
// This example shows how to call a single method, and pass arguments to and from it.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in PHP on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-PHP .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

$inputs[0] = false;
$inputs[1] = 1;
$inputs[2] = 2;
$inputs[3] = 3;
$inputs[4] = 4;
$inputs[5] = 5;
$inputs[6] = 6;
$inputs[7] = 7;
$inputs[8] = 8;
$inputs[9] = 9;
$inputs[10] = 10;

$typeCodes[0] = 3;    // TypeCode.Boolean
$typeCodes[1] = 5;    // TypeCode.SByte
$typeCodes[2] = 6;    // TypeCode.Byte
$typeCodes[3] = 7;    // TypeCode.Int16
$typeCodes[4] = 8;    // TypeCode.UInt16
$typeCodes[5] = 9;    // TypeCode.Int32
$typeCodes[6] = 10;   // TypeCode.UInt32
$typeCodes[7] = 11;   // TypeCode.Int64
$typeCodes[8] = 12;   // TypeCode.UInt64
$typeCodes[9] = 13;   // TypeCode.Single
$typeCodes[10] = 14;  // TypeCode.Double

// Instantiate the client object
$Client = new COM("OpcLabs.EasyOpc.UA.EasyUAClient");

// Perform the operation
try
{
    $outputs = $Client->CallMethod(
        //"http://opcua.demo-this.com:51211/UA/SampleServer", 
        "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", 
        "nsu=http://test.org/UA/Data/ ;i=10755", 
        "nsu=http://test.org/UA/Data/ ;i=10756", 
        $inputs, 
        $typeCodes);
}
catch (com_exception $e)
{
    printf("*** Failure: %s\n", $e->getMessage());
    Exit();
}

// Display results
for ($i = 0; $i < count($outputs); $i++)
{
    printf("outputs[d]s\n", $i, $outputs[$i]);
}
# This example shows how to call a single method, and pass arguments to and from it.
#
# The Python for Windows (pywin32) extensions package is needed. Install it using "pip install pypiwin32".
# CAUTION: We now recommend using Python.NET package instead. Full set of examples with Python.NET is available!
#
# Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
import win32com.client
from pywintypes import com_error

# Instantiate the client object
client = win32com.client.Dispatch('OpcLabs.EasyOpc.UA.EasyUAClient') 

# 
inputs = [False, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
typeCodes = [
    3,  # TypeCode.Boolean
    5,  # TypeCode.SByte
    6,  # TypeCode.Byte
    7,  # TypeCode.Int16
    8,  # TypeCode.UInt16
    9,  # TypeCode.Int32
    10, # TypeCode.UInt32
    11, # TypeCode.Int64
    12, # TypeCode.UInt64
    13, # TypeCode.Single
    14  # TypeCode.Double
    ]


# Perform the operation
try:
    outputs = client.CallMethod(
        'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer',
        'nsu=http://test.org/UA/Data/ ;i=10755',
        'nsu=http://test.org/UA/Data/ ;i=10756',
        inputs,
        typeCodes)
    # outputs[0] contains the actual results; outputs[1] and outputs[2] are copies of inputs and typeCodes.
except com_error as e:
    print('*** Failure: ' + e.args[2][1] + ': ' + e.args[2][2])
    exit()


# Display results
for i, value in enumerate(outputs[0]):
     print('outputs[', i, ']: ', value)

# Example output:
#outputs[0]: False
#outputs[1]: 1
#outputs[2]: 2
#outputs[3]: 3
#outputs[4]: 4
#outputs[5]: 5
#outputs[6]: 6
#outputs[7]: 7
#outputs[8]: 8
#outputs[9]: 9.0
#outputs[10]: 10.0
REM This example shows how to call a single method, and pass arguments to and from it.
REM
REM Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
REM OPC client and subscriber examples in Visual Basic on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VB .
REM Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
REM a commercial license in order to use Online Forums, and we reply to every post.

Public Sub CallMethod_Main_Command_Click()
    OutputText = ""

    Dim inputs(10)
    inputs(0) = False
    inputs(1) = 1
    inputs(2) = 2
    inputs(3) = 3
    inputs(4) = 4
    inputs(5) = 5
    inputs(6) = 6
    inputs(7) = 7
    inputs(8) = 8
    inputs(9) = 9
    inputs(10) = 10

    Dim typeCodes(10)
    typeCodes(0) = 3    ' TypeCode.Boolean
    typeCodes(1) = 5    ' TypeCode.SByte
    typeCodes(2) = 6    ' TypeCode.Byte
    typeCodes(3) = 7    ' TypeCode.Int16
    typeCodes(4) = 8    ' TypeCode.UInt16
    typeCodes(5) = 9    ' TypeCode.Int32
    typeCodes(6) = 10   ' TypeCode.UInt32
    typeCodes(7) = 11   ' TypeCode.Int64
    typeCodes(8) = 12   ' TypeCode.UInt64
    typeCodes(9) = 13   ' TypeCode.Single
    typeCodes(10) = 14  ' TypeCode.Double

    ' Instantiate the client object
    Dim Client As New EasyUAClient

    ' Perform the operation
    On Error Resume Next
    Dim outputs As Variant
    outputs = Client.CallMethod( _
        "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", _
        "nsu=http://test.org/UA/Data/ ;i=10755", _
        "nsu=http://test.org/UA/Data/ ;i=10756", _
        inputs, _
        typeCodes)
    If Err.Number <> 0 Then
        OutputText = OutputText & "*** Failure: " & Err.Source & ": " & Err.Description & vbCrLf
        Exit Sub
    End If
    On Error GoTo 0

    ' Display results
    Dim i: For i = LBound(outputs) To UBound(outputs)
        On Error Resume Next
        OutputText = OutputText & "outputs(" & i & "): " & outputs(i) & vbCrLf
        If Err <> 0 Then OutputText = OutputText & "*** Error" & vbCrLf ' occurrs with types not recognized by VB6
        On Error GoTo 0
    Next
End Sub
Rem This example shows how to call a single method, and pass arguments to and from it.
Rem
Rem Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
Rem OPC client and subscriber examples in VBScript on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBScript .
Rem Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
Rem a commercial license in order to use Online Forums, and we reply to every post.

Option Explicit

Dim inputs(10)
inputs(0) = False
inputs(1) = 1
inputs(2) = 2
inputs(3) = 3
inputs(4) = 4
inputs(5) = 5
inputs(6) = 6
inputs(7) = 7
inputs(8) = 8
inputs(9) = 9
inputs(10) = 10

Dim typeCodes(10)
typeCodes(0) = 3    ' TypeCode.Boolean
typeCodes(1) = 5    ' TypeCode.SByte
typeCodes(2) = 6    ' TypeCode.Byte
typeCodes(3) = 7    ' TypeCode.Int16
typeCodes(4) = 8    ' TypeCode.UInt16
typeCodes(5) = 9    ' TypeCode.Int32
typeCodes(6) = 10   ' TypeCode.UInt32
typeCodes(7) = 11   ' TypeCode.Int64
typeCodes(8) = 12   ' TypeCode.UInt64
typeCodes(9) = 13   ' TypeCode.Single
typeCodes(10) = 14  ' TypeCode.Double

' Instantiate the client object
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient")

' Perform the operation
On Error Resume Next
Dim outputs: outputs = Client.CallMethod( _
    "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", _
    "nsu=http://test.org/UA/Data/ ;i=10755", _
    "nsu=http://test.org/UA/Data/ ;i=10756", _
    inputs, _
    typeCodes)
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0

' Display results
Dim i: For i = LBound(outputs) To UBound(outputs)
    On Error Resume Next
    WScript.Echo "outputs(" & i & "): " & outputs(i)
    If Err <> 0 Then WScript.Echo "*** Error"   ' occurrs with types not recognized by VBScript
    On Error Goto 0
Next
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