Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

ASP .NET web charting example

 
Dear National Instruments,
I am attempting to build an ASP.NET web interface similar to the graph charting example in the Measurement Studio ASP.NET Demonstration Gallery. I have made heavy reference to the Create Thin-Client Remote Monitoring and Control Applications webcast, which demonstrates plotting arrays of data from a network variable source. I would like to read a single value (double)data from a network variable and do a
 
protected void AutoRefresh1_Refresh(object sender, RefreshEventArgs e)
{
      WaveformGraph1.PlotYAppend(data);
}
 
Can you point me to an example of how to do this or make the Measurement Studio ASP.NET Demonstration Gallery source code available for the graph charting example?
Thanks,
Ben Gross
Purdue University
0 Kudos
Message 1 of 18
(7,244 Views)
Hello benovice,

I'm glad that our demonstration gallery and webcasts have been helpful to you.  If you are trying to read a single value from a network variable, you can use the ReadData() method of your Network Variable subscriber object and return the result to a NetworkVariableData object, as in the code below.  Have you tried this approach?  If you are experiencing an error when trying to do this, please post back with details.  I hope that helps.

NetworkVariableData readData = subscriber.ReadData();
Regards,


Marty H.
National Instruments
0 Kudos
Message 2 of 18
(7,213 Views)
I've still got a few questions about this approach:
1. Where in the code do I create a new instance of the NetworkVariableBufferedSubscriber<double> subscriber object? I tried creating a new instance at the page level, but further calls to subscriber.ReadData() threw a NullReferenceException. Should I instantiate the subscriber object at the page level, session level, or application level? Also, I'm worried about worried about putting the ReadData() method in the auto refresh event handler - doesn't this approach tie up the application as it waits for data to come in over the network?
protected void AutoRefresh1_Refresh(object sender, RefreshEventArgs e)
{
//read the data from the network variable
NetworkVariableData<double> networkData = m_bufferedSubscriber.ReadData();
//also plot the data, code not shown here
}
Any help would be greatly appreciated. -Ben Gross, Purdue University
 
0 Kudos
Message 3 of 18
(7,140 Views)
Hello Ben,

The scope of your NetworkVariableBufferedSubscriber<double> subscriber object should be determined by the range of breadth over which your object is used.  In other words, if you are using this object within only one function, it could be declared within that function, but if you use it in multiple functions, it must be declared outside of that function.  If you are using the object beyond the single page level, it must be declared at the session level, and if you use it beyond the single session level, it must be declared globally at the application level.

To track down the NullReferenceException that is thrown, I would recommend creating a watch for that variable and then debugging your code with breakpoints and stepping to determine at what point the variable loses its data.  Again, you will also want to make sure that it is declared at a high enough scope.

I think it makes sense to put the ReadData() function into it's own function, rather than the auto refresh event handler.  You can then call that function as often as you like.  You might want to call this function at a set timing interval, so that you know exactly how often you are reading data.  I hope that helps.
Regards,


Marty H.
National Instruments
0 Kudos
Message 4 of 18
(7,121 Views)

Hi Ben,

Actually the best choice in your case is to use the NetworkVariableDataSource which was designed to work within an ASP.NET web page.  It actually encapsulates a NetworkVariableWriter and NetworkVariableBufferedSubscriber.  The NetworkVariableDataSource is very easy to use and we take care of any issue's that might arise when dealing with the ASP.NET page life cycle.  Refer to the Using the Measurement Studio Network Variable Data Source in Web Forms help topic in the NI Measurement Studio Help. We also have an exmaple pgoram located in the Documents and Settings\All Users\Documents\National Instruments\MStudioVS2005\DotNET\Examples\NetworkVariable\Basic. This solution contains several network variable projects, one of which using the data source.

Hope this helps!

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 5 of 18
(7,112 Views)
Hello,
Using the NetworkVariableDataSource, I was able to get my application to work. My AutoRefresh event handler looks like this:

protected

void AutoRefresh1_Refresh(object sender, RefreshEventArgs e)

{

double data = (double)NetworkVariableDataSource1.Bindings[0].GetValue();

NumericEdit1.Value = data;

WaveformGraph1.PlotYAppend(data);

}

 Lets say I'm writing to the network variable calling

NetworkVariableBufferedWriter

<double>.WriteValue( double data)

once every 250 ms, and my AutoRefresh interval is 1 s; only 1 value / second is plotted on the WaveformGraph. Is there a buffer in NetworkVariableDataSource that can be flushed to the WaveformGraph in the AutoRefresh_refresh(object sender, RefreshEventArgs e) event handler? I'd like to flush a buffer to the WaveformGraph rather than plotting the most recent value. Using your Basic NetworkVariable example and calling

WaveformGraph1.BindingData = NetworkVariableDataSource1.Bindings[0].GetValue();

doesn't work for my application; I'm writing only one double value at a time to the NetworkVariable whereas the Basic example writes a  double[] array to the NetworkVariable. In any case, this is a fairly minor issue and I appreciate your help in getting my Thin Client Monitoring application up and running. -Ben Gross, Purdue 

0 Kudos
Message 6 of 18
(7,084 Views)
Hi Ben,

Check out the help topic Best Practices for Graphing and Charting in a Measurement Studio WebForms Application in the NI Measurement Studio Help. This should answer your question.

Best Regards,
Jonathan N.
National Instruments
0 Kudos
Message 7 of 18
(7,082 Views)
Dear NI,
I am attempting two way binding with a web based ASP .NET knob control and a Windows knob control. The control behavior I want is more or less equal access to the knob control from the Web application  and from a Windows application (with the Windows app having priority). I get the correct behavior on the Windows form application, but the knob doesn't maintain its value in the Web Forms app (I've attached my best effort code). Do you have an example of how to synchronize Measurement Studio ASP .NET numeric knob or slide controls with a Measurement Studio Windows forms application?
-Ben Gross
Purdue University
 
0 Kudos
Message 8 of 18
(6,955 Views)

Hi Ben,

I reviewed your ASP.NET application and your windows application and discovered the problem which happens to be with your coding logic.  If you run through your ASP.NET logic by hand (which I recommend if you’re having trouble visualizing how your ASP.NET app works), it’s easy to see why the knob is going back to its previous state.  Essentially, you are reading from the "writer" variable in the statement
double newKnobData = (double)NetworkVariableDataSource1.Bindings[0].GetValue();

which is only being updated in the knob1_AfterChangeValue event handler in your windows application.  When you compare this value to the current knob value, it will always be different and thus you will execute the statement of
Knob1.Value = newKnobData.  This in turn reverts your knobs value back to its previous state.  Therefore you need to add the statement of m_ampControlWriter.WriteValue(knob1.Value); in your m_ampControlReader_DataUpdated event handler in your windows application. There is multiple ways you could have debugged this problem either by hand logic, using Debug.WriteLines or even using Firebug if you are using Firefox. 

Another problem you were running into which you can't directly see because of improper exception handling is that you have 2 writers writing to the same variable which isn't allowed with implicit creation. Implicit variables always have the single-writer restriction.  This restriction would have been caught if you were actually catching NetworkVariable exceptions.  For example, when you call the WriteValue method inside of your knob1_AfterChangeValue event handler, if you were catching exceptions, you would have received an exception that basically stated  "A general access denied error occurred".  So the solution to this problem is to either not have multiple writers or use explicit variable creation via using Variable Manager.

In my opinion I believe you should be catching those exceptions and not ignoring them.  So I definitely recommend you change this practice and appropriately handle exceptions. Just my thoughts...

As a side note, we don't document this restriction and so I will make sure we add this in the future. 

Best Regards,

Jonathan N.
National Instruments
0 Kudos
Message 9 of 18
(6,931 Views)
 

Hey,

Thanks for looking over my code and helping to get my ASP .NET Measurement Studio application up and running.

Now I'm trying to run the web application on a remote web server. According to  Create Thin-Client Remote Monitoring and Control Applications webcast, the requirements are: IIS 5.0 or later, Windows 2000 / 2003 server and Windows XP Pro or Windows 2000, and .NET framework 1.1 or 2.0 . My web hosting service, www.hostmysite.com, easily meets all of these requirements (.NET framework 2.0, Windows 2003 Server). When I simply use Visual Studio 2005 to publish my ASP .NET web site, the site is precompiled and sent to the web server but the web server is unable to render the web page. I assume that its because the National Instruments assemblies do not exist on my web server. What's the best way around this situation?

-Ben Gross   

0 Kudos
Message 10 of 18
(6,899 Views)