// 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