Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read in prallel from different AI lines ?

I am new to NI DAQ programming. I am struggling to get the concepts right. This question may be very simple to answer. I am trying to read from different AI lines at the same time using C#. I use multiple threads to create NI capture Tasks from different AI.

 

I noticed that NIDAQ reading would need to c

1) Create a Task


2) Create a voltage channel.


3) Configure sample clock.


4) Start the task.


5) Define a reader and read multiple samples.


7) Stop the task.

 

This task based model seems very asynchronous. When I try to create multiple tasks at the same time to read from different AI lines after a while it fails with an error - -50103 - The specified resource is reserved.

 

 

So far I read across and I found that I should be able to read simultaneously from different AI lines. Is my understanding in correct ? In such case, is it even possible to read from different AI channels at the same time ?

 

0 Kudos
Message 1 of 8
(3,108 Views)

Hi,

 

You can read multiple channels with one task.

 

//Create a task that will be disposed after it has been used
               
daqMultiTask = new Task();

                
daqMultiTask.AIChannels.CreateVoltageChannel("Dev1/ai0:4", "",
                    (AITerminalConfiguration)(-1), Convert.ToDouble(Global.Configuration.DAQ_RangeMin) ,
                    Convert.ToDouble(Global.Configuration.DAQ_RangeMax), AIVoltageUnits.Volts);

                
daqMultiTask.Timing.ConfigureSampleClock("", sampleRate , SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples,totalSamples);

                
//Verify the Task
daqMultiTask.Control(TaskAction.Verify);

daqMultiReader = new AnalogMultiChannelReader(daqMultiTask.Stream);


//Read the data from the channels

double[,] data = daqMultiReader.ReadMultiSample(totalSamples);


daqMultiTask.Dispose();

 

Curt

0 Kudos
Message 2 of 8
(3,090 Views)

Hello Curt_C,

 

It doesn't fulfil my requirement. To read from multiple channels I need to know the channels in advance. That is not possible in my case.

It is part of a complicated software system. The software system would generate requests to read from specific lines at randomly. I don't want to serialize this operation. That slows down the software. I can't even construct a muti-channel read request because - requests are random, sampling frequency may differ.

 

Is there a any way to achieve using NIDAQ ? Is the device even capable of performing operations like this ?

 

Thanks for responding!

 

 

0 Kudos
Message 3 of 8
(3,078 Views)

Is it a product limitation ? Can I reach NI tech support and get clarification on it?

0 Kudos
Message 4 of 8
(3,064 Views)

I don't know what device you have but on all the common NI DAQ boards I know of, only 1 timing engine is available for the AI subsystem.   This means that at any given time, there can be only 1 sample rate.   You can't sample at 1 rate for 1 channel while sampling at another rate for another channel.

 

Here's what you *could* do:  put all possible channels into the task and always sample at the highest expected rate.  When another part of the software requests data, serve up the channel(s) it requests.   One side or the other will have to then deal with processing the data down to the desired rate.

 

It's not perfect, but it can often work.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 5 of 8
(3,060 Views)

Thanks Kevin, we have many different kind of devices. We use them on a very high scale. However this is a common functionality we are trying to achieve.

 

Sampling rate isn’t a problem for me. I can manage that. But I cannot concert my single channel read to multiple channel read. I wouldn’t know which channels would be read at which point of time. We have 80 analog lines. I can be reading on 10 lines at some time and another 10 some other time. The high level software will manage that. 

 

Also, the error message that I get doesn’t suggest I cannot read from different likes at the same time. It only suggests that some resource is reserved. I am curious if people don’t try to read from different lines at the same time at all. It sounds like a very simple use case of the device.

0 Kudos
Message 6 of 8
(3,056 Views)

Very likely the resource that's reserved is the timing circuitry needed for hw-clocked AI sampling.   Error messages are often terse and often don't give the entire context related to the specific error in question.

 

The problem isn't that you're trying to read multiple channels -- Curt_C demonstrated a method to do that in msg #2.   The problem is that you're (apparently) trying to set up multiple hw-clocked tasks simultaneously on a single board.

 

Based on threads here on the forums, lots of people have wanted to have multiple independent hw-clocked AI tasks running at the same time on a board.  But they run into the same problem you're running into because the hardware isn't designed to support it.

 

Here are some things that *ARE* possible:

1. Simultaneous AI tasks without a hw clock.  These are considered software-timed, on-demand tasks.  You set them up by never making a call to DAQmx Timing.  You collect multiple samples by (rapidly) iterating over calls to DAQmx Read and accumulating the values in software.

2. Multiple AI tasks that are hardware-clocked but which DO NOT OVERLAP in time.  You can run any one at a time as needed.  

3. Multiple simultaneous hw-clocked tasks spread across multiple DAQ boards.  One task per board.  Parallel wire the "popular" analog signals to multiple boards to give you a better chance at fulfilling the simultaneous acqusition requests.

4. Create a data server that captures all 80 channels at the max rate.  Change the code that tries to spawn off separate DAQ tasks and have it instead spawn clients that request channels of interest from the server.   I recently set up something fairly analogous to this as my method for providing multiple processes with simultaneous access to hw-clocked AI data.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 7 of 8
(3,052 Views)

Thanks Kevin, all of these are very valuable suggestions. I can build a high precision software clock and leave alone NIDAQ's hardware clock and give it a try (suggestion #1). I will try it this week and update this thread.

 

Thanks again!

-P

0 Kudos
Message 8 of 8
(3,024 Views)