LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I show a sub vi whenever a boolean value changes

Hey I have modified ur original vi to suit ur need ....Hope it works...also i ahve made changes to ur sub vi...to work satisfactorily.......

Inform me...if things dont work....!!!
0 Kudos
Message 31 of 35
(758 Views)
Yups ....if u want the for loop yo wait for the sub vi to finish its execution.......simply place the subvi inside a case & place this case inside the for loop......the for loop will wait.......for the sub vi to complete its exec....first...!!!
0 Kudos
Message 32 of 35
(757 Views)
This is the way that my program is set up...... I have one big case structure and within that structure I have a while loop and a for loop.  The for loop is not in the while loop.  I have a delay on the while for about 250ms and a delay on the for loop for about 200ms.  The way it works is that the while loop goes through one iteration, waits the delay, then the for loop goes through one iteration, waits the delay, then the while loop again and it continues until the program is done executing.  Well, I put a case structure within the while that delays a sub vi whenever a indicator changes value.  Whenever the sub vi opens, the while loop doesn't finish executing until that sub vi closes.  But the for loop continue executing as normal.  How can I make so that when the while loop is paused due to the fact that the sub vi is open, the for loop also pauses until the while loop start executing again.  I also want the for loop the start off at the same place it left off.  If I use the case structure around the for loop, like you suggested, and wire to it a command in the while loop, so that whenever the sub vi opens, it sends a false command to the while loop that will causes it to stop, when the while loop sends out a true command, will the for loop continue to execute where it left off?    I can't load my program for you all to see because it is so large. 
0 Kudos
Message 33 of 35
(753 Views)
First of all, if your vi is too large to post, then it is too large, period.  It would be best to break it down to subvi's with the main calling the different subvi's.  Trying to link loop execution so that a for loop gets paused when a while loop calls a subvi is not a very elegant solution.  You should really think about changing your architecture.  I suppose you could use local variables so that a flag is set in the while loop when the subvi is called, and then reset when the subvi returns.  In the for loop, the flag can be wired into a case structure to cause a pause loop.  See attached vi.
- tbob

Inventor of the WORM Global
0 Kudos
Message 34 of 35
(741 Views)
Hello,
 
I think your last question in there was about my suggestion, so I'll clarify.  My understanding is that you originally had a while loop and a for loop in parallel, where in the while loop you had a subVI which would open it's front panel.  The behavior you wanted was that the for loop to pause when that subVI runs, and resume after that subVI completes.  What I suggested was to replace your for loop with a while loop that behaves like a for loop with pausing capabilities.  HOWEVER, by pausing I don't mean in the middle of a loop iteration... the solution I proposed will at each loop iteration ask the question, "do I execute the suspend case or the usual case?"  Thus, you will not pause in the middle of an iteration, rather, when your subVI is launched and the boolean is set (which controls the case structures input selector), then your while loop begins executing the suspend case on subsequent iterations, until the boolean is changed again (which presumably happens when your subVI finishes executing).  If the loop is in the middle of an iteration when your subVI (in the other loop) is called, then that loop will finish it's current iteration, and then use the boolean to decide which case to execute next (as it always would), where if your subVI hasn't finished by the time that loop iteration completes, then the suspend case should execute.
 
If you need to have finer control over what happens, you'll have to use a more sophistocated architecture to communicate between your loops.  For example, you could replace your for loop with a more general state machine instead (my original suggestion is actually a two-state state machine).  How it would work would be to have it trivially cycle through a sequence of states, where in each state you put a piece of your code that you have in your for loop.  Then, you could use a boolean, much like in the previous suggestion, to conditionally jump to the suspend state from any of those "pieces" states, and stay in the suspend state until the boolean changed back.  Now to start your execution back at the right place (in the right state) you'll need to have some next-state logic which likely takes the current state, previous DISTINCT state, and the boolean's value to determine the next state.  You will also have to keep track of computation results from a given state to pass to a next state.
 
Ok, I know that's a lot of text, but I think if you read it carefully it will be coherent and helpful.  From what I understood from the last post, you were putting a while loop and a case structure AROUND your current for loop... I am suggesting that you REPLACE the for loop with the while loop and case structure (state machine) architecture.
 
Hopefully this helps!  If necessary, you can post a very stripped down version of your application... so it won't be too big!
 
Best Regards,
 
JLS
Best,
JLS
Sixclear
0 Kudos
Message 35 of 35
(739 Views)