LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

2 simultanius while loops - how do they execute?

Hi there.
 
I have 2 while loops running simultanius i my program.
 
How are these loops executet.
 
Does loop1 finish one execution before loop2 starts, or are they executet as 2 separate threads in Windows which then run simultaniusly?
 
/Stephan
0 Kudos
Message 1 of 7
(3,412 Views)

They run as two seperate threads.

 

Tom

0 Kudos
Message 2 of 7
(3,407 Views)

Ok, thanks.

I am using a DAQ USB 6008 unit.

One of the while loops reads analogue inputs from the device, and the other writes/reads digital IO.

Do you know if the program could crash if both while loops tries to communicate with the 6008 unit at the same time?

/Stephan

0 Kudos
Message 3 of 7
(3,406 Views)
Hi Stephan,
 
if you could provide the  code it would be easier to help you .
 
I assume that you are using MAX to setp up your channels and task
 
Xseadog
0 Kudos
Message 4 of 7
(3,399 Views)

First, Let me say I don't know the answer!  (Someone else may comment with more knowledge of your setup).  My gut feeling is no.  Reading the analog inputs will occur and doesn't hurt the other function.  Reading/writing of DIO will happen when required.  The only risk I see is maybe a missed message -- if you have requested a read with one loop and the DAQ is busy getting that info while the other loop then tries to write -- you may miss the command.  Although the unit probably has a buffer to hold the request until it is no longer busy --so the risk is probably low or not a risk at all.  I would recommend watching for this and make sure that you receive all the reads and the DAQ executes all the writes that you command. 

 

Tom

0 Kudos
Message 5 of 7
(3,399 Views)

As long as the loops have no wires connecting them, they will run in parallel. If you have any wires running from one to to the other, the loop that has wires running out of it will run first. When it finishes, the other loop will run.

DAQmx allows multithreaded access to DAQ devices. In other words, you can access the IO resources of the device from multiple places in your application. The one exception to this is the analog inputs on the majority of DAQ cards. The analog inputs all share a single "resource" on the card because they share a single analog to digital converter and the channels are sequentially scanned in the order they are setup in the task.

This means you can have one loop accessing the analog inputs and another loop accessing the digital lines. But you cannot have two loops accessing the analog inputs. (well, you can but you have to configure the task, acquire data, close the task, configure in the other loop, acquire, close, rinse and repeat...)

Ed



Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 6 of 7
(3,380 Views)
Thanks guys, I think now know, what I need to know Smiley Happy
0 Kudos
Message 7 of 7
(3,363 Views)