Professional OPC
Development Tools

logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions. You do not have to be a licensed user of our product.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible. Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

Get event state during event handling

More
28 Apr 2020 08:24 #8409 by KrisSik
Hi,

Code you provided works:
UAFilterElements.SimpleAttribute(UAObjectTypeIds.AlarmConditionType, "/ActiveState"),

Thank you.

Best regards,
Kristian

Please Log in or Create an account to join the conversation.

More
27 Apr 2020 14:28 - 27 Apr 2020 14:28 #8406 by support
Yes, you are right, this is done using the Select clause.

The Active state is not present in all Events. In fact, not even in all Conditions. The conditions needs to be of the AlarmConditionType (see UA Spec 1.04 Part 9, chapter 5.8.2). In AlarmConditionType, there is ActiveState variable.

Assuming that this is what you are dealing with, you should be able to modify the example for Select clauses (opclabs.doc-that.com/files/onlinedocs/QuickOpc/Latest/User%2...0in%20an%20event%20filter.html ) accordingly. Here is how it looks currently:
// This example shows how to select fields for event notifications.
 
using System;
using System.Collections.Generic;
using OpcLabs.BaseLib.OperationModel;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.AddressSpace.Standard;
using OpcLabs.EasyOpc.UA.AlarmsAndConditions;
using OpcLabs.EasyOpc.UA.Filtering;
using OpcLabs.EasyOpc.UA.OperationModel;
 
namespace UADocExamples.AlarmsAndConditions
{
    class SelectClauses
    {
        public static void Main1()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:62544/Quickstarts/AlarmConditionServer";
 
            // Instantiate the client object and hook events
            var client = new EasyUAClient();
            client.EventNotification += client_EventNotification;
 
            Console.WriteLine("Subscribing...");
            client.SubscribeEvent(
                endpointDescriptor,
                UAObjectIds.Server,
                1000,
                new UAAttributeFieldCollection
                {
                    // Select specific fields using standard operand symbols
                    UABaseEventObject.Operands.NodeId,
                    UABaseEventObject.Operands.SourceNode,
                    UABaseEventObject.Operands.SourceName,
                    UABaseEventObject.Operands.Time,
 
                    // Select specific fields using an event type ID and a simple relative path
                    UAFilterElements.SimpleAttribute(UAObjectTypeIds.BaseEventType, "/Message"),
                    UAFilterElements.SimpleAttribute(UAObjectTypeIds.BaseEventType, "/Severity"),
                });
 
            Console.WriteLine("Processing event notifications for 30 seconds...");
            System.Threading.Thread.Sleep(30 * 1000);
 
            Console.WriteLine("Unsubscribing...");
            client.UnsubscribeAllMonitoredItems();
 
            Console.WriteLine("Waiting for 5 seconds...");
            System.Threading.Thread.Sleep(5 * 1000);
        }
 
        static void client_EventNotification(object sender, EasyUAEventNotificationEventArgs e)
        {
            Console.WriteLine();
 
            // Display the event
            if (e.EventData == null)
            {
                Console.WriteLine(e);
                return;
            }
            Console.WriteLine("All fields:");
            foreach (KeyValuePair<UAAttributeField, ValueResult> pair in e.EventData.FieldResults)
            {
                UAAttributeField attributeField = pair.Key;
                ValueResult valueResult = pair.Value;
                Console.WriteLine("  {0} -> {1}", attributeField, valueResult);
            }
            // Extracting a specific field using a standard operand symbol
            Console.WriteLine("Source name: {0}", 
                e.EventData.FieldResults[UABaseEventObject.Operands.SourceName]);
            // Extracting a specific field using an event type ID and a simple relative path
            Console.WriteLine("Message: {0}", 
                e.EventData.FieldResults[UAFilterElements.SimpleAttribute(UAObjectTypeIds.BaseEventType, "/Message")]);
        }
    }
}

and you would include something like
UAFilterElements.SimpleAttribute(UAObjectTypeIds.AlarmConditionType, "/ActiveState"),
(not tested)

Let me know if that works for you, please.

Best regards
Last edit: 27 Apr 2020 14:28 by support.
The following user(s) said Thank You: KrisSik

Please Log in or Create an account to join the conversation.

More
27 Apr 2020 09:36 - 27 Apr 2020 09:43 #8403 by KrisSik
Hi,

I am trying to get event's active/inactive state in the OpcClientOnEventNotification(object sender, EasyUAEventNotificationEventArgs e) event handler, but have no success in that, could you please help me?

I was expecting to see that attribute in the e.EventData.FieldResults, but that is not present in this dictionary. Maybe I need to configure the select clause while subscribing? For subscription I use SubscribeMultipleMonitoredItems method.

Best regards,
Kristian
Last edit: 27 Apr 2020 09:43 by KrisSik.

Please Log in or Create an account to join the conversation.

Moderators: support
Time to create page: 0.056 seconds