07-09-2009 06:02 AM
Hello!
I am trying to create a windows form application with visual studio 2008 that allows me to acquire signals from NI USB 6009 and store data into a network variable. Data type that results from my acquisition is AnalogWaveform<double>[]. Then I want to view that acquisition using a thin client application developed with ASP.NET 3.5 and Measurement Studio 8.6 Enterprise on a simple waveform graph. The problem appers in my presentation stage, on ploting the waveform on the graph...in Autorefresh's Refresh function. I saw some examples on Data Acquisition with Network Variable....but the acquisition there was software simulated.
I need some help with the Refresh function, when I'm supposed to plot the data from my network variable.
In the example code from NI I found a member for the GraphWaveform called DataBind, but in NI MS 8.6 I can't find that anymore....
Solved! Go to Solution.
07-10-2009 08:40 AM
You will need to Add a Network Variable Data Source to the Designer, select Edit Bindings and bind to the network variable you want to be displayed on your Measurement Studio Waveform Graph.
Then you can add a FormView control to the Designer and set the Data Source to the Network Variable Data Source control that you just added. You can then select Edit Templates in the FormFiew smart tag and add controls that you want to be visible on the web site.
You can delete the populated binding that appears by default. Drag the Measurement Studio Waveform graph into this FormView control and select Edit DataBindings on the Waveform Control.
Here you can specify the binding to the variable that you configured in the Network Variable Data Source.
You can now select End Template Editing for the FormView Control.
To AutoRefresh the Controls in the Form View, add a Measurement Studio AutoRefresh control to the Designer and select Edit Default Refresh Items.
Select Add and TYPE the name of the Waveform Graph control that was added to the FormView control.
Select Debug»Start without Debugging. Your Waveform Graph should now bind the network variable and automatically refresh on the web page.
Should you want to refresh pragmatically you can reference the Measurement Studio User Manual Chapter 5 Walkthrough:Walkthrough: Creating a Measurement Studio Application with Web Forms Controls and Network Variable
-Adri Kruger
07-10-2009 10:07 AM
Thanks for the idea, I've tried that before and no result.
My WindowsForms application for the acquisition code looks like:
[...]
#region vars
private string _networkVariablePath;
public NetworkVariableWriter<AnalogWaveform<double>[]> myNetworkVariableWriter;
#endregion
public void Initialization()
{
_networkVariablePath = @"\\localhost\system\myVariable";
myNetworkVariableWriter = new NetworkVariableWriter<AnalogWaveform<double>[]>(_networkVariablePath);
myNetworkVariableWriter.Connect();
}
[...]
private void daqTaskComponent1_DataReady(object sender, DaqTaskComponentDataReadyEventArgs e)
{
NationalInstruments.AnalogWaveform<double>[] acquiredData = e.GetData();
myNetworkVariableWriter.WriteValue(acquiredData);
waveformGraph1.PlotWaveforms(acquiredData);
}
[...]
I have a continuous data acquisition there and that part is working properly.
My problem appears at ploting data on the waveformgraph
Help please 😞
Thanks a lot
07-10-2009 12:44 PM
07-10-2009 01:10 PM
07-13-2009 05:12 PM - edited 07-13-2009 05:14 PM
KarinaA,
I just tested the code Adri posted, and all I had to do was publish the live data to a network variable, then bind the Waveform Graph to that variable. All I had to do was to open the code by going to File»Open»Web Site, then select the ReadingNetworkVariable folder. This opened the ReadingNetworkVariable project. I then selected the "NetworkVariableDataSource" item at the top of the Default.aspx designer page, clicked on the arrow to the right of it and selected "Edit Bindings". From there I could modify the Location property of Bindin1 to be my variable. After that, I just ran the webpage and it worked. What problems are you seeing?
EDIT: I should note that I was using live data. I had a simple VI reading in data from a DAQ card and publishing it to a network variable.
07-22-2009 07:31 AM - edited 07-22-2009 07:34 AM
I found a solution
private void Acquisition()
{
if (_runningTask == null)
{
try
{
_myTask = new Task();
_myTask.AIChannels.CreateVoltageChannel(textBox1.Text,"", AITerminalConfiguration.Differential, Convert.ToDouble("-10"),
Convert.ToDouble("10"), AIVoltageUnits.Volts);
_myTask.Timing.ConfigureSampleClock("",numericEdit2.Value, SampleClockActiveEdge.Rising,
SampleQuantityMode.ContinuousSamples, Convert.ToInt32(numericEdit1.Value));
_myTask.Control(TaskAction.Verify);
_runningTask = _myTask;
_myTask.Stream.ReadOverwriteMode =
ReadOverwriteMode.OverwriteUnreadSamples;
myAnalogSingleChannelReader = new
AnalogSingleChannelReader(_myTask.Stream);
analogCallback = new
AsyncCallback(MyAnalogSingleChannelReaderCallback);
myAnalogSingleChannelReader.BeginReadMultiSample(Convert.ToInt32(numericEdit2
.Value), analogCallback, _myTask);
}
catch (DaqException exception)
{
MessageBox.Show(exception.Message);
_myTask.Dispose();
this.switch1.Value = false;
}
}
}
private void MyAnalogSingleChannelReaderCallback(IAsyncResult
asyncresult)
{
try
{
if (_runningTask == asyncresult.AsyncState)
{
_myData =
myAnalogSingleChannelReader.EndReadMultiSample(asyncresult);
long newSamples =
_myTask.Stream.TotalSamplesAcquiredPerChannel -
_myTask.Stream.CurrentReadPosition;
if (newSamples <
_myTask.Stream.AvailableSamplesPerChannel)
{
_myTask.Stream.ReadRelativeTo =
ReadRelativeTo.CurrentReadPosition;
_myTask.Stream.ReadOffset = 0;
}
else
{
_myTask.Stream.ReadRelativeTo =
ReadRelativeTo.MostRecentSample;
_myTask.Stream.ReadOffset = -
(int)_myTask.Stream.AvailableSamplesPerChannel;
}
this.textBox6.Text = "Writing to DoubleArray...";
myBufferedWriter.WriteValue(_myData);
waveformGraph1.PlotY(_myData);
myAnalogSingleChannelReader.BeginReadMultiSample(Convert.ToInt32(numericEdit2
.Value), analogCallback, _myTask);
}
}
catch (DaqException exception)
{
MessageBox.Show(exception.Message);
_runningTask = null;
_myTask.Dispose();
}
}