C#实现OPCUA客户端数据订阅功能

已锁定

手机用户20190719290310

  • 帖子

    2
  • 精华

    0
  • 被关注

    0

论坛等级:新手

注册时间:2019-07-19

普通 普通 如何晋级?

C#实现OPCUA客户端数据订阅功能

2068

3

2019-07-20 06:48:18

求助各位:

        请问我要用C#实现一个功能,就是    opcua 服务器端一个节点里面内容有变化,立刻得到这个节点的数据。我网上查了,需要用数据订阅功能。下面是我代码,但是运行到      m_OpcUaClient.AddSubscription("A", "ns=2;s=Machines/Machine B/TestValueFloat", SubCallback);

这段后,跳转不到SubCallback()这个方法。报如下错误

System.NullReferenceException:“未将对象引用设置到对象的实例。”



 

代码如下:

private OpcUaClient m_OpcUaClient;

        private void button4_Click(object sender, EventArgs e)
        {
            // sub
          
            m_OpcUaClient.AddSubscription("A", "ns=2;s=Machines/Machine B/TestValueFloat", SubCallback);

        }


 private void SubCallback(string key, MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs args)
        {
            if (InvokeRequired)
            {
                Invoke(new Action<string, MonitoredItem, MonitoredItemNotificationEventArgs>(SubCallback), key, monitoredItem, args);
                return;
            }

            if (key == "A")
            {
                // 如果有多个的订阅值都关联了当前的方法,可以通过key和monitoredItem来区分
                MonitoredItemNotification notification = args.NotificationValue as MonitoredItemNotification;
                if (notification != null)
                {
                    textBox1.Text = notification.Value.WrappedValue.Value.ToString();
                }
            }
         
        }


C#实现OPCUA客户端数据订阅功能 已锁定
编辑推荐: 关闭

请填写推广理由:

本版热门话题

SIMATIC S7-1500系列

共有8664条技术帖

相关推荐

热门标签

相关帖子推荐

guzhang

恭喜,你发布的帖子

评为精华帖!

快扫描右侧二维码晒一晒吧!

再发帖或跟帖交流2条,就能晋升VIP啦!开启更多专属权限!

top
您收到0封站内信:
×
×
信息提示
很抱歉!您所访问的页面不存在,或网址发生了变化,请稍后再试。