Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Application is unable to keep up with hardware acquisition in continuous generation

Hello,

Error: -200279

I am currently designing a digital filter for sensor smoothing using the USB-6002 programmed on Visual C#. I keep getting the error "application is unable to keep up with hardware acquisition". I have tried decreasing the sample rate, removing UI updates, increasing number of samples to read however, the problem persists. I am aware that this is because I am not reading from the PC Buffer fast enough but how do I increase the read speed? Below is the source code:

using System;
using System.Data;
using System.Windows.Forms;
using NationalInstruments.DAQmx;
namespace filterFaster
{
public partial class Form1 : Form
{
private Task analogInTask;
private AnalogSingleChannelReader analogInReader;
private AsyncCallback analogCallback;
private AIChannel myAIChannel;
private Task runningTask;
private NationalInstruments.AnalogWaveform<double> data;
double currX = 0;
double currY = 0;
double prevX = 0;
double prevY = 0;
int count = 0;
double time = 0;
private DateTime value;
private DateTime value2;
private TimeSpan interval;

bool first = true;
public Form1()
{
InitializeComponent();
initializeChart();
}
private void initializeChart()
{
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
chart1.ChartAreas[0].RecalculateAxesScale();
chart1.ChartAreas[0].AxisY.Maximum = Double.NaN;

chart1.ChartAreas[0].CursorY.AutoScroll = true;

chart1.ChartAreas[0].AxisY.ScrollBar.Size = 15;
chart1.ChartAreas[0].AxisY.ScrollBar.IsPositionedInside = true;
chart1.ChartAreas[0].AxisY.ScrollBar.Enabled = true;


chart1.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;

}

private void startButton_Click(object sender, EventArgs e)
{
if (runningTask == null)
{
try
{

startButton.Enabled = false;

// Create a new task
analogInTask = new Task();

// Create a virtual channel
analogInTask.AIChannels.CreateVoltageChannel("dev2/ai0", "AIChannel",
AITerminalConfiguration.Rse, 0,
5, AIVoltageUnits.Volts);

// Configure the timing parameters
analogInTask.Timing.ConfigureSampleClock("", 48000,
SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples);
analogInTask.Stream.Buffer.InputBufferSize=100000;
// Verify the Task
analogInTask.Control(TaskAction.Verify);

// Prepare the table for Data


runningTask = analogInTask;
analogInReader = new AnalogSingleChannelReader(analogInTask.Stream);
analogCallback = new AsyncCallback(AnalogInCallback);

// Use SynchronizeCallbacks to specify that the object
// marshals callbacks across threads appropriately.
analogInReader.SynchronizeCallbacks = true;
value = DateTime.Now;
analogInReader.BeginReadWaveform(Convert.ToInt32(1),
analogCallback, analogInTask);
}
catch (Exception exception)
{
// Display Errors
MessageBox.Show(exception.Message);
runningTask = null;
analogInTask.Dispose();
startButton.Enabled = true;
}

}
}

private void AnalogInCallback(IAsyncResult ar)
{
try
{
if (runningTask != null && runningTask == ar.AsyncState)
{
// Read the available data from the channels

data = analogInReader.EndReadWaveform(ar);

// Plot your data here
currY = data.Samples[0].Value;
interval=data.Samples[0].TimeStamp.Subtract(value);
time = interval.TotalSeconds;
//fc=1000Hz , fs=48kHz Butterworth

currX = 0.877 * prevX + 0.0615*currY+ 0.0615* prevY;

//fc=100Hz, fs=48kHz
//currX=0.987*prevX+0.0065*currY+0.0065*prevY;

chart1.Series[0].Points.AddXY(time, currY);
chart1.Series[1].Points.AddXY(time, currX);
chart1.ChartAreas[0].RecalculateAxesScale();
if (chart1.Series[0].Points.Count > 200)
{
chart1.Series[0].Points.RemoveAt(0);
chart1.Series[1].Points.RemoveAt(0);
chart1.ChartAreas[0].AxisX.Minimum = chart1.Series[0].Points[0].XValue;
chart1.ChartAreas[0].AxisX.Maximum = time;

}
prevX = currX;
prevY = currY;

analogInReader.BeginMemoryOptimizedReadWaveform(1,
analogCallback, analogInTask, data);


}
}
catch (Exception exception)
{
// Display Errors
MessageBox.Show(exception.Message);
runningTask = null;
analogInTask.Dispose();
startButton.Enabled = true;
}
}
private void displayData(NationalInstruments.AnalogWaveform<double> data)
{
for(int i = 0; i < data.SampleCount; i++)
{
currY = data.Samples[i].Value;
interval = data.Samples[i].TimeStamp.Subtract(value);
time = interval.TotalSeconds;
//fc=1000Hz , fs=48kHz Butterworth

currX = 0.877 * prevX + 0.0615 * currY + 0.0615 * prevY;

//fc=100Hz, fs=48kHz
//currX=0.987*prevX+0.0065*currY+0.0065*prevY;

chart1.Series[0].Points.AddXY(time, currY);
chart1.Series[1].Points.AddXY(time, currX);
chart1.ChartAreas[0].RecalculateAxesScale();
if (chart1.Series[0].Points.Count > 200)
{
chart1.Series[0].Points.RemoveAt(0);
chart1.Series[1].Points.RemoveAt(0);
chart1.ChartAreas[0].AxisX.Minimum = chart1.Series[0].Points[0].XValue;
chart1.ChartAreas[0].AxisX.Maximum = time;

}
prevX = currX;
prevY = currY;
}
}
}
}

 

0 Kudos
Message 1 of 4
(1,159 Views)

Hi Mohammed,

 


Mohammed@Saeed wrote:

Error: -200279

 

I am aware that this is because I am not reading from the PC Buffer fast enough but how do I increase the read speed?


The usual recommendation in LabVIEW is: instead of reading just one sample you should read blocks of samples. Blocksize is recommended to 1/10 of samplerate to result in a loop iterating at 10Hz…

 

Maybe you should ask in the CVI forum where people are discussing C code?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 4
(1,156 Views)

I moved this thread from the LabVIEW board to the DAQ board, where it can hopefully get better help.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 4
(1,126 Views)

Hello,

Yes, your recommendation worked however some of lines of code cannot be executed for each data sample such as recalculating axes scales and these seem to take too long of a time for the data acquisition leading to the same error. 

0 Kudos
Message 4 of 4
(1,076 Views)