QuickOPC User's Guide and Reference
ChangeEventSubscription(IEasyAEClient,Int32,Int32) Method
Example 



OpcLabs.EasyOpcClassicCore Assembly > OpcLabs.EasyOpc.AlarmsAndEvents Namespace > IEasyAEClientExtension Class > ChangeEventSubscription Method : ChangeEventSubscription(IEasyAEClient,Int32,Int32) Method
The client object that will perform the operation.
Event subscription handle as returned by the SubscribeEvents method
The requested notification rate. The notification rate is in milliseconds and tells the server how often to send event notifications. This is a minimum time - do not send event notifications any faster that this UNLESS the buffer size is reached. A value of 0 for notification rate means that the server should send event notifications as soon as it gets them. This parameter is used to improve communications efficiency between client and server. This parameter is a recommendation from the client, and the server is allowed to ignore the parameter.
Changes parameters of a particular event subscription. Changes parameters of an event subscription. Specify new notification rate. There will be no filtering, and the subscription will be activated.
Syntax
'Declaration
 
<ExtensionAttribute()>
Public Overloads Shared Sub ChangeEventSubscription( _
   ByVal client As IEasyAEClient, _
   ByVal handle As Integer, _
   ByVal notificationRate As Integer _
) 
'Usage
 
Dim client As IEasyAEClient
Dim handle As Integer
Dim notificationRate As Integer
 
IEasyAEClientExtension.ChangeEventSubscription(client, handle, notificationRate)
[Extension()]
public static void ChangeEventSubscription( 
   IEasyAEClient client,
   int handle,
   int notificationRate
)
[Extension()]
public:
static void ChangeEventSubscription( 
   IEasyAEClient^ client,
   int handle,
   int notificationRate
) 

Parameters

client
The client object that will perform the operation.
handle
Event subscription handle as returned by the SubscribeEvents method
notificationRate
The requested notification rate. The notification rate is in milliseconds and tells the server how often to send event notifications. This is a minimum time - do not send event notifications any faster that this UNLESS the buffer size is reached. A value of 0 for notification rate means that the server should send event notifications as soon as it gets them. This parameter is used to improve communications efficiency between client and server. This parameter is a recommendation from the client, and the server is allowed to ignore the parameter.
Exceptions
ExceptionDescription

One of the arguments provided to a method is not valid.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

The value of an argument is outside the allowable range of values as defined by the invoked method.

This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception.

Remarks

 

This method operates (at least in part) asynchronously, with respect to the caller. The actual execution of the operation may be delayed, and the outcome of the operation (if any) is provided to the calling code using an event notification, callback, or other means explained in the text. In a properly written program, this method does not throw any exceptions. You should therefore not put try/catch statements or similar constructs around calls to this method. The only exceptions thrown by this method are for usage errors, i.e. when your code violates the usage contract of the method, such as passing in invalid arguments or calling the method when the state of the object does not allow it. Any operation-related errors (i.e. errors that depend on external conditions that your code cannot reliably check) are indicated by the means the operation returns its outcome (if any), which is described in the text. For more information, see Do not catch any exceptions with asynchronous or multiple-operation methods.
Example

.NET

.NET

// This example shows how to subscribe to events and later change the notification rate.

using System;
using System.Threading;
using OpcLabs.EasyOpc.AlarmsAndEvents;
using OpcLabs.EasyOpc.AlarmsAndEvents.OperationModel;

namespace DocExamples.AlarmsAndEvents._EasyAEClient
{
    class ChangeEventSubscription
    {
        public static void Main1()
        {
            // Instantiate the client object.
            using (var client = new EasyAEClient())
            {
                var eventHandler = new EasyAENotificationEventHandler(client_Notification);
                client.Notification += eventHandler;

                Console.WriteLine("Subscribing...");
                int handle = client.SubscribeEvents("", "OPCLabs.KitEventServer.2", 500);

                Console.WriteLine("Waiting for 10 seconds...");
                Thread.Sleep(10 * 1000);

                Console.WriteLine("Changing subscription...");
                client.ChangeEventSubscription(handle, 5 * 1000);

                Console.WriteLine("Waiting for 50 seconds...");
                Thread.Sleep(50 * 1000);

                client.UnsubscribeEvents(handle);
            }
        }

        // Notification event handler
        static void client_Notification(object sender, EasyAENotificationEventArgs e)
        {
            if (!e.Succeeded)
            {
                Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief);
                return;
            }

            if (!(e.EventData is null))
                Console.WriteLine(e.EventData.Message);
        }
    }
}
# This example shows how to subscribe to events and later change the notification rate.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
import time

# Import .NET namespaces.
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.AlarmsAndEvents import *


# Notification event handler
def notification(sender, e):
    if not e.Succeeded:
        print('*** Failure: ', e.ErrorMessageBrief, sep='')
        return
    else:
        if e.EventData is not None:
            print(e.EventData.Message)


# Instantiate the client object
client = EasyAEClient()

client.Notification += notification

print('Subscribing events...')
handle = IEasyAEClientExtension.SubscribeEvents(client, '', 'OPCLabs.KitEventServer.2', 500)

print('Waiting for 10 seconds...')
time.sleep(10)

print('Changing event subscription...')
IEasyAEClientExtension.ChangeEventSubscription(client, handle, 5*1000)

print('Waiting for 50 seconds...')
time.sleep(50)

print('Unsubscribing events...')
client.UnsubscribeAllEvents()

client.Notification -= notification

print('Finished.')
' This example shows how to subscribe to events and later change the notification rate.

Imports System.Threading
Imports OpcLabs.EasyOpc.AlarmsAndEvents
Imports OpcLabs.EasyOpc.AlarmsAndEvents.OperationModel

Namespace AlarmsAndEvents._EasyAEClient

    Friend Class ChangeEventSubscription
        Public Shared Sub Main1()
            Using client = New EasyAEClient()
                Dim eventHandler = New EasyAENotificationEventHandler(AddressOf client_Notification)
                AddHandler client.Notification, eventHandler

                Console.WriteLine("Subscribing...")
                Dim handle As Integer = client.SubscribeEvents("", "OPCLabs.KitEventServer.2", 500)

                Console.WriteLine("Waiting for 10 seconds...")
                Thread.Sleep(10 * 1000)

                Console.WriteLine("Changing subscription...")
                client.ChangeEventSubscription(handle, 5 * 1000)

                Console.WriteLine("Waiting for 50 seconds...")
                Thread.Sleep(50 * 1000)

                client.UnsubscribeEvents(handle)
            End Using
        End Sub

        ' Notification event handler
        Private Shared Sub client_Notification(ByVal sender As Object, ByVal e As EasyAENotificationEventArgs)
            If Not e.Succeeded Then
                Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief)
                Exit Sub
            End If
            If e.EventData IsNot Nothing Then
                Console.WriteLine(e.EventData.Message)
            End If
        End Sub
    End Class
End Namespace
// This example shows how to subscribe to events and later change the notification rate.

using System;
using System.Threading;
using OpcLabs.EasyOpc.AlarmsAndEvents;
using OpcLabs.EasyOpc.AlarmsAndEvents.OperationModel;

namespace DocExamples.AlarmsAndEvents._EasyAEClient
{
    class ChangeEventSubscription
    {
        public static void Main1()
        {
            // Instantiate the client object.
            using (var client = new EasyAEClient())
            {
                var eventHandler = new EasyAENotificationEventHandler(client_Notification);
                client.Notification += eventHandler;

                Console.WriteLine("Subscribing...");
                int handle = client.SubscribeEvents("", "OPCLabs.KitEventServer.2", 500);

                Console.WriteLine("Waiting for 10 seconds...");
                Thread.Sleep(10 * 1000);

                Console.WriteLine("Changing subscription...");
                client.ChangeEventSubscription(handle, 5 * 1000);

                Console.WriteLine("Waiting for 50 seconds...");
                Thread.Sleep(50 * 1000);

                client.UnsubscribeEvents(handle);
            }
        }

        // Notification event handler
        static void client_Notification(object sender, EasyAENotificationEventArgs e)
        {
            if (!e.Succeeded)
            {
                Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief);
                return;
            }

            if (!(e.EventData is null))
                Console.WriteLine(e.EventData.Message);
        }
    }
}
# This example shows how to subscribe to events and later change the notification rate.

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc
import time

# Import .NET namespaces.
from OpcLabs.EasyOpc import *
from OpcLabs.EasyOpc.AlarmsAndEvents import *


# Notification event handler
def notification(sender, e):
    if not e.Succeeded:
        print('*** Failure: ', e.ErrorMessageBrief, sep='')
        return
    else:
        if e.EventData is not None:
            print(e.EventData.Message)


# Instantiate the client object
client = EasyAEClient()

client.Notification += notification

print('Subscribing events...')
handle = IEasyAEClientExtension.SubscribeEvents(client, '', 'OPCLabs.KitEventServer.2', 500)

print('Waiting for 10 seconds...')
time.sleep(10)

print('Changing event subscription...')
IEasyAEClientExtension.ChangeEventSubscription(client, handle, 5*1000)

print('Waiting for 50 seconds...')
time.sleep(50)

print('Unsubscribing events...')
client.UnsubscribeAllEvents()

client.Notification -= notification

print('Finished.')
' This example shows how to subscribe to events and later change the notification rate.

Imports System.Threading
Imports OpcLabs.EasyOpc.AlarmsAndEvents
Imports OpcLabs.EasyOpc.AlarmsAndEvents.OperationModel

Namespace AlarmsAndEvents._EasyAEClient

    Friend Class ChangeEventSubscription
        Public Shared Sub Main1()
            Using client = New EasyAEClient()
                Dim eventHandler = New EasyAENotificationEventHandler(AddressOf client_Notification)
                AddHandler client.Notification, eventHandler

                Console.WriteLine("Subscribing...")
                Dim handle As Integer = client.SubscribeEvents("", "OPCLabs.KitEventServer.2", 500)

                Console.WriteLine("Waiting for 10 seconds...")
                Thread.Sleep(10 * 1000)

                Console.WriteLine("Changing subscription...")
                client.ChangeEventSubscription(handle, 5 * 1000)

                Console.WriteLine("Waiting for 50 seconds...")
                Thread.Sleep(50 * 1000)

                client.UnsubscribeEvents(handle)
            End Using
        End Sub

        ' Notification event handler
        Private Shared Sub client_Notification(ByVal sender As Object, ByVal e As EasyAENotificationEventArgs)
            If Not e.Succeeded Then
                Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief)
                Exit Sub
            End If
            If e.EventData IsNot Nothing Then
                Console.WriteLine(e.EventData.Message)
            End If
        End Sub
    End Class
End Namespace
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