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



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.ComTypes Namespace > _EasyUAClient Interface : ChangeMonitoredItemSubscription Method
Monitored item subscription handle as returned by the subscription method.
The sampling interval (in milliseconds) indicates the fastest rate at which the Server should sample its underlying source for data changes.
Changes parameters of a subscription. Specify the handle, and a new sampling interval.
Syntax
'Declaration
 
Sub ChangeMonitoredItemSubscription( _
   ByVal handle As Integer, _
   ByVal samplingInterval As Integer _
) 
'Usage
 
Dim instance As _EasyUAClient
Dim handle As Integer
Dim samplingInterval As Integer
 
instance.ChangeMonitoredItemSubscription(handle, samplingInterval)
void ChangeMonitoredItemSubscription( 
   int handle,
   int samplingInterval
)
void ChangeMonitoredItemSubscription( 
   int handle,
   int samplingInterval
) 

Parameters

handle
Monitored item subscription handle as returned by the subscription method.
samplingInterval
The sampling interval (in milliseconds) indicates the fastest rate at which the Server should sample its underlying source for data changes.
Remarks

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 change the sampling rate of an existing monitored
// item subscription.
//
// 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.

type
  TClientEventHandlers110 = class
    procedure OnDataChangeNotification(
      ASender: TObject;
      sender: OleVariant;
      const eventArgs: _EasyUADataChangeNotificationEventArgs);
  end;

procedure TClientEventHandlers110.OnDataChangeNotification(
  ASender: TObject;
  sender: OleVariant;
  const eventArgs: _EasyUADataChangeNotificationEventArgs);
begin
  // Display the data
  if eventArgs.Succeeded then
      WriteLn(eventArgs.AttributeData.ToString)
  else
      WriteLn('*** Failure: ',
      eventArgs.ErrorMessageBrief);
end;

class procedure ChangeMonitoredItemSubscription.Main;
var
  Client: TEasyUAClient;
  ClientEventHandlers: TClientEventHandlers110;
  Handle: Cardinal;
begin
  // Instantiate the client object and hook events
  Client := TEasyUAClient.Create(nil);
  ClientEventHandlers := TClientEventHandlers110.Create;
  Client.OnDataChangeNotification := ClientEventHandlers.OnDataChangeNotification;

  WriteLn('Subscribing...');
  Handle := Client.SubscribeDataChange(
    //'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=10853',
    1000);

  WriteLn('Processing monitored item changed events for 10 seconds...');
  PumpSleep(10*1000);

  Client.ChangeMonitoredItemSubscription(Handle, 100);

  WriteLn('Processing monitored item changed events for 10 seconds...');
  PumpSleep(10*1000);

  WriteLn('Unsubscribing...');
  Client.UnsubscribeAllMonitoredItems;

  WriteLn('Waiting for 5 seconds...');
  PumpSleep(5*1000);

  WriteLn('Finished.');
  FreeAndNil(Client);
  FreeAndNil(ClientEventHandlers);
end;
REM This example shows how to change the sampling rate of an existing monitored
REM item subscription.
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.

' The client object, with events
'Public WithEvents Client5 As EasyUAClient

Public Sub ChangeMonitoredItemSubscription_Main_Command_Click()
    OutputText = ""
    
    Set Client5 = New EasyUAClient

    OutputText = OutputText & "Subscribing..." & vbCrLf
    Dim Handle As Long
    Handle = Client5.SubscribeDataChange("opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", "nsu=http://test.org/UA/Data/ ;i=10853", 1000)

    OutputText = OutputText & "Processing monitored item changed events for 10 seconds..." & vbCrLf
    Pause 10000

    Call Client5.ChangeMonitoredItemSubscription(Handle, 100)

    OutputText = OutputText & "Processing monitored item changed events for 10 seconds..." & vbCrLf
    Pause 10000

    OutputText = OutputText & "Unsubscribing..." & vbCrLf
    Client5.UnsubscribeAllMonitoredItems

    OutputText = OutputText & "Waiting for 5 seconds..." & vbCrLf
    Pause 5000

    OutputText = OutputText & "Finished." & vbCrLf
    Set Client5 = Nothing
End Sub

Public Sub Client5_DataChangeNotification(ByVal sender As Variant, ByVal eventArgs As EasyUADataChangeNotificationEventArgs)
    ' Display the data
    If eventArgs.Exception Is Nothing Then
        OutputText = OutputText & eventArgs.AttributeData & vbCrLf
    Else
        OutputText = OutputText & eventArgs.ErrorMessageBrief & vbCrLf
    End If
End Sub
Rem This example shows how to change the sampling rate of an existing monitored item subscription.
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

' Instantiate the client object and hook events
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient")
WScript.ConnectObject Client, "Client_"

WScript.Echo "Subscribing..."
Dim handle: handle = Client.SubscribeDataChange( _
    "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", _
    "nsu=http://test.org/UA/Data/ ;i=10853", _
    1000)

WScript.Echo "Processing monitored item changed events for 10 seconds..."
WScript.Sleep 10 * 1000

WScript.Echo "Changing subscription..."
Client.ChangeMonitoredItemSubscription handle, 100

WScript.Echo "Processing monitored item changed events for 10 seconds..."
WScript.Sleep 10 * 1000

WScript.Echo "Unsubscribing..."
Client.UnsubscribeAllMonitoredItems

WScript.Echo "Waiting for 5 seconds..."
WScript.Sleep 5 * 1000



Sub Client_DataChangeNotification(Sender, e)
    Dim display: If e.Exception Is Nothing Then display = e.AttributeData Else display = e.ErrorMessageBrief
    WScript.Echo display
End Sub
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