12-05-2012 10:30 AM
Hi,
I've looked around but haven't been able to find example code for single asynchronous read of multiple waveforms. Could someone point me in the right direction?
Thanks,
Dale
Solved! Go to Solution.
12-06-2012 12:55 PM
Hi Dale,
If you are trying to read multiple channels, you can take any example and list multiple channels in the "Physical Channel" input. For example, in the .NET 4.0 example for acquiring one analog voltage sample, I simply specified "Dev3/ai0, Dev3/ai1, Dev3/ai2" and got three samples, one from each channel. The only trick is to ensure that the code is prepared to accept multiple values. In the example above, there is a section that formats the data table based on the number of channels to be read.
Hope this helps!
-Alexandra
12-06-2012 03:38 PM
Hi Alexandra,
Thanks for the reply, but the source of my difficulty is more with asychronous reading. Using "\NI-DAQ\Examples\DotNET2.0\Analog In\Measure Voltage\AcqOneVoltageSample\cs\AcqOneVoltageSample" as a reference, the call on line 349 double[] data = reader.ReadSingleSample(); is synchronous.
I think I need to do something like reader.BeginReadWaveform(aiTaskNumberOfSamples, aiAsyncCallback, aiTask);. Unfortunately, in my method AnalogInCallback(IAsyncResult ar) at the call to AnalogWaveform<double>[] data = reader.EndReadWaveform(ar); I get
NI Platform Services: The specified resource is reserved. The operation could not be completed as specified.
Task Name: _unnamedTask<2>
Status Code: -50103
Now I have to admit, I haven't done much investigation on the error code. I thought I would be lazy efficient and ask you guys for some sample code to get me started in the right direction.
Cheers,
Dale
Thanks
12-06-2012 04:26 PM
Hi Dale,
Have you looked at the example code in the .NET Framework DAQmx help? It shows this code:
class DAQmxAsyncRead
{
private AnalogSingleChannelReader reader = null;
public DAQmxAsyncRead(Task t)
{
//Create the reader
reader = new AnalogSingleChannelReader(t.Stream);
//Acquire 100 samples
IAsyncResult handle = reader.BeginReadMultiSample(100,new AsyncCallback(OnDataReady),null);
}
public void OnDataReady(IAsyncResult i)
{
//Retrieve the data that was read.
//At this point, any exceptions that occurred during the asynchronous read are thrown
double[] data = reader.EndReadMultiSample(i);
//You can call the BeginReadMultiSample method here again
}
}
Also, this article: http://digital.ni.com/public.nsf/allkb/485201B647950BF886257537006CEB89?OpenDocument talks about the different causes of the resource reserved error.
Regards,
Alexandra Valiton
12-06-2012 05:19 PM
Hi Alexandra,
Thanks for the sample!
Cheers,
Dale
12-06-2012 05:21 PM
Hi Dale,
Glad I could help! Check for more help in the .NET Framework Help located at Start>Programs>National Instruments>NI-DAQmx>Text-Based Code Support
Best of luck in your development!
Alexandra