Пример #1
0
        private void OpcUaClientHelper_OnDataChanged(object sender, OpcUaHelper.OpcUaDataEventArgs e)
        {
            Func <List <OpcUaClientHelper>, int, string> func = (a, b) =>
            {
                LogHelper.Logger.Debug("12113321");

                return("asd");
            };

            //DispatchingHandler = new dispatchingDelegate(dispatchingExecute);
            DispatchingHandler.BeginInvoke(sender, e, new AsyncCallback((a) =>
            {
                if (a.IsCompleted)
                {
                    try
                    {
                        bool result = DispatchingHandler.EndInvoke(a);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.Logger.Error("OPCUA数据回调错误", ex);
                    }
                }
            }), null);
        }
Пример #2
0
        private void OpcUaClienthelper_OnDataChanged(object sender, OpcUaHelper.OpcUaDataEventArgs e)
        {
            string message = DateTime.Now.ToString(dateString) + e.OpcUaStatusCodes + " " + (e.OpcUaDataItem == null ? " " : e.OpcUaDataItem.ToString()) + System.Environment.NewLine;


            try
            {
                //int.TryParse(e.OpcDataItem.OldValue.ToString(), out int old);
                //int.TryParse(e.OpcDataItem.NewValue.ToString(), out int newv);
                //if (old + 3 != newv)
                //{
                //    System.Diagnostics.Debug.Print($"值不连续{e.OpcDataItem.ToString()}");
                //}
                //else
                //{
                //    //System.Diagnostics.Debug.Print($"连续{e.OpcDataItem.ToString()}");
                //    WriteFile(message);

                //}

                asyncUpMessage(message);



                this.Dispatcher.Invoke(new Action(() =>
                {
                    var oldItem = opcUaDataItems.FirstOrDefault(a => a.Name == e.OpcUaDataItem.Name);

                    int index = opcUaDataItems.IndexOf(oldItem);
                    opcUaDataItems.Insert(index, e.OpcUaDataItem);
                    opcUaDataItems.Remove(oldItem);
                    gvOpcUaDataItems.ItemsSource = null;
                    gvOpcUaDataItems.ItemsSource = opcUaDataItems;
                }));



                //asyncUpOpcUaDataItems(this.opcUaClientHelper.OpcUaDataItems);

                //upOpcDataItemDelgate(e.OpcDataItem);
            }
            catch (AggregateException ex)
            {
                //asyncUpMessage(DateTime.Now.ToString(dateString) + ex.Message + System.Environment.NewLine);
            }
        }
Пример #3
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);
            }
        }