'Usage
Dim instance As EasyAEClient Dim handle As Integer instance.RefreshEventSubscription(handle)
Parameters
- handle
- Event subscription handle as returned by the SubscribeEvents method
'Usage
Dim instance As EasyAEClient Dim handle As Integer instance.RefreshEventSubscription(handle)
Exception | Description |
---|---|
System.ArgumentException | One of the arguments provided to a method is not valid. |
When the client needs a refreshed list of active conditions, it will request a "refresh" from the server. The server will send event notifications to that specific client indicating that they are "refresh" instead of "original" event notifications. Since the client only needs to get the current state information for conditions, only condition events will be refreshed. Remark: "Refresh" is not a general "replay" capability since the server is not required to maintain an event history. Refresh is only for updating the client's state information for active or unacknowledged conditions.
In addition to the refresh indicator, there may be other differences between original and refresh event notifications. Specifically, since some attribute information available at the time of the original event notification may be unavailable at the time of the refresh, some attributes in the refresh may be null.
Refresh and original event notifications may be interleaved. Thus, it is the responsibility of the client to check time stamps on the event notifications and put them into the correct order, to ensure correct condition status is obtained.
When sending refresh event notifications, the server indicates if there are more refresh event notifications to send (see the RefreshComplete property of EasyAENotificationEventArgs).
This method is applicable to condition-related events only. Notifications for simple events and tracking events are not returned, even if they would satisfy the filter of the event subscription.
This method is applicable both when the subscription is active and when it is inactive (see the discussion of the Active for the SubscribeEvents and ChangeEventSubscription methods).
// This example shows how to for a refresh for all active conditions and inactive, unacknowledged conditions. using System; using System.Threading; using OpcLabs.EasyOpc.AlarmsAndEvents; using OpcLabs.EasyOpc.AlarmsAndEvents.OperationModel; using OpcLabs.EasyOpc.DataAccess; using OpcLabs.EasyOpc.OperationModel; namespace DocExamples.AlarmsAndEvents._EasyAEClient { class RefreshEventSubscription { // Instantiate the OPC-A&E client object. static readonly EasyAEClient AEClient = new EasyAEClient(); // Instantiate the OPC-DA client object. static readonly EasyDAClient DAClient = new EasyDAClient(); public static void Main1() { var eventHandler = new EasyAENotificationEventHandler(AEClient_Notification); AEClient.Notification += eventHandler; Console.WriteLine("Processing event notifications..."); var subscriptionFilter = new AESubscriptionFilter { Sources = new AENodeDescriptor[] { "Simulation.ConditionState1", "Simulation.ConditionState2", "Simulation.ConditionState3" } }; int handle = AEClient.SubscribeEvents("", "OPCLabs.KitEventServer.2", 1000, null, subscriptionFilter); // The component will perform auto-refresh at this point, give it time to happen Console.WriteLine("Waiting for 10 seconds..."); Thread.Sleep(10 * 1000); // Set some events to active state, which will cause them to appear in refresh Console.WriteLine("Activating conditions and waiting for 10 seconds..."); try { DAClient.WriteItemValue("", "OPCLabs.KitServer.2", "SimulateEvents.ConditionState1.Activate", true); DAClient.WriteItemValue("", "OPCLabs.KitServer.2", "SimulateEvents.ConditionState2.Activate", true); } catch (OpcException opcException) { Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message); return; } Thread.Sleep(10 * 1000); Console.WriteLine("Refreshing subscription and waiting for 10 seconds..."); AEClient.RefreshEventSubscription(handle); Thread.Sleep(10 * 1000); AEClient.UnsubscribeEvents(handle); AEClient.Notification -= eventHandler; } // Notification event handler static void AEClient_Notification(object sender, EasyAENotificationEventArgs e) { Console.WriteLine(); if (!e.Succeeded) { Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief); return; } Console.WriteLine("Refresh: {0}", e.Refresh); Console.WriteLine("RefreshComplete: {0}", e.RefreshComplete); AEEventData eventData = e.EventData; if (!(eventData is null)) { Console.WriteLine("Event.QualifiedSourceName: {0}", eventData.QualifiedSourceName); Console.WriteLine("Event.Message: {0}", eventData.Message); Console.WriteLine("Event.Active: {0}", eventData.Active); Console.WriteLine("Event.Acknowledged: {0}", eventData.Acknowledged); } } } }
' This example shows how to for a refresh for all active conditions and inactive, unacknowledged conditions. Imports System.Threading Imports OpcLabs.EasyOpc.AlarmsAndEvents Imports OpcLabs.EasyOpc.AlarmsAndEvents.OperationModel Imports OpcLabs.EasyOpc.DataAccess Imports OpcLabs.EasyOpc.OperationModel Namespace AlarmsAndEvents._EasyAEClient Friend Class RefreshEventSubscription _ Private Shared ReadOnly AEClient As New EasyAEClient() _ Private Shared ReadOnly DAClient As New EasyDAClient() Public Shared Sub Main1() Dim eventHandler = New EasyAENotificationEventHandler(AddressOf AEClient_Notification) AddHandler AEClient.Notification, eventHandler Console.WriteLine("Processing event notifications...") Dim subscriptionFilter As New AESubscriptionFilter subscriptionFilter.Sources = New AENodeDescriptor() {"Simulation.ConditionState1", "Simulation.ConditionState2", "Simulation.ConditionState3"} Dim handle As Integer = AEClient.SubscribeEvents("", "OPCLabs.KitEventServer.2", 1000, Nothing, subscriptionFilter) ' The component will perform auto-refresh at this point, give it time to happen Console.WriteLine("Waiting for 10 seconds...") Thread.Sleep(10 * 1000) ' Set some events to active state, which will cause them to appear in refresh Console.WriteLine("Activating conditions and waiting for 10 seconds...") Try DAClient.WriteItemValue("", "OPCLabs.KitServer.2", "SimulateEvents.ConditionState1.Activate", True) DAClient.WriteItemValue("", "OPCLabs.KitServer.2", "SimulateEvents.ConditionState2.Activate", True) Catch opcException As OpcException Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message) Exit Sub End Try Thread.Sleep(10 * 1000) Console.WriteLine("Refreshing subscription and waiting for 10 seconds...") AEClient.RefreshEventSubscription(handle) Thread.Sleep(10 * 1000) AEClient.UnsubscribeEvents(handle) RemoveHandler AEClient.Notification, eventHandler End Sub ' Notification event handler Private Shared Sub AEClient_Notification(ByVal sender As Object, ByVal e As EasyAENotificationEventArgs) Console.WriteLine() If Not e.Succeeded Then Console.WriteLine("*** Failure: {0}", e.ErrorMessageBrief) Exit Sub End If Console.WriteLine("Refresh: {0}", e.Refresh) Console.WriteLine("RefreshComplete: {0}", e.RefreshComplete) If e.EventData IsNot Nothing Then Dim eventData As AEEventData = e.EventData Console.WriteLine("Event.QualifiedSourceName: {0}", eventData.QualifiedSourceName) Console.WriteLine("Event.Message: {0}", eventData.Message) Console.WriteLine("Event.Active: {0}", eventData.Active) Console.WriteLine("Event.Acknowledged: {0}", eventData.Acknowledged) End If End Sub End Class End Namespace