Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Can two task use same AI channels?

Hi DAQ Guru,

I want to create two tasks which use same AI channels, but I hope they work at sequential time. For example, while 1st task completes acquiring data, 2nd task will immediately start to work employing the same 4 channels.Then I can read the data from 1st task when 2nd task is still running. Does it work?

I just worry about that both tasks will occupy the same internal buffer. To me, the internal buffer attached to each task is blackbox. I do this to simulate a ring buffer to speed up my processing.

By the way, does DAQ has a built-in support for ring buffer?

Your help is much appreciated.

My example is attached as following,

iStatus = DAQmxCreateTask ("Acquire1", &thAcquire1);
iStatus = DAQmxCreateTa
sk ("Acquire2", &thAcquire2);

//Virtual channel creation for analog input ports 0-3.

iStatus = DAQmxCreateAIVoltageChan (thAcquire1, "Dev1/ai0:3",
"aiChan", DAQmx_Val_Cfg_Default, -1.0, 2.5, DAQmx_Val_Volts, NULL);

iStatus = DAQmxCreateAIVoltageChan (thAcquire2, "Dev1/ai0:3",
"aiChan", DAQmx_Val_Cfg_Default, -1.0, 2.5, DAQmx_Val_Volts, NULL);
0 Kudos
Message 1 of 7
(3,846 Views)
I'm not aware of built-in support for any type of "ring buffer", but it could be possible that I don't completely understand what you're describing.

For your application, I would recommend either postponing all data analysis until after all data acquisition is completed, or making your application multithreaded so that you are able to have one thread performing analysis all of the time.
0 Kudos
Message 2 of 7
(3,845 Views)
Hi Zmoct,

Two tasks cannot be ran simultaneously on the same resource. However, you can run them alternatively by stopping one before starting the other. The resource is considered reserved when DAQmx Read operation is performed, so you cannot read the data using this VI while you are running a different task.
If you are referring to circular buffer in the second part of your question, then yes DAQ has builtin support for circular buffer. For example, setting the number of scans to acquire to zero in the AI Start means that you want to implement a circular buffer.
I hope this answers your question.

Serges Lemo
Application Engineer
National Instruments
Message 3 of 7
(3,845 Views)
Hi Serges,

Thank you so much for your answers,which are what I want to know.

Now, I am coding in C++ not Labview. How can I read data from buffer 1 while the task is writing data to buffer2. And how can I configure circular buffer in C++. IMAQ has a wonderful C example for ring buffer using image grabber PCI1428,is there any C example on how to use cirucular buffer for DAQ?

Again thank you so much!

Zmoct
0 Kudos
Message 4 of 7
(3,845 Views)
Hi Jasonv,

Thank you so much for your nice answer.

I am using multithread to processing the data.However,when I am reading the data,I have to stop the task that will deminish my system performance. Serges(NI engineer) told me that NI has a builtin supports for cirucular buffer. That will solve my problem if I know to implement it in C rather than labview. I hope to get a example from Serges.

Thank you again for your great help.

Zmoct
0 Kudos
Message 5 of 7
(3,845 Views)
Hi Zmoct

Unfortunately, I do not support C++ for data acquisition. However, you can read about this double buffering in the NI-DAQ manual. If you have it installed in your machine, you can go to Start->Programs->National Instruments->NI-DAQ and open the user manual. Then search for either circular buffer or double buffer. If you are working in Visual C++, you can also go to the following link to fiind out how to install examples: http://digital.ni.com/public.nsf/websearch/C8CC0C1EA6229B09862565E90044DDF3?OpenDocument.

Sorry I could not be of more help.

Serges Lemo
Applications Engineer
National Instruments
0 Kudos
Message 6 of 7
(3,845 Views)
Hi Zmoct,

I suggest you use a single task to read the data, as both tasks read the
same channels sequentialy. Then you decide which samples correspond to
"buffer 1" or "buffer 2" based on number of samples acquired, time or other
condition.

If you only want to use the double buffer technique, where the card fills a
buffer while you read the other one, you can do it with only one task. Just
follow this procedure:

1) Initialization.
1.a) Call "DAQmxCreateTask".
1.b) Call "DAQmxCreateAIVoltageChan".
1.c) Call "DAQmxCfgSampClkTiming" to set buffer size and sampling frequency.
1.d) Call "DAQmxSetAIDataXferMech" with "DAQmx_Val_DMA" to acquire data
using DMA (if available).
1.e) Call "DAQmxSetAIDataXferReqCond" with
"DAQmx_Val_OnBrdMemMoreThanHalfFull" so the board transfers data when half
its internal buffer is full.
1.f) Call "DAQmxSetReadOverWrite".

2) Starting the task.
2.a) Call "DAQmxStartTask".

3) Acquiring the data.
3.a) Call "DAQmxGetReadChangeDetectHasOverflowed" to check for buffer
overflowing.
3.b) Call "DAQmxGetReadAvailSampPerChan" to get the number of samples
acquired so far.
3.c) If the number of samples acquired is greater than the number of samples
that fit half the buffer, call "DAQmxReadAnalogF64" (or the analog reading
function you want).

4) Don't forget to call "DAQmxStopTask" when you're finished.


The idea behind this procedure is the same as "double buffer", but you use
two "half buffers". There are philosophical differences only.

You could have a timer that executes the code of Step 3. I highly recommend
multimedia timers on MS Windows. Just make sure to check the buffer faster
than it fills.

I don't know if this is the best method to do it, but it's the one I use and
it is really fast. You should check if your card supports DMA. For details
on the parameters of the functions, please check the "NI-DAQmx C Reference
Help".


Best regards



"zmoct" escribi� en el mensaje
news:50650000000500000055C60100-1079395200000@exchange.ni.com...
> Hi Serges,
>
> Thank you so much for your answers,which are what I want to know.
>
> Now, I am coding in C++ not Labview. How can I read data from buffer 1
> while the task is writing data to buffer2. And how can I configure
> circular buffer in C++. IMAQ has a wonderful C example for ring buffer
> using image grabber PCI1428,is there any C example on how to use
> cirucular buffer for DAQ?
>
> Again thank you so much!
>
> Zmoct
Message 7 of 7
(3,845 Views)