scls19fr Posted April 8, 2008 Report Share Posted April 8, 2008 Hello, in a VI I have two parallels loop. I would like to stop the two loops when I click on a STOP button. I tryed two ideas One STOP button is connected on the loop until condition of the first loop and is also connected to the other loop. -> It doesn't work ! One loop is never run. One STOP button is connected on the loop until condition of the first loop and a STOP local variable is connected to the other loop condition. -> It doesn't work ! It can't compile because of the mechanical characteristics of the STOP button. What should I do ? Best regards Quote Link to comment
Francois Normandin Posted April 8, 2008 Report Share Posted April 8, 2008 I think you're looking for a master/slave or producer/consumer designs. Check out the templates that you can access when selecting "New..." You can get your inspiration from one of the templates you'll find there. (see picture) Quote Link to comment
T_Schott Posted April 8, 2008 Report Share Posted April 8, 2008 change the mechanical action of the button but that s not the best way to handle this problem in my programs i often use one global variable to stop all my running Loops well you can do this with queues oder notifiers - but when you have several loops (>10) you have a lot of wire work you should not use globals for all inter-loop-communications! Quote Link to comment
scls19fr Posted April 8, 2008 Author Report Share Posted April 8, 2008 Thanks you both for your replies... I found an interessting document about this "problem" on NI site Stopping Parallel While Loops in LabVIEW With One Stop Button http://digital.ni.com/public.nsf/allkb/267...AE?OpenDocument Quote Link to comment
Justin Goeres Posted April 8, 2008 Report Share Posted April 8, 2008 QUOTE (scls19fr @ Apr 7 2008, 07:24 AM) I found an interessting document about this "problem" on NI sitehttp://digital.ni.com/public.nsf/allkb/267...AE?OpenDocument Just bear in mind that the method discussed in the NI article is fine for relatively simple programs, but may not scale well for larger applications. In that case, you'll need to do something with queues, notifiers, events, etc. (like the examples posted above). Quote Link to comment
mross Posted April 8, 2008 Report Share Posted April 8, 2008 QUOTE (scls19fr @ Apr 7 2008, 09:28 AM) Hello,in a VI I have two parallels loop. I would like to stop the two loops when I click on a STOP button. I tryed two ideas One STOP button is connected on the loop until condition of the first loop and is also connected to the other loop. -> It doesn't work ! One loop is never run. You need to understand a basic principle of LabVIEW called "data flow." A VI does not proceed acording to a sequence of commands as is common with text based programming languages. With data flow every item, functaional block, or sub VI begins to function only whan all the wires to the item have brought data. IF one wire is nver activated then the function will remain idle until the data is produced. This is true also of loops. If you ignore what is inside of a loop it is similar to every other fcuntion on a block diagram - it has wires that bring input data and wires that carry away output data. Of course controls, indicators and constants can only have one type of wire. A control and a constant are only outputs. An indicator is a sink (or receptacle) for data - and has only input wire coming to it. A loop must receive data on all its input wires or it will not run. Only when the loop has stopped running will ot produce data on its outputs that are sent to the next wired function. You can turn on highlighting to examine how date flows at slow speed using the light bulb icon at the to0p of the block diagram. You should do this. You should attach pictures of your code or attach the VI itself to get the most informed responses. Without that I am guessing, but I will try to say why your second loop does not run. The wire from the Stop of the first loop must stop the first loop before that wire can carry the stop information to the second loop. But still the second loop may never run if all the input wires on it have not brought data. If the loop is never run this is the only reason. In data flow any loop will run if all the input wires are activated and the data is received. Next you will need to notice that a loop never puts data on a wire until it is completey finished looping. If you make a local variable of the Stop button and place that in the second loop, then the second loop will read the local variable each time it loops as data flow allows. Since there is no wire from the Stop button, then the loop wil activate as soon as all other inputs are filled. Use the highlight button. It is instructive. Show us your code to get better answers. Mike Quote Link to comment
scls19fr Posted April 8, 2008 Author Report Share Posted April 8, 2008 Thanks guys for your very informative posts. My VI is relatively simple so I will use the NI method. But I keep in mind the master/slave sample. Best regards Quote Link to comment
Doon Posted April 8, 2008 Report Share Posted April 8, 2008 Hiya, I have always used a "parallel" event structure to handle stopping parallel loops. In each loop, simply add an event structure with the "Stop":Value Change event. Connect "NewVal" parameter out of the Event Data Node to the stop button of the containing While Loop, and a-la-peanutbutter-and-jelly-sandwiches, you have parallel stopping loops. Download File:post-3343-1207596547.vi __ALTERNATIVELY__ If you need one loop to stop another, you may register a dynamic event. But that may be a bit complex for the purposes you need. have a nice day, -H Quote Link to comment
scls19fr Posted April 8, 2008 Author Report Share Posted April 8, 2008 Thanks a lot. I never had a look at event structure before... I use LV since a long time... but I'm still a newbie ! I will look at this because I guess it can be very usefull ! Quote Link to comment
mross Posted April 8, 2008 Report Share Posted April 8, 2008 QUOTE (Doon @ Apr 7 2008, 03:45 PM) Hiya,I have always used a "parallel" event structure to handle stopping parallel loops. In each loop, simply add an event structure with the "Stop":Value Change event. Connect "NewVal" parameter out of the Event Data Node to the stop button of the containing While Loop, and a-la-peanutbutter-and-jelly-sandwiches, you have parallel stopping loops. http://lavag.org/old_files/post-3343-1207596547.vi'>Download File:post-3343-1207596547.vi __ALTERNATIVELY__ If you need one loop to stop another, you may register a dynamic event. But that may be a bit complex for the purposes you need. have a nice day, -H I am having a hard time with this. What is better about this than a local varialble? Not to mention the trouble that can be caused by multiple event structures (theory to me since I have never had to resort to such a thing). Also, NI says don't use multpile event structures, so I don't. I have always lacked the curiousity to find out why they say that. Mike Quote Link to comment
Yuri33 Posted April 8, 2008 Report Share Posted April 8, 2008 This is my standard LV2-based global stop: Download File:post-7607-1207603671.vi (LV 8.2) Quote Link to comment
Mark Balla Posted April 9, 2008 Report Share Posted April 9, 2008 There are other examples of global stops Here Quote Link to comment
PaulG. Posted April 9, 2008 Report Share Posted April 9, 2008 QUOTE (mross @ Apr 7 2008, 04:24 PM) ... NI says don't use multpile event structures, so I don't ...Mike My understanding is not to use multiple event structures in the same loop. I've had single event structures in mulitple loops with no trouble. Quote Link to comment
Doon Posted April 9, 2008 Report Share Posted April 9, 2008 QUOTE (mross @ Apr 7 2008, 01:24 PM) I am having a hard time with this. What is better about this than a local varialble? I see two problems with local variables 1) You cannot use "push-button" interface with locals. That would mean that one would have to use "switch-buttons" to stop the loop and another local variable to unset the switch so that it looks like a push-button. 2) You end up with a "polling interface" type structure which suffers from potential race conditions. You run the risk of one loop quiting and precluding the quiting of another. QUOTE (mross @ Apr 7 2008, 01:24 PM) Also, NI says don't use multpile event structures, so I don't. Event Structures behave as "invisible queues". This is the result of NI's implementation of the Event Structure. This means that *sequential* event structures are dangerous (e.g., try sequencing two event loops that handle the same controls). I have always surmised that this was a "lesser of two evils" design decision on NI's part, given the intrinsic parallel capabilities of LabVIEW. have a nice day, 8D Quote Link to comment
mross Posted April 9, 2008 Report Share Posted April 9, 2008 QUOTE (PaulG. @ Apr 8 2008, 12:09 PM) My understanding is not to use multiple event structures in the same loop. I've had single event structures in mulitple loops with no trouble. Paul, Since my hammer of choice is the queued producer consumer architecture, I suppose I simply haven't had a need for more than one event structure. However, to have one event structure in each of several separate loops I would want to be very, very sure there is no intearaction between the loops. In my ignorance, I think I prefer the use of one exectutive loop with one event structure, then if necessary multiple parrallel loops operated by queues, one per parallel loop. This sort of arrangement debugs well. Since I am not curious enough to try (or not able to burn the time to try) the mutiple loop/multiple event structure method, can you tell me what I would see if the same event is firing two different event structures? Is it as simple as both EvntStructs are fired reliably and the separate loops go about there merry separate business? OR do the same events never show up in two differenct loops? Thanks, Mike QUOTE (Doon @ Apr 8 2008, 01:50 PM) I see two problems with local variables 1) You cannot use "push-button" interface with locals. That would mean that one would have to use "switch-buttons" to stop the loop and another local variable to unset the switch so that it looks like a push-button. 2) You end up with a "polling interface" type structure which suffers from potential race conditions. You run the risk of one loop quiting and precluding the quiting of another. Event Structures behave as "invisible queues". This is the result of NI's implementation of the Event Structure. This means that *sequential* event structures are dangerous (e.g., try sequencing two event loops that handle the same controls). I have always surmised that this was a "lesser of two evils" design decision on NI's part, given the intrinsic parallel capabilities of LabVIEW. have a nice day, 8D I was asking about the simplest implementation that began this discussion. That problem needs no more than a local variable to solve it and you live with how the switch functions. For my self I always fire an event with a STOP, or End All button (stop gets used for a variety of things in reality), then I deal with shutting down the various ongoing functions with queues. Mike Quote Link to comment
orko Posted April 10, 2008 Report Share Posted April 10, 2008 QUOTE (mross @ Apr 8 2008, 11:04 AM) Since I am not curious enough to try (or not able to burn the time to try) the mutiple loop/multiple event structure method, can you tell me what I would see if the same event is firing two different event structures? Is it as simple as both EvntStructs are fired reliably and the separate loops go about there merry separate business? OR do the same events never show up in two differenct loops? They do not fire reliably at the same time... Which is why I don't use this method. See the below VI which shows that the second and third event structures do not get the event until the subsequent loop iteration. If they all got the event at the same time, then the delays here would be less than the wait time for each loop: (LV8.5) Quote Link to comment
Kevin P Posted April 10, 2008 Report Share Posted April 10, 2008 QUOTE (mross @ Apr 8 2008, 02:04 PM) Since I am not curious enough to try (or not able to burn the time to try) the mutiple loop/multiple event structure method, can you tell me what I would see if the same event is firing two different event structures? Is it as simple as both EvntStructs are fired reliably and the separate loops go about there merry separate business? OR do the same events never show up in two differenct loops? Mike, I've put together code before with at least 3 independent While loops that each reacted to a single "Stop" button event. One mouse click always stopped all the loops. Every event structure that is "registered" to react to a particular event will have the event delivered to its queue. I generally only use this technique for quick prototype stuff since it seems to be a frowned-upon style, but it has always worked out fine in my experience. One little tidbit for those inclined to try it out: do *not* use the value from the button's terminal. Only read from the "NewVal" event property on the left side of the event structure. Reading from the terminal can subject you to a race condition. -Kevin P. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.