Changes parameters of a particular event subscription.
Changes parameters of an event subscription. Specify new notification rate, subscription filter object, and an "active" flag.
Syntax
Parameters
- 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.
- filter
- An AESubscriptionFilter that determines the filtering criteria to be used for the event subscription.
- active
- Activates or deactivates the subscription. If the client deactivates the subscription, then the server will no longer send event notifications to the client based on that subscription, and has no responsibility to buffer or maintain the event notifications. Thus event notifications may be lost. Even if the subscription is inactive, the Refresh method will still function. In effect, this allows a client to obtain current condition states from time to time (by invoking Refresh) without the need to process event notifications in "real time".
Exceptions
Exception | Description |
System.ArgumentNullException | A null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument. |
Example
// 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.
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 2012 R2, Windows Server 2016; .NET: Linux, macOS, Microsoft Windows
See Also