0

I'm trying to monitor alarm events on a OPC UA client utilizing event based monitored items. I subscribe to the node: ns=2;s=Sinumerik and add the corresponding attributes and filters. Later on I handle the notification on a OnNotification() method as shown in the code below.

var list = new List<MonitoredItem> { new MonitoredItem(_subscription.DefaultItem) {StartNodeId = "ns=2;s=Sinumerik" } };

foreach (MonitoredItem item in list)
{
    item.AttributeId = Attributes.EventNotifier;
    item.MonitoringMode = MonitoringMode.Reporting;
    item.SamplingInterval = -1;
    item.QueueSize = 100;
    item.DiscardOldest = false;
    EventFilter filter = new EventFilter();
    filter.AddSelectClause(ObjectTypes.BaseEventType, Opc.Ua.BrowseNames.Message);
    filter.AddSelectClause(ObjectTypes.BaseEventType, Opc.Ua.BrowseNames.Severity);
    item.Filter = filter;
    item.Notification += OnNotification;
}

_subscriptions[subscriptionNum].Create();
_subscriptions[subscriptionNum].ApplyChanges();

The OnNotification() method looks like this:

private void OnNotification(MonitoredItem item, MonitoredItemNotificationEventArgs e)
{
    foreach (var value in item.DequeueValues())
    {
        Console.WriteLine("Display Name: " + item.DisplayName + "Value: " + value.Value);
    }
}

I receive the event notification but there are no Values in the MonitoredItem.

Is this the correct way to monitor event based monitored items for Sinumerik Alarms using OPC UA?

Rodrigo Arroyo
  • 107
  • 1
  • 2
  • 9

1 Answers1

0

You are subscribing for Events, not other data attributes, so try item.DequeueEvents() instead.

Kevin Herron
  • 6,500
  • 3
  • 26
  • 35
  • `item.DequeueEvents()` returns no values. I see that some of the information I need is being stored in the `MonitoredItemNotificationEventArgs e` variable but I'm not able to access it in runtime, only while debugging – Rodrigo Arroyo Apr 08 '21 at 01:02