LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Nested while loops issue

Solved!
Go to solution

Crossrulz, thanks a ton for your help. I feel like I have a much better understanding of notifiers now. I solved the final problem of the loop continuing to run by just placing the three inner loops in a case structure with the selector wired to the stop of the larger main loop, only allowing them to run when it read false.

0 Kudos
Message 11 of 13
(456 Views)

Here are some suggestions:

  • Use the Error Line!  It is your Friend, and helps to serialize things that need to be serialized (more on this later).
  • You "count" your loops using a Shift Register.  But the loops have their own built-in counter ("i") -- use it and simplify your loops.
  • Not (yet) thinking about stopping loops, you have two (not one) parallel processes running -- one with two sequential loops (that each count to 5) and another loop that just counts.
  • Ordinarily, a "Count to 5" loop would be coded as a For loop, rather than a While loop (again, simpler logic).  You can stop a For loop mid-count by adding a Conditional Stop terminal to it (right-click loop edge and look for Conditional Stop in the Drop-down list) -- this might be slightly better as For loops are mnemonic for "Count from 1 to N".
  • Once you have these two parallel loops (one containing two serial loops) coded, you should be able to run it and see A count 1..5, then B count 1..5, then repeating, while C counts 1.. (forever).  So there's only the "How To Stop" question.
  • You only need one notifier, as you want all the above 4 (did you think there were only 3?) loops to stop.  If you code Loop 1 with For Loops + Conditional Stop, you wire the Notifier output to the Conditional Stop.  Pass the Notifier Reference and the Error Line through the For Loop (use either Shift Registers or a "Last Value" output tunnel) and bring Reference and Error Line through the surrounding While Loop.  Also, bring the output of the second Notifier to the Stop terminal of the While Loop.  The "Countinuous Count" While Loop simply wires the output of the Notifier to its Stop.  Bring out its Error Line, as well.
  • So how do you "fire" the Notifier?  One more While Loop with an Event Structure, looking at a Value Change on the Stop button.  Think carefully about what you want to wire to the input of the Send Notification function.  Bring out its Error Line.
  • Final piece of the puzzle -- when do you Release the Notifier?  You don't want to get rid of it before it "does its job", which is when all three loops have stopped.  Look at Merge Errors (in Dialog and User Interface Palette) and remember, Error Lines are Your Friend.

Try coding this.  You should end up with something simple, intuitive (you could explain what it is doing to someone who has never seen LabVIEW), and easily maintained/extended.  "I'll show you mine after you show me yours".

 

Bob Schor

Message 12 of 13
(452 Views)

I understand there some major simplifications that can be made, but I created this example to use as a reference for a bigger project I've got going that I can't post online. The actual functionalities are quite different, but it uses the same structure as the one I've posted here. Three while loops within a larger main while loop. Thank you for your advice though! Efficient programming on LabVIEW is probably my biggest weakness. Simplicity is key with visual programming and immediately recognizing the simplest solution is not a strong suit of mine. 

Message 13 of 13
(445 Views)