12-15-2008 11:58 AM
Hello,
I am attempting to read 8 channels of analog input data. The analog waveform is a 60Hz AC voltage, and I want to read 500 samples at 5kHz. Then, I want to use the 500 samples to compute the RMS voltage for each channel. I have successfully been able to do so, however, the acquisition time is way too long (about 3 seconds per update).
Here is the code:
public void UpdateVoltages()
{
try
{
Console.WriteLine("begin read...");
// capture the waveform for each channel (for increased performance)
voltageReader.BeginReadWaveform(500, new AsyncCallback(voltageWaveformReadCallback), null);
DAQtimer.Stop();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
StopDAQ();
}
and the callback:
private void voltageWaveformReadCallback(IAsyncResult result)
{
try
{
Console.WriteLine("Read waveform begin...");
AnalogWaveform<Double>[] voltageWaveform = voltageReader.EndReadWaveform(result);
Console.WriteLine("Read waveform completed");
int i = 0;
while (i < voltageWaveform.Length)
{
double rmsValue = NationalInstruments.Analysis.Math.Statistics.RootMeanSquared(voltageWaveform[i].GetRawData());
RMSvoltages.SetValue(rmsValue, i);
i++;
}
DAQtimer.Start();
Console.WriteLine("end RMS calc...");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
StopDAQ();
}
}
RMSvoltages is an Array of doubles used to store the RMS values for each of the 8 channels I want to read. Once again, I am receiving accurate data...however, the refresh time is way too long for my application. I have identified the statement in the code that takes the longest time to execute. The statement, voltageReader.BeginReadWaveform(500,......) is what takes nearly 3 seconds to execute. What can I do to speed up the reading time of the analog waveforms?
Thank you for your assistance.
-Eric
12-17-2008 11:29 AM
Hi Eric,
What version of Visual Basic and .NET are you using? I would try to run one of the DAQmx shipping examples to see if that helps the performance of the program. If you can run one of the examples to acquire the same amount of samples on the same number of channels then we will be able to tell a little better where the slow down is coming from.
The latest version of the example that you can run is in the following file path. If you have a previous version of .NET you can follow the same file path but the folder DotNet3.5 will just be something like DotNet2.5, etc.
C:\Documents and Settings\All Users\Documents\National Instruments\NI-DAQ\Examples\DotNET3.5\Analog In\Measure Voltage\AcqVoltageSamples_IntClk\cs
This example is set up to only acquire from one channel but you can modify it to be ai0:n. Give this a try to see if it behaves the same way. This would atleast show if it an issue with the acquisition.
Chris W