Jump to content

Stop 2 parallels do loops while


Recommended Posts

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

Link to comment

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!

Link to comment

QUOTE (scls19fr @ Apr 7 2008, 07:24 AM)

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).

Link to comment

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

Link to comment

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

Link to comment

QUOTE (Doon @ Apr 7 2008, 03:45 PM)

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

Link to comment

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.

Link to comment

QUOTE (mross @ Apr 7 2008, 01:24 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.

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

Link to comment

QUOTE (PaulG. @ Apr 8 2008, 12:09 PM)

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

Link to comment

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:

post-11742-0-14787900-1379450867.png (LV8.5)

Link to comment

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.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.