LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Start two while loops in differents VI

Solved!
Go to solution

Hello, 

 

I would like to start two while loops in differents VI at the same time. I have looked at notifiers, queues but I don't really know how to use them. Can you help me please ? 

 

Thank you ! 

0 Kudos
Message 1 of 8
(2,251 Views)

Hi stevennn,

 

here you have a simple queue. The producerloop is generating a signal and feeds the queue. The consumerloop takes the data out of the queue and puts it back into a graph.

0 Kudos
Message 2 of 8
(2,239 Views)

I'm using Labview 2010 and I can not open your VI 😕 

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

A rendezvous reference passed to the two VI's sound more appropriate as they act as a hold point until all code execution as reached the point.

 

What do you consider "same time"?  What is the tolerance on timing?

0 Kudos
Message 4 of 8
(2,195 Views)

I have 2 subVIs and inside each of them I have a while loop. I would like these loops to start at the same time with tolerance 0.1 ms if it's possible. I have tried to use a rendezvous but the second while loop start 500ms after the first one.. It's the first time I'm using rendezvous so i'm not sure to use it correctly..   

0 Kudos
Message 5 of 8
(2,180 Views)

@stevennn wrote:

It's the first time I'm using rendezvous so i'm not sure to use it correctly..   


... then show us your code so we can see if you are using it correctly. Is this running under windows or an RT system?

What do the loops actually do? How do you tell if the timing is correct and what the actual difference is?

 

Please describe in more details what you are trying to achieve in more general terms. Maybe there is a better solution overall.

0 Kudos
Message 6 of 8
(2,167 Views)
Solution
Accepted by topic author stevennn

You have one "signal" (which I'll call "Go", say a Boolean that you can set to "True" when you want the loops to start), and two While Loops that need to "wait" until they get the signal.  The fact that the signaller and the recipients are all in different VIs means that you can't simply use Wires to transfer the data, but need to use something that can be written once and read multiple times.

 

This eliminates Queues (unless you do complicated back-flips) which are "one read per write", but does accept Notifiers (write once, read many).  It can also include a Global Variable (which works just fine in the "write once, read many" scenario).  Let's explore this latter (simpler) scenario.

 

The Writer side is simple -- when you want to start the two Targets, you simply write "True" to the Global and you are done.

 

Now for the Reader.  A key question is how closely synchronized do you need the two VIs to be?  Can they be started within a millisecond of each other?  Let's assume that this is OK.  Let's also assume that you only need to send one Go signal.

 

Create a While Loop that has a Wait 1 ms function, with the Global wired to the "Stop" terminal.  Put this at the "entrance" to the code you want to start, so that when Go appears, the "Waiting" loop stops, and the code you want to run starts.  Both VIs, running independently, will see the Go signal and will start within 1 ms of each other -- indeed, since they use the same clock, and I'm guessing the clocks are synchronized, it would not surprise me if the two waits run essentially synchronously, hence will exit as close to the "same time" as Windows allows.

 

If you wanted to get fancy and use a Notifier, you'd do much the same thing.  You'd need to pass the Notifier as a parameter from the Caller to the two Callees.  The Caller would simply write "True" into the Notifier (actually, it doesn't matter, really, if the Notifier is a Boolean or an Integer or anything else -- you are just asking "Did I get anything?").  The Callees have a While Loop with a Wait on Notification, which will "block" until a Notification arrives.  But what if the Caller crashes and never sends the Notification?  The Callees will never receive it, and will never stop!

 

"What, Never?  No, Never!  What, Never?  Well, Hardly Ever ...  Hardly Ever unless you use the TimeOut!" (with apologies to Gilbert and Sullivan ...).  To prevent this problem, you can change the Timeout on the Wait on Notification from -1 (Wait Forever) to, say, 10000 (wait 10 seconds).  If the Notifier exits because of a Timeout (read the Help to learn how to detect this case), you can use some other signal to detect if the Main has stopped/crashed.  There are various ways to do this, but that's a bit beyond the scope of this not-so-brief note ...

 

Bob Schor

0 Kudos
Message 7 of 8
(2,166 Views)

Use Occurrences

Snap12.png

 

mcduff

0 Kudos
Message 8 of 8
(2,126 Views)