LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can we run two while loops independently in one application?

I am acquiring two channels using PCI-6052.both channels to be read at 2ks/s,but I want to scans read at a time different for each channel,So I put two AI-read vi's in two different while loops.but the second while loop waits until the first is completed.Can we run independently both while loops?
0 Kudos
Message 1 of 4
(3,037 Views)
What you see here is one of the limitations of the old NI-DAQ driver. The traditional NI-DAQ driver is not truely multithreaded. In your case this means that the first AI-read waits until the number of samples you have specified have been acquired. During this time no other NI-DAQ calls can be processed and this makes the second loop wait.

There are two solutions for your poblem:

1. Use the NI-DAQmx 7.1 driver. Since NI-DAQ 7.0 the driver contains two driver kernels and APIs. One is called NI-DAQmx which is the new one and the other one is called "traditional DAQ" that is mainly the older NI-DAQ 6.9.3 driver and it still has the same limitation.
In contrast NI-DAQmx provides a truely multithreaded architecture which allows you to run multiple DAQ opera
tions in parallel without an impact on each other. NI-DAQmx also provides a streamlined API which speeds up your development.

The use of NI-DAQmx is the recommended method as all further development will be done on NI-DAQmx.

2. If you are working on an existing project you may not want to switch to NI-DAQmx now. In this case you should use the drop-in replacement for the AI read function that can be obtained from this link:

http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3D83F56A4E034080020E74861&p_node=DZ52302&p_source=External

The trick is here to check the scan backlog prior to reading the data. Data is only read back when the appropriate number of scans has already arrived in the buffer. Thus the AI read function doesn't need to wait and doesn't block other NI-DAQ calls.

Best regards,

Jochen Klier
Applications Engineering Group Leader
National Instruments Germany GmbH
Message 2 of 4
(3,037 Views)
Hello:

Jochen is absolutely correct about DAQmx being a true multithreaded driver. However, you still can not have two analog input tasks for the same device at the same time. This is because a task must reserve the hardware resources and keep those resources until it is completed. To have two tasks running and requesting the same hardware resources will not work. The same problem will occur in traditional DAQ using the AI read VIs. Your best bet it to use the single-VI DAQ VIs to Open, Read, and then close the resources on every loop iteration. Since you want to read 2 channels (each in a while loop), I suggest something like the image of a front panel and block diagram I have included...

Good Luck!

Sincerely,

Brooks B
Application
s Engineering
National Instruments
0 Kudos
Message 3 of 4
(3,037 Views)
Brooks,

thank you for adding your comment. I was a bit in a hurry and somehow I thought the question was how to acquire data from two 6052s instead of from two channels of the same device.

Thanks,

Jochen
NI-Germany
0 Kudos
Message 4 of 4
(3,037 Views)