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