I have an 8 channel analog input board (NI PXI-4472) that allows all 8 channels to be sampled simultaneously. I've written code in C# that reads the data. I implemented a callback. My goal is to read 8 channels where each channel is sampled at 16000 samples/second. I setup a buffer to hold 16000 bytes. When the callback gets called, I immediately read the data using EndReadMultiSample and start the callback again using BeginReadMultiSample. What I expect to happen is that if I am doing a continuous read using 16000 samples per second and have a buffer of 16000 bytes, the callback should only get called every second. That is what I want. What actually is happening is that the callback is getting called thousands of times within a second. I can't figure that out. How can I get my call back to execute continuously every second and give me exactly 16000 samples for each channel? Below is the code I wrote...
Thanks,
Johann
private AnalogMultiChannelReader aiReader = null;
// Configure a task
public class NIPXI4472 : Task
{
public NIPXI4472() : base("NIPXI4472")
{
this.Configure();
}
public virtual void Configure()
{
CreateVoltageChannel("PXI1Slot4/ai0", "Voltage0", Pseudodifferential, -5, 5, Volts);
CreateVoltageChannel("PXI1Slot4/ai1", "Voltage1", Pseudodifferential, -5, 5, Volts);
CreateVoltageChannel("PXI1Slot4/ai2", "Voltage2", Pseudodifferential, -5, 5, Volts);
CreateVoltageChannel("PXI1Slot4/ai3", "Voltage3", Pseudodifferential, -5, 5, Volts);
CreateVoltageChannel("PXI1Slot4/ai4", "Voltage4", Pseudodifferential, -5, 5, Volts);
CreateVoltageChannel("PXI1Slot4/ai5", "Voltage5", Pseudodifferential, -5, 5, Volts);
CreateVoltageChannel("PXI1Slot4/ai6", "Voltage6", Pseudodifferential, -5, 5, Volts);
CreateVoltageChannel("PXI1Slot4/ai7", "Voltage7", Pseudodifferential, -5, 5, Volts);
this.Timing.ConfigureSampleClock("", 16000, Rising, ContinuousSamples, 16000);
}
}
// Create a task
NIPXI4472 task = new NIPXI4472();
this.aiReader = new AnalogMultiChannelReader(task.Stream);
//Acquire samples
IAsyncResult handle = this.aiReader.BeginReadMultiSample(-1, new AsyncCallback(OnSamplesAcquiredCallback), null);
...
// The callback that gets called continuously. Should get called once a second.
public void OnSamplesAcquiredCallback(IAsyncResult i)
{
//Retrieve the data that was read.
double[,] data = this.aiReader.EndReadMultiSample(i);
IAsyncResult handle = this.aiReader.BeginReadMultiSample(-1, new AsyncCallback(OnSamplesAcquiredCallback), null);
}