OPC Studio User's Guide and Reference
Acknowledging a Condition (OPC A&E)
View with Navigation Tools
Client and Subscriber Development > Development Models > Imperative Programming Model > Imperative Programming Model for OPC Classic A&E > Modifying Information (OPC A&E) > Acknowledging a Condition (OPC A&E)

If you want to acknowledge a condition in OPC Alarms and Events server, call the AcknowledgeCondition method. You pass in individual arguments for machine name, server class, fully qualified source name, condition name, and an active time and cookie corresponding to the transition of the condition you are acknowledging.

.NET

// This example shows how to acknowledge an event condition in the OPC server.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

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

COM

Rem This example shows how to acknowledge an event condition in the OPC server.
Rem
Rem Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

Option Explicit

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

WScript.Echo "Hooking event handler..."
WScript.ConnectObject AEClient, "AEClient_"

Dim ServerDescriptor: Set ServerDescriptor = CreateObject("OpcLabs.EasyOpc.ServerDescriptor")
ServerDescriptor.ServerClass = "OPCLabs.KitEventServer.2"

Dim SourceDescriptor: Set SourceDescriptor = CreateObject("OpcLabs.EasyOpc.AlarmsAndEvents.AENodeDescriptor")
SourceDescriptor.QualifiedName = "Simulation.ConditionState1"

WScript.Echo "Processing event notifications for 1 minute..."
Dim SubscriptionParameters: Set SubscriptionParameters = CreateObject("OpcLabs.EasyOpc.AlarmsAndEvents.AESubscriptionParameters")
SubscriptionParameters.Filter.Sources = Array(SourceDescriptor)
SubscriptionParameters.NotificationRate = 1000
Dim handle: handle = AEClient.SubscribeEvents(ServerDescriptor, SubscriptionParameters, True, Nothing)

WScript.Echo "Give the refresh operation time to complete: Waiting for 5 seconds..."
WScript.Sleep 5*1000

WScript.Echo "Triggering an acknowledgeable event..."
On Error Resume Next
DAClient.WriteItemValue "", "OPCLabs.KitServer.2", "SimulateEvents.ConditionState1.Activate", True
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0

Dim done: done = False
Dim endTime: endTime = Now() + 5*(1/24/60/60)
While (Not done) And (Now() < endTime)
    WScript.Sleep 1000
WEnd

WScript.Echo "Give some time to also receive the acknowledgement notification: Waiting for 5 seconds..."
WScript.Sleep 5*1000

WScript.Echo "Unsubscribing events..."
AEClient.UnsubscribeEvents handle

WScript.Echo "Unhooking event handler..."
WScript.DisconnectObject AEClient

WScript.Echo "Finished."



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
            WScript.Echo "EventData.AcknowledgeRequired: " & .AcknowledgeRequired

            If .AcknowledgeRequired Then
                WScript.Echo ">>>>> ACKNOWLEDGING THIS EVENT"
                On Error Resume Next
                AEClient.AcknowledgeCondition ServerDescriptor, SourceDescriptor, "Simulated", _
                    .ActiveTime, .Cookie, "aUser", ""
                If Err.Number <> 0 Then
                    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
                    Exit Sub
                End If
                On Error Goto 0
                WScript.Echo ">>>>> EVENT ACKNOWLEDGED"
                done = True
            End If
        End With
    End If
End Sub

 

Optionally, you can pass in acknowledger ID (who is acknowledging the condition), and a comment string.

You can alternatively pass in a ServerDescriptor in place of machine name and server class arguments.

See Also