02-01-2011 07:28 AM
02-01-2011 07:47 AM
I can read a network variable when it has changed by using the following code
Public Class Form1
Private WithEvents SS_ThermoRec_Delay As NetworkVariableSubscriber(Of Double)
SS_ThermoRec_Delay = New NetworkVariableSubscriber(Of Double)("\\192.168.10.2\SS_Real Time Variable Library\SS_ThermoRec_Delay")
SS_ThermoRec_Delay.Connect()
Private Sub SS_Pulse_Type_Data_Updated(ByVal sender As System.Object, ByVal e As NationalInstruments.NetworkVariable.DataUpdatedEventArgs(Of Int32)) Handles SS_Pulse_Type.DataUpdated SS_txtPulseType.Text = e.Data.GetValue
End Sub
End Class
I appreciate I am being dumb but how do I just read a network variable I would like to say
Variable 1 = Variable 2 * SS_ThermoRec_Delay.Value
What is the call to get the data. I would preferably not use bindings cheers
02-01-2011 09:18 AM
Hello -
Instead of using a NetworkVariableSubscriber object, you should create a NetworkVariableReader object. Then you can get your data by calling reader.ReadData();
For more information, take a look at the OnDemandReader example located at:
<MeasurementStudio_version>\DotNET\Examples\NetworkVariable\Basic\vb\OnDemandReader
NickB
National Instruments
02-02-2011 11:19 AM
Thanks for that
So I can use the variables for event as well as read them I have made a subscriber and a reader as I have tried the following code and had some issues:
Public Class Form1 Private WithEvents SS_ThermoRec_Delay As NetworkVariableReader(Of Double) SS_ThermoRec_Delay = New NetworkVariableReader(Of Double)("\\192.168.10.2\SS_Real Time Variable Library\SS_ThermoRec_Delay") SS_ThermoRec_Delay.Connect() Private Sub SS_ThermoRec_Delay_Reader_Data_Updated(ByVal sender As System.Object, ByVal e As NationalInstruments.NetworkVariable.DataUpdatedEventArgs(Of Int32)) Handles SS_ThermoRec_Delay_Reader.DataUpdated SS_ThermoRec_Delay_Reader.Text = e.Data.GetValue End Sub End Class
It doesn’t like the Handles SS_Pulse_Type.DataUpdated – it says Event ‘DataUpdated’ cannot be found
What I have therefore done is have a subscriber and a reader pointing at the same variable
Public Class Form1 Private WithEvents SS_ThermoRec_Delay_Reader As NetworkVariableReader(Of Double) SS_ThermoRec_Delay_Reader = New NetworkVariableReader(Of Double)("\\192.168.10.2\SS_Real Time Variable Library\SS_ThermoRec_Delay") SS_ThermoRec_Delay_Reader.Connect() Private WithEvents SS_ThermoRec_Delay_Subscriber As NetworkVariableSubscriber(Of Double) SS_ThermoRec_Delay_Subscriber = New NetworkVariableSubscriber(Of Double)("\\192.168.10.2\SS_Real Time Variable Library\SS_ThermoRec_Delay") SS_ThermoRec_Delay_Subscriber.Connect() Private Sub SS_ThermoRec_Delay_Subscriber_Data_Updated(ByVal sender As System.Object, ByVal e As NationalInstruments.NetworkVariable.DataUpdatedEventArgs(Of Int32)) Handles SS_ThermoRec_Delay_Subscriber.DataUpdated SS_ThermoRec_Delay.Text = e.Data.GetValue End Sub End Class
My problem is now I am still having trouble reading these pesky variables. I am trying the following code
Dim myVar As Double myVar = SS_ThermoRec_Delay_Reader.ReadData
I get the wiggly blue line under SS_ThermoRec_Delay_Reader.ReadData with the message ‘Value of type ‘NationalInstruments.NetworkVariableData(of Double)’ cannot be converted to ‘Double’.’
Anyone now how do a simple read? Any actual code would be appreciated
Thanks oh clever people
02-03-2011 08:23 AM
Hello -
Were you able to find the example I pointed you to? It is actual code that shows exactly how to get the actual data from the object returned by ReadData. Not only that, but there are many other examples there that should help you with the subscriber you're creating as well.
ReadData returns an object of type NetworkVariableData(of TValue). To get the actual data of the variable, you must call GetValue on the NetworkVariableData(of TValue) object.
NickB
National Instruments