Do I want to realize A function in c #, A node is opcua server inside content have change, immediately get the node data, I checked on the net, need to use data subscription function, here is my code, but run into m_OpcUaClient. AddSubscription (" A ", "ns=2; S=those/Machine/B TestValueFloat ", SubCallback);
After this time, can't jump SubCallback () this method, to quote the following error
System. NullReferenceException: "the object reference not set to an instance of an object,"
The code is as follows:
Private OpcUaClient m_OpcUaClient;
Private void button4_Click (object sender, EventArgs e)
{
//sub
M_OpcUaClient. AddSubscription (" A ", "ns=2; S=those/Machine/B TestValueFloat ", SubCallback);
}
Private void SubCallback (string key, MonitoredItem MonitoredItem, MonitoredItemNotificationEventArgs args)
{
If (InvokeRequired)
{
Invoke (new Action
return;
}
If (key=="A")
{
//if there are multiple subscription values are associated with the current method, can distinguish by key and monitoredItem
MonitoredItemNotification notification=args. NotificationValue as MonitoredItemNotification;
If (notification!=null)
{
TextBox1. Text=notification. Value. WrappedValue. Value. The ToString ();
}
}
}
CodePudding user response:
System. NullReferenceException: "the object reference not set to an instance of an object,"Where the error is thrown?