简体   繁体   English

在 a.Net Core OPC UA 客户端上使用基于事件的 MonitoredItem 处理 Sinumerik 警报

[英]Handling Sinumerik Alarms with Event Based MonitoredItem on a .Net Core OPC UA client

I'm trying to monitor alarm events on a OPC UA client utilizing event based monitored items.我正在尝试使用基于事件的监控项来监控 OPC UA 客户端上的警报事件。 I subscribe to the node: ns=2;s=Sinumerik and add the corresponding attributes and filters.我订阅了节点: ns=2;s=Sinumerik并添加了相应的属性和过滤器。 Later on I handle the notification on a OnNotification() method as shown in the code below.稍后我在 OnNotification() 方法上处理通知,如下面的代码所示。

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: OnNotification() 方法如下所示:

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.我收到事件通知,但 MonitoredItem 中没有值。

Is this the correct way to monitor event based monitored items for Sinumerik Alarms using OPC UA?这是使用 OPC UA 监控 Sinumerik 警报的基于事件的监控项的正确方法吗?

You are subscribing for Events, not other data attributes, so try item.DequeueEvents() instead.您正在订阅事件,而不是其他数据属性,因此请尝试item.DequeueEvents()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM