07-16-2007 01:24 PM
Hi,
I am using DAQmx 8.5 to control a NI9215 USB 4 channel analog to digital converter.
I have written a program (using C# 2.0) that uses the Measurement Studio .NET Class Library.
I am Aynchronously reading the analog input channels at 15000 samples per second using an AnalogMultiChannelReader. The BeginReadMultiSample / EndReadMultiSample methods are called ten times per second. I call the task Control method to set the state to Commit before I start the task by calling BeginReadMultiChannel. To stop the task I am calling the task Stop method in the asynchronous callback method that I supply to BeginReadMultiChannel.
I have found that if I repetitively start and stop the task that reads the analog input channels, it eventually fails with either a DaqException (Onboard Device memory overflow) or a AccessViolationException.
When I have configured all 4 channels to be used, I can successfully start and stop the data collection task 8 times before subsequent task starts will result in a failure. When I have configured 1 channel to be used, I can successfully start and stop the data collection task just 2 times before the subsequent task start will result in a failure.
Is this a bug or am I not using the library the correct way?
Any help is appreciated,
Thanks,
Dave McDonald
07-16-2007 05:07 PM
namespace DataAcqTest
{
public partial class MainForm : Form
{
private Task _AcqTask;
private AnalogMultiChannelReader _Reader;
private AsyncCallback _SampleBufferFilled;
private Boolean _ContinueRunning;
private readonly Double _SampleRate = 15000.0;
private readonly Int32 _NumSamplesToReadAtATime = 1500;
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
_SampleBufferFilled = new AsyncCallback(this.SampleBufferFilled);
_AcqTask = new Task("DemoAnalogInTask");
for (int i = 0; i < 4; i++)
{
_AcqTask.AIChannels.CreateVoltageChannel("NI-9215-1/ai" + i.ToString(),
"",
AITerminalConfiguration.Differential,
-10.0,
+10.0,
AIVoltageUnits.Volts);
}
_AcqTask.Timing.ConfigureSampleClock(String.Empty, // signal source is internal clock
_SampleRate,
SampleClockActiveEdge.Rising,
SampleQuantityMode.ContinuousSamples,
_NumSamplesToReadAtATime);
_AcqTask.Control(TaskAction.Commit);
_Reader = new AnalogMultiChannelReader(_AcqTask.Stream);
_Reader.SynchronizeCallbacks = true;
_StopBtn.Enabled = false;
}
private void StartBtn_Click(object sender, EventArgs e)
{
_ContinueRunning = true;
_StartBtn.Enabled = false;
_StopBtn.Enabled = true;
_Reader.BeginReadMultiSample(_NumSamplesToReadAtATime,
_SampleBufferFilled,
null);
}
private void StopBtn_Click(object sender, EventArgs e)
{
_ContinueRunning = false;
_StopBtn.Enabled = false;
}
private void SampleBufferFilled(IAsyncResult ar)
{
Double[/*channel*/, /*sample*/] channelsSamples = _Reader.EndReadMultiSample(ar);
if (_ContinueRunning)
{
_Reader.BeginReadMultiSample(_NumSamplesToReadAtATime,
_SampleBufferFilled,
this);
}
else
{
_AcqTask.Stop(); // Goes to the committed state
_StartBtn.Enabled = true;
}
}
}
}
07-17-2007 04:28 PM
07-25-2007 10:06 PM
01-13-2008 02:29 PM
02-11-2008 09:13 AM
02-12-2008 10:31 AM
02-14-2008 06:42 AM
02-15-2008 03:03 PM
03-11-2008 08:54 AM