Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Example code for single asynchronous read of multiple waveforms

Solved!
Go to solution

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

0 Kudos
Message 1 of 6
(6,673 Views)

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

National Instruments
Applications Engineer
0 Kudos
Message 2 of 6
(6,661 Views)

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

 

0 Kudos
Message 3 of 6
(6,655 Views)
Solution
Accepted by topic author DaleBessette

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

National Instruments
Applications Engineer
0 Kudos
Message 4 of 6
(6,651 Views)

Hi Alexandra,

 

Thanks for the sample!

 

Cheers,

Dale

0 Kudos
Message 5 of 6
(6,647 Views)

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

 

 

National Instruments
Applications Engineer
0 Kudos
Message 6 of 6
(6,645 Views)