OPC Studio User's Guide and Reference
RefreshEventSubscription Method (_EasyAEClient)
Example 



OpcLabs.EasyOpcClassic Assembly > OpcLabs.EasyOpc.AlarmsAndEvents.ComTypes Namespace > _EasyAEClient Interface : RefreshEventSubscription Method
Event subscription handle as returned by the SubscribeEvents method
Force a refresh for all active conditions and inactive, unacknowledged conditions whose event notifications match the filter of the event subscription.

Clients often need to get the current condition information from the server, particularly at client startup, for things such as a current alarm summary. The OPC Event Server supports this requirement by resending the most recent event notifications which satisfy the filter in the event subscription and which are related to active and/or unacknowledged conditions. The client can then derive the current condition status from the "refreshed" event notifications.
Syntax
'Declaration
 
Sub RefreshEventSubscription( _
   ByVal handle As Integer _
) 
'Usage
 
Dim instance As _EasyAEClient
Dim handle As Integer
 
instance.RefreshEventSubscription(handle)
void RefreshEventSubscription( 
   int handle
)
void RefreshEventSubscription( 
   int handle
) 

Parameters

handle
Event subscription handle as returned by the SubscribeEvents method
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.

Remarks

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

Rem This example shows how to for a refresh for all active conditions and inactive, unacknowledged conditions.
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

Dim DAClient: Set DAClient = CreateObject("OpcLabs.EasyOpc.DataAccess.EasyDAClient")
Dim AEClient: Set AEClient = CreateObject("OpcLabs.EasyOpc.AlarmsAndEvents.EasyAEClient")
WScript.ConnectObject AEClient, "AEClient_"

WScript.Echo "Processing event notifications..."
Dim ServerDescriptor: Set ServerDescriptor = CreateObject("OpcLabs.EasyOpc.ServerDescriptor")
ServerDescriptor.ServerClass = "OPCLabs.KitEventServer.2"
Dim SourceDescriptor1: Set SourceDescriptor1 = CreateObject("OpcLabs.EasyOpc.AlarmsAndEvents.AENodeDescriptor")
SourceDescriptor1.QualifiedName = "Simulation.ConditionState1"
Dim SourceDescriptor2: Set SourceDescriptor2 = CreateObject("OpcLabs.EasyOpc.AlarmsAndEvents.AENodeDescriptor")
SourceDescriptor2.QualifiedName = "Simulation.ConditionState1"
Dim SourceDescriptor3: Set SourceDescriptor3 = CreateObject("OpcLabs.EasyOpc.AlarmsAndEvents.AENodeDescriptor")
SourceDescriptor3.QualifiedName = "Simulation.ConditionState1"
Dim SubscriptionParameters: Set SubscriptionParameters = CreateObject("OpcLabs.EasyOpc.AlarmsAndEvents.AESubscriptionParameters")
SubscriptionParameters.Filter.Sources = Array(SourceDescriptor1, SourceDescriptor2, SourceDescriptor3)
SubscriptionParameters.NotificationRate = 1000
Dim handle: handle = AEClient.SubscribeEvents(ServerDescriptor, SubscriptionParameters, True, Nothing)

Rem The component will perform auto-refresh at this point, give it time to happen
WScript.Echo "Waiting for 10 seconds..."
WScript.Sleep 10*1000

Rem Set some events to active state, which will cause them to appear in refresh
On Error Resume Next
WScript.Echo "Activating conditions and waiting for 10 seconds..."
DAClient.WriteItemValue "", "OPCLabs.KitServer.2", "SimulateEvents.ConditionState1.Activate", True
DAClient.WriteItemValue "", "OPCLabs.KitServer.2", "SimulateEvents.ConditionState2.Activate", True
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0
WScript.Sleep 10*1000

WScript.Echo "Refreshing subscription and waiting for 10 seconds..."
AEClient.RefreshEventSubscription handle
WScript.Sleep 10*1000

AEClient.UnsubscribeEvents handle



Rem Notification event handler
Sub AEClient_Notification(Sender, e)
    If Not (e.Succeeded) Then
        WScript.Echo "*** Failure: " & e.ErrorMessageBrief
        Exit Sub
    End If

    WScript.Echo 
    WScript.Echo "Refresh: " & e.Refresh
    WScript.Echo "RefreshComplete: " & e.RefreshComplete

    If Not (e.EventData Is Nothing) Then
        With e.EventData
            WScript.Echo "EventData.QualifiedSourceName: " & .QualifiedSourceName
            WScript.Echo "EventData.Message: " & .Message
            WScript.Echo "EventData.Active: " & .Active
            WScript.Echo "EventData.Acknowledged: " & .Acknowledged
        End With
    End If
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