From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing an element from a double[] network data variable

I have a double[] network data variable and am trying to access individual elements of the array in a web form so that I can populate a number of NumericEdit components.
 
When I try and access the network data variable in the AutoRefresh event using
double[] data = (double[])NetworkVariableDataSource1.Bindings[1].GetValue();
 
I get the exception
Unable to cast object of type 'System.String' to type 'System.Double[]'.
 
I know how to populate a waveform graph with the double[] network variable but am not sure how to access the double[] directly?
 
Thanks
 
Adam
0 Kudos
Message 1 of 2
(2,837 Views)
Ok. What is happening is if the read fails (no data avaliable, no connection established) the DataSource tries to get the default value specified in NetworkVariableBinding.DefaultReadValue. This is a string if set in the designer. So what is happening is, you are probably getting the DefaultReadValue you set in the read and it is a string of some value and cannot be explicitly converted to a double[] value (we added the NetworkVariableBinding.BindingType property to convert some most used values like Double, Boolean, but not every possible value like double[]). To verify this you can hook up to the ReadFailed event of the NetworkVaraibleDataSource and check the value of the FailureCause property in the args (it tells whether there is nodata or the connection is unconnected). You can also set the Value property of those args to an empty double[] like this say, new double[0]. This value will be used as the new default value when a read fails. This allow you to change the default read value dymanically depending on what the failure was.
 
Brock
0 Kudos
Message 2 of 2
(2,828 Views)