Exemplo n.º 1
0
        /// <summary>
        /// 处理订阅事件
        /// </summary>
        /// <param name="item"></param>
        /// <param name="e"></param>
        private void OnMonitoredNotification(MonitoredItem item, MonitoredItemNotificationEventArgs e)
        {
            MonitoredItemNotification notification = e.NotificationValue as MonitoredItemNotification;
            var node          = e.NotificationValue as NodeId;
            var opcUaDataItem = this.OpcUaDataItems.FirstOrDefault(a => a.Name == item.ResolvedNodeId.ToString());

            if (!Equals(opcUaDataItem, null))
            {
                opcUaDataItem.OldValue         = opcUaDataItem.NewValue;
                opcUaDataItem.NewValue         = notification?.Value.Value;
                opcUaDataItem.OpcUaStatusCodes = (OpcUaStatusCodes)notification?.Value.StatusCode.Code;
                OpcUaDataEventArgs args = new OpcUaDataEventArgs(opcUaDataItem.OpcUaStatusCodes, opcUaDataItem);
                OnDataChanged?.BeginInvoke(this, args, new AsyncCallback((a) =>
                {
                    if (a.IsCompleted)
                    {
                        OnDataChanged?.EndInvoke(a);
                    }
                }), null);
            }
        }