QuickOPC User's Guide and Reference
AcknowledgeCondition(IEasyAEClient,ServerDescriptor,AENodeDescriptor,String,Int64,Int64,String,String) Method
Example 



OpcLabs.EasyOpcClassicCore Assembly > OpcLabs.EasyOpc.AlarmsAndEvents Namespace > IEasyAEClientExtension Class > AcknowledgeCondition Method : AcknowledgeCondition(IEasyAEClient,ServerDescriptor,AENodeDescriptor,String,Int64,Int64,String,String) Method
The client object that will perform the operation.
The OPC server involved in the operation.
Contains fully qualified source name. Identifies the source of the condition that is being acknowledged, e.g. FIC101.
A condition name, identifying the condition that is being acknowledged. Condition Names are unique within the scope of the event server. Examples of Condition Names might be "LevelAlarm" or "Deviation".
An active time (in UTC ticks) corresponding to the Source and Condition Name pair. This parameter uniquely identifies a specific transition of the condition to the active state or into a different sub-condition and is the same as the AEConditionState.SubconditionActiveTime condition attribute. Active Times are passed to the client in the event notification. If the condition has become active again or transitioned into a different sub-condition at a later time, this acknowledgment will be ignored.
A server supplied "cookie" corresponding to the Source and Condition Name pair that in addition to the Active Time uniquely identifies a specific event notification. Cookies are passed to the client in the event notification. The client is responsible for returning the same cookie parameter, received in the event notification, back to the server in the condition acknowledgment.
A string passed in by the client, identifying who is acknowledging the condition. This is an attribute (AcknowledgerID) of the condition that identifies who acknowledged the condition. This is just a string generated by the client. This is also also included as the ActorId in the acknowledgment event notification sent to all subscribing clients. When omitted, a default value from OpcLabs.EasyOpc.AlarmsAndEvents.Engine.EasyAEClientMode.AcknowledgerId is used. An AcknowledgerId cannot result in an empty string, since such AcknowledgerId is used to indicate that the event was automatically acknowledged by the server.
Comment string passed in by the client associated with acknowledging the condition. An empty string indicating no comment is allowed. When omitted, an empty string is used instead.
Acknowledges a condition in the Event Server. The client will receive event notifications (indicating the acknowledgement) from conditions. This method specifically acknowledges the condition becoming active or transitioning into a different sub-condition (and no other state transition of the condition). One or more conditions belong to a specific event source - the source of the event notification. For each condition-related event notification, the corresponding Source, Condition Name, Active Time and Cookie is received by the client as part of the event notification.

Acknowledges a condition in the Event Server. The client will receive event notifications (indicating the acknowledgement) from conditions. This method specifically acknowledges the condition becoming active or transitioning into a different sub-condition (and no other state transition of the condition). One or more conditions belong to a specific event source - the source of the event notification. For each condition-related event notification, the corresponding Source, Condition Name, Active Time and Cookie is received by the client as part of the event notification.

Uses server descriptor for specifying the OPC server. Pass in acknowledger ID and comment. The active time time is specified in UTC ticks.

Syntax
'Declaration
 
<ExtensionAttribute()>
Public Overloads Shared Sub AcknowledgeCondition( _
   ByVal client As IEasyAEClient, _
   ByVal serverDescriptor As ServerDescriptor, _
   ByVal sourceDescriptor As AENodeDescriptor, _
   ByVal conditionName As String, _
   ByVal activeTimeTicks As Long, _
   ByVal cookie As Long, _
   ByVal acknowledgerId As String, _
   ByVal comment As String _
) 
'Usage
 
Dim client As IEasyAEClient
Dim serverDescriptor As ServerDescriptor
Dim sourceDescriptor As AENodeDescriptor
Dim conditionName As String
Dim activeTimeTicks As Long
Dim cookie As Long
Dim acknowledgerId As String
Dim comment As String
 
IEasyAEClientExtension.AcknowledgeCondition(client, serverDescriptor, sourceDescriptor, conditionName, activeTimeTicks, cookie, acknowledgerId, comment)

Parameters

client
The client object that will perform the operation.
serverDescriptor
The OPC server involved in the operation.
sourceDescriptor
Contains fully qualified source name. Identifies the source of the condition that is being acknowledged, e.g. FIC101.
conditionName
A condition name, identifying the condition that is being acknowledged. Condition Names are unique within the scope of the event server. Examples of Condition Names might be "LevelAlarm" or "Deviation".
activeTimeTicks
An active time (in UTC ticks) corresponding to the Source and Condition Name pair. This parameter uniquely identifies a specific transition of the condition to the active state or into a different sub-condition and is the same as the AEConditionState.SubconditionActiveTime condition attribute. Active Times are passed to the client in the event notification. If the condition has become active again or transitioned into a different sub-condition at a later time, this acknowledgment will be ignored.
cookie
A server supplied "cookie" corresponding to the Source and Condition Name pair that in addition to the Active Time uniquely identifies a specific event notification. Cookies are passed to the client in the event notification. The client is responsible for returning the same cookie parameter, received in the event notification, back to the server in the condition acknowledgment.
acknowledgerId
A string passed in by the client, identifying who is acknowledging the condition. This is an attribute (AcknowledgerID) of the condition that identifies who acknowledged the condition. This is just a string generated by the client. This is also also included as the ActorId in the acknowledgment event notification sent to all subscribing clients. When omitted, a default value from OpcLabs.EasyOpc.AlarmsAndEvents.Engine.EasyAEClientMode.AcknowledgerId is used. An AcknowledgerId cannot result in an empty string, since such AcknowledgerId is used to indicate that the event was automatically acknowledged by the server.
comment
Comment string passed in by the client associated with acknowledging the condition. An empty string indicating no comment is allowed. When omitted, an empty string is used instead.
Exceptions
ExceptionDescription

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.

The OPC "Classic" (or OPC XML-DA) operation has failed. This operation exception in uniformly used to allow common handling of various kinds of errors. The System.Exception.InnerException always contains information about the actual error cause.

This is an operation error that depends on factors external to your program, and thus cannot be always avoided. Your code must handle it appropriately.

Remarks

The server can be local or can be remotely accessed via DCOM. Optionally, an access path can be specified or a specific data type can be requested.

The client is required to pass the activeTime and cookie received in the event notification to the AcknowledgeCondition method without modification.

The server can be local or can be remotely accessed via DCOM. Optionally, an access path can be specified or a specific data type can be requested.

The client is required to pass the activeTime and cookie received in the event notification to the AcknowledgeCondition method without modification.

Example

.NET

.NET

// This example shows how to acknowledge an event condition in the OPC server.

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 AcknowledgeCondition
    {
        // 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();

        static volatile bool _done;

        public static void Main1()
        {
            var eventHandler = new EasyAENotificationEventHandler(AEClient_Notification);
            AEClient.Notification += eventHandler;

            Console.WriteLine("Processing event notifications for 1 minute...");
            var subscriptionFilter = new AESubscriptionFilter
            {
                Sources = new AENodeDescriptor[] { "Simulation.ConditionState1" }
            };
            int handle = AEClient.SubscribeEvents("", "OPCLabs.KitEventServer.2", 1000, null, subscriptionFilter);

            // Give the refresh operation time to complete
            Thread.Sleep(5 * 1000);

            // Trigger an acknowledgeable event
            try
            {
                DAClient.WriteItemValue("", "OPCLabs.KitServer.2", "SimulateEvents.ConditionState1.Activate", true);
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }

            _done = false;
            DateTime endTime = DateTime.Now + new TimeSpan(0, 0, 5);
            while ((!_done) && (DateTime.Now < endTime))
                Thread.Sleep(1000);

            // Give some time to also receive the acknowledgement notification
            Thread.Sleep(5 * 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);
                Console.WriteLine("Event.AcknowledgeRequired: {0}", eventData.AcknowledgeRequired);

                if (eventData.AcknowledgeRequired)
                {
                    Console.WriteLine(">>>>> ACKNOWLEDGING THIS EVENT");
                    try
                    {
                        AEClient.AcknowledgeCondition("", "OPCLabs.KitEventServer.2", "Simulation.ConditionState1", "Simulated",
                            eventData.ActiveTime, eventData.Cookie);
                    }
                    catch (OpcException opcException)
                    {
                        Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                        return;
                    }
                    Console.WriteLine(">>>>> EVENT ACKNOWLEDGED");
                    _done = true;
                }
            }
        }
    }
}
# This example shows how to acknowledge an event condition in the OPC server.

# 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 *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *


# Notification event handler
def notification(sender, e):
    global aeClient
    global done

    if not e.Succeeded:
        print('*** Failure: ', e.ErrorMessageBrief, sep='')
        return
    print('Refresh: ', e.Refresh, sep='')
    print('RefreshComplete: ', e.RefreshComplete, sep='')
    eventData = e.EventData
    if eventData is not None:
        print('EventData.QualifiedSourceName: ', eventData.QualifiedSourceName, sep='')
        print('EventData.Message: ', eventData.Message, sep='')
        print('EventData.Active: ', eventData.Active, sep='')
        print('EventData.ActiveTime: ', eventData.ActiveTime, sep='')
        print('EventData.ActiveTimeTicks: ', eventData.ActiveTimeTicks, sep='')
        print('EventData.Acknowledged: ', eventData.Acknowledged, sep='')
        print('EventData.AcknowledgeRequired: ', eventData.AcknowledgeRequired, sep='')
        print('EventData.Cookie: ', eventData.Cookie, sep='')
        if eventData.AcknowledgeRequired:
            print('>>>>> ACKNOWLEDGING THIS EVENT')
            try:
                IEasyAEClientExtension.AcknowledgeCondition(aeClient,
                                                            '', 'OPCLabs.KitEventServer.2',
                                                            'Simulation.ConditionState1', 'Simulated',
                                                            eventData.ActiveTimeTicks, eventData.Cookie,
                                                            'Myself')  # acknowledgerId
                # The precise ActiveTime is important for event acknowledgement in OPC A&E. Python.NET, however,
                # represents .NET DateTime to Python 'datetime' object, possibly losing precision. For this reason,
                # use AEEventData.ActiveTimeTicks (as above), and not AEEventData.ActiveTime.
                # aeClient.AcknowledgeCondition('', 'OPCLabs.KitEventServer.2',
                #                               'Simulation.ConditionState1', 'Simulated',
                #                               eventData.ActiveTime, eventData.Cookie)
            except OpcException as opcException:
                print('*** Failure: ' + opcException.GetBaseException().Message)
                done = True
                return
            print('>>>>> EVENT ACKNOWLEDGED')
            done = True


# Instantiate the OPC-A&E client object.
aeClient = EasyAEClient()

# Instantiate the OPC-DA client object.
daClient = EasyDAClient()

#
aeClient.Notification += notification

print('Processing event notifications for 1 minute...')
subscriptionFilter = AESubscriptionFilter()
subscriptionFilter.Sources = [AENodeDescriptor('Simulation.ConditionState1')]
handle = IEasyAEClientExtension.SubscribeEvents(aeClient, '', 'OPCLabs.KitEventServer.2', 1000, None,
                                                subscriptionFilter)

# Give the refresh operation time to complete.
time.sleep(5)

# Trigger an acknowledgeable event.
done = False
try:
    IEasyDAClientExtension.WriteItemValue(daClient, '', 'OPCLabs.KitServer.2',
                                          'SimulateEvents.ConditionState1.Activate', True)
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message)
    exit()

endTime = time.time() + 60
while (not done) and (time.time() < endTime):
    time.sleep(1)

# Give some time to also receive the acknowledgement notification.
time.sleep(5)

aeClient.UnsubscribeAllEvents()
aeClient.Notification -= notification

print('Finished.')
' This example shows how to acknowledge an event condition in the OPC server.

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 AcknowledgeCondition
        _
        Private Shared ReadOnly AEClient As New EasyAEClient()
        _
        Private Shared ReadOnly DAClient As New EasyDAClient()

        Private Shared _done As Boolean ' volatile

        Public Shared Sub Main1()
            Dim eventHandler = New EasyAENotificationEventHandler(AddressOf AEClient_Notification)
            AddHandler AEClient.Notification, eventHandler

            Console.WriteLine("Processing event notifications for 1 minute...")
            Dim subscriptionFilter As New AESubscriptionFilter
            subscriptionFilter.Sources = New AENodeDescriptor() {"Simulation.ConditionState1"}
            Dim handle As Integer = AEClient.SubscribeEvents("", "OPCLabs.KitEventServer.2", 1000, Nothing, subscriptionFilter)

            ' Give the refresh operation time to complete
            Thread.Sleep(5 * 1000)

            ' Trigger an acknowledgeable event
            Try
                DAClient.WriteItemValue("", "OPCLabs.KitServer.2", "SimulateEvents.ConditionState1.Activate", True)
            Catch opcException As OpcException
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                Exit Sub
            End Try

            _done = False
            Dim endTime As Date = Date.Now + New TimeSpan(0, 0, 5)
            Do While ((Not _done)) AndAlso (Date.Now < endTime)
                Thread.Sleep(1000)
            Loop

            ' Give some time to also receive the acknowledgement notification
            Thread.Sleep(5 * 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("EventData.QualifiedSourceName: {0}", eventData.QualifiedSourceName)
                Console.WriteLine("EventData.Message: {0}", eventData.Message)
                Console.WriteLine("EventData.Active: {0}", eventData.Active)
                Console.WriteLine("EventData.Acknowledged: {0}", eventData.Acknowledged)
                Console.WriteLine("EventData.AcknowledgeRequired: {0}", eventData.AcknowledgeRequired)

                If eventData.AcknowledgeRequired Then
                    Console.WriteLine(">>>>> ACKNOWLEDGING THIS EVENT")
                    Try
                        AEClient.AcknowledgeCondition("", "OPCLabs.KitEventServer.2", "Simulation.ConditionState1", "Simulated", eventData.ActiveTime, eventData.Cookie)
                    Catch opcException As OpcException
                        Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                        Exit Sub
                    End Try
                    Console.WriteLine(">>>>> EVENT ACKNOWLEDGED")
                    _done = True
                End If
            End If
        End Sub
    End Class
End Namespace
// This example shows how to acknowledge an event condition in the OPC server.

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 AcknowledgeCondition
    {
        // 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();

        static volatile bool _done;

        public static void Main1()
        {
            var eventHandler = new EasyAENotificationEventHandler(AEClient_Notification);
            AEClient.Notification += eventHandler;

            Console.WriteLine("Processing event notifications for 1 minute...");
            var subscriptionFilter = new AESubscriptionFilter
            {
                Sources = new AENodeDescriptor[] { "Simulation.ConditionState1" }
            };
            int handle = AEClient.SubscribeEvents("", "OPCLabs.KitEventServer.2", 1000, null, subscriptionFilter);

            // Give the refresh operation time to complete
            Thread.Sleep(5 * 1000);

            // Trigger an acknowledgeable event
            try
            {
                DAClient.WriteItemValue("", "OPCLabs.KitServer.2", "SimulateEvents.ConditionState1.Activate", true);
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }

            _done = false;
            DateTime endTime = DateTime.Now + new TimeSpan(0, 0, 5);
            while ((!_done) && (DateTime.Now < endTime))
                Thread.Sleep(1000);

            // Give some time to also receive the acknowledgement notification
            Thread.Sleep(5 * 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);
                Console.WriteLine("Event.AcknowledgeRequired: {0}", eventData.AcknowledgeRequired);

                if (eventData.AcknowledgeRequired)
                {
                    Console.WriteLine(">>>>> ACKNOWLEDGING THIS EVENT");
                    try
                    {
                        AEClient.AcknowledgeCondition("", "OPCLabs.KitEventServer.2", "Simulation.ConditionState1", "Simulated",
                            eventData.ActiveTime, eventData.Cookie);
                    }
                    catch (OpcException opcException)
                    {
                        Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                        return;
                    }
                    Console.WriteLine(">>>>> EVENT ACKNOWLEDGED");
                    _done = true;
                }
            }
        }
    }
}
# This example shows how to acknowledge an event condition in the OPC server.

# 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 *
from OpcLabs.EasyOpc.DataAccess import *
from OpcLabs.EasyOpc.OperationModel import *


# Notification event handler
def notification(sender, e):
    global aeClient
    global done

    if not e.Succeeded:
        print('*** Failure: ', e.ErrorMessageBrief, sep='')
        return
    print('Refresh: ', e.Refresh, sep='')
    print('RefreshComplete: ', e.RefreshComplete, sep='')
    eventData = e.EventData
    if eventData is not None:
        print('EventData.QualifiedSourceName: ', eventData.QualifiedSourceName, sep='')
        print('EventData.Message: ', eventData.Message, sep='')
        print('EventData.Active: ', eventData.Active, sep='')
        print('EventData.ActiveTime: ', eventData.ActiveTime, sep='')
        print('EventData.ActiveTimeTicks: ', eventData.ActiveTimeTicks, sep='')
        print('EventData.Acknowledged: ', eventData.Acknowledged, sep='')
        print('EventData.AcknowledgeRequired: ', eventData.AcknowledgeRequired, sep='')
        print('EventData.Cookie: ', eventData.Cookie, sep='')
        if eventData.AcknowledgeRequired:
            print('>>>>> ACKNOWLEDGING THIS EVENT')
            try:
                IEasyAEClientExtension.AcknowledgeCondition(aeClient,
                                                            '', 'OPCLabs.KitEventServer.2',
                                                            'Simulation.ConditionState1', 'Simulated',
                                                            eventData.ActiveTimeTicks, eventData.Cookie,
                                                            'Myself')  # acknowledgerId
                # The precise ActiveTime is important for event acknowledgement in OPC A&E. Python.NET, however,
                # represents .NET DateTime to Python 'datetime' object, possibly losing precision. For this reason,
                # use AEEventData.ActiveTimeTicks (as above), and not AEEventData.ActiveTime.
                # aeClient.AcknowledgeCondition('', 'OPCLabs.KitEventServer.2',
                #                               'Simulation.ConditionState1', 'Simulated',
                #                               eventData.ActiveTime, eventData.Cookie)
            except OpcException as opcException:
                print('*** Failure: ' + opcException.GetBaseException().Message)
                done = True
                return
            print('>>>>> EVENT ACKNOWLEDGED')
            done = True


# Instantiate the OPC-A&E client object.
aeClient = EasyAEClient()

# Instantiate the OPC-DA client object.
daClient = EasyDAClient()

#
aeClient.Notification += notification

print('Processing event notifications for 1 minute...')
subscriptionFilter = AESubscriptionFilter()
subscriptionFilter.Sources = [AENodeDescriptor('Simulation.ConditionState1')]
handle = IEasyAEClientExtension.SubscribeEvents(aeClient, '', 'OPCLabs.KitEventServer.2', 1000, None,
                                                subscriptionFilter)

# Give the refresh operation time to complete.
time.sleep(5)

# Trigger an acknowledgeable event.
done = False
try:
    IEasyDAClientExtension.WriteItemValue(daClient, '', 'OPCLabs.KitServer.2',
                                          'SimulateEvents.ConditionState1.Activate', True)
except OpcException as opcException:
    print('*** Failure: ' + opcException.GetBaseException().Message)
    exit()

endTime = time.time() + 60
while (not done) and (time.time() < endTime):
    time.sleep(1)

# Give some time to also receive the acknowledgement notification.
time.sleep(5)

aeClient.UnsubscribeAllEvents()
aeClient.Notification -= notification

print('Finished.')
' This example shows how to acknowledge an event condition in the OPC server.

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 AcknowledgeCondition
        _
        Private Shared ReadOnly AEClient As New EasyAEClient()
        _
        Private Shared ReadOnly DAClient As New EasyDAClient()

        Private Shared _done As Boolean ' volatile

        Public Shared Sub Main1()
            Dim eventHandler = New EasyAENotificationEventHandler(AddressOf AEClient_Notification)
            AddHandler AEClient.Notification, eventHandler

            Console.WriteLine("Processing event notifications for 1 minute...")
            Dim subscriptionFilter As New AESubscriptionFilter
            subscriptionFilter.Sources = New AENodeDescriptor() {"Simulation.ConditionState1"}
            Dim handle As Integer = AEClient.SubscribeEvents("", "OPCLabs.KitEventServer.2", 1000, Nothing, subscriptionFilter)

            ' Give the refresh operation time to complete
            Thread.Sleep(5 * 1000)

            ' Trigger an acknowledgeable event
            Try
                DAClient.WriteItemValue("", "OPCLabs.KitServer.2", "SimulateEvents.ConditionState1.Activate", True)
            Catch opcException As OpcException
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                Exit Sub
            End Try

            _done = False
            Dim endTime As Date = Date.Now + New TimeSpan(0, 0, 5)
            Do While ((Not _done)) AndAlso (Date.Now < endTime)
                Thread.Sleep(1000)
            Loop

            ' Give some time to also receive the acknowledgement notification
            Thread.Sleep(5 * 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("EventData.QualifiedSourceName: {0}", eventData.QualifiedSourceName)
                Console.WriteLine("EventData.Message: {0}", eventData.Message)
                Console.WriteLine("EventData.Active: {0}", eventData.Active)
                Console.WriteLine("EventData.Acknowledged: {0}", eventData.Acknowledged)
                Console.WriteLine("EventData.AcknowledgeRequired: {0}", eventData.AcknowledgeRequired)

                If eventData.AcknowledgeRequired Then
                    Console.WriteLine(">>>>> ACKNOWLEDGING THIS EVENT")
                    Try
                        AEClient.AcknowledgeCondition("", "OPCLabs.KitEventServer.2", "Simulation.ConditionState1", "Simulated", eventData.ActiveTime, eventData.Cookie)
                    Catch opcException As OpcException
                        Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                        Exit Sub
                    End Try
                    Console.WriteLine(">>>>> EVENT ACKNOWLEDGED")
                    _done = True
                End If
            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