LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

I am using two while loops in labview .. i want a single stop button to stop the both things


@LarsUlrich wrote:

I think the iot and the iut are the result of a type-o, I even made one myself when i wrote iton and missed the space in between (see my previous posts)


Probably. Could be posting from a phone?

0 Kudos
Message 11 of 26
(1,972 Views)

@mahadev wrote:

I did not get u s, can u expalin it

I am using 2 stop buttons to stop 2 while loops but i wanted to stop both while loops by using a single stop button.

 

thanks

mahadev


Hey Mahadev.

 

As you'll probably now understand, variables from outside of loops become unaccessable whilst the loop is running. You have to imagine that While Loops are pretty much oblivious to the occurences outside of them whilst they're running; but there is a way to get around this problem by making use of a Local Variable. 

 

A Local Variable is essentially a pointer to a location in memory where a variable is stored. This way, loops have direct access to the value rather than simply being passed to it in data flow. The value of the variable can still be read and changed without having to rely on the temporarily

inaccessable dataflow link from outside of the iterating loop.

 

Below, you'll see use of a stop button and a Local Variable pointing to the stop loop in order to control the condition of two concurrent while loops:

 

Concurrency Snippet.png

 

 

You can create local variables by right clicking on the control and selecting Create > Local Variable.

 

Hope this helps.


Alex Thomas, University of Manchester School of EEE LabVIEW Ambassador (CLAD)

0 Kudos
Message 12 of 26
(1,964 Views)

Hi Alex,

I have a similar problem and I am also new to LV.

The purpose of this vi is to let user press any one of n (=4 here) buttons and generate a value correspondiong to the button pressed. So as seen in the attached LV bolck diagram, pressing Start should give 1, Stop should give 2 and so on. I have created only two events inside the while loop, to see how and whether it will work.

The problem is it stops after the first button is pushed.and No Output (Numeric) value shows up. Clicking the other button gets no response.

I also cannot get the buttons to reset (i.e return to thier default value)

I don't understand why this happens and so would like to understand the mechanism so I can learn and fix it myself.

Appreciate any suggestions/ expalination you can give.

I also do not understand why after I push1 button, the vi does not stop, even though the "OR" in front of the STOP symbol sees a TRUE from the corresponding Event block... It just sits there..

Finally is this a simple problem that I am, maybe making too complicated ?

 

Thanks.

Bhal Tulpule

0 Kudos
Message 13 of 26
(1,498 Views)

You can't have two event structures in the same while loop.  The loop can't iterate until all code inside of it completes, and the while loop is sitting there waiting for an event in the other event structure to execute.

 

Read Caveats and Recommendations when Using Events in LabVIEW - LabVIEW 2013 Help .

 

You should also look into the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

0 Kudos
Message 14 of 26
(1,494 Views)

BhalT wrote:

Finally is this a simple problem that I am, maybe making too complicated ?


Ravens already explaind the dataflow problem. (You should really start a new thread, because your question has nothing to do with the earlier discussion here. This tread is about stopping two while loops while your question has two events structures in a single while loop)

 

Yes, use a single event structure as follows.

 

 

 

Since the loop stops no matter what, you don't even need the while loop.

 

You can make it even simpler if you want events for all four buttons. try it.

0 Kudos
Message 15 of 26
(1,486 Views)

Hi !

You are right, I should have started a new thread.It is hard to navigate in LV or me.Anyways, I tried the simple solution you suggested and it works ! (ofcourse). Figuring out the stop button was tricky since I did not have any. I am attaching the vi for anyone's benefit.

One problem I don't understand is when I run this in continuous mode, the subsequent button pushes do not generate any results. I will ask that question on a new post...

Thanks.

Bhal Tulpule

0 Kudos
Message 16 of 26
(1,448 Views)

You should use "latch when relesed" mechanical action. Switch until released will give you two events, another one when the button is pressed, but at that time the VI has already completed. This is not what you want.

 

After you correct that, your code is pretty pointless, because the output is always "not equal zero", else the event would not have been fired to begin with. It would work exactly the same without the while loop present. Right?

 

Why are you using continuous mode? Still, running continuously, all buttons seems to work just fine. What do you mean by "...do not generate any results"? What "results" do you expect?

0 Kudos
Message 17 of 26
(1,431 Views)

Hi !

I was using the while loop earlier because w/o it, the vi would lock up (i.e. not respond to a second press of the same or button). So I added the EQ 0 to stop the loop. However with the change to "Latch when pressed" or "Latch  when released" the while loop is unnecessary and so I have removed. The EQ 0 is then useless.

 

Thanks for pointing that out.

Bhal Tulpule

0 Kudos
Message 18 of 26
(1,420 Views)

BhalT wrote:

I was using the while loop earlier because w/o it, the vi would lock up (i.e. not respond to a second press of the same or button).


Well, the second press would generate the same output, so you would not see a difference anyway. Typically "locked up" means the VI becomes unresponsive. What exactly did you observe?

 

All these select nodes make the code complicated and potentially buggy because it is difficult to tell if one of the diagram constants has been changed accidentally. Too many points where bugs can hide! Here is a better and more scalable solution. Now you can easily add more buttons with virtually no significant changes in the code.

 

I assume that this is a dialog style subVI to be used in a larger program, even though you have not assigned any connector terminals yet. 😉

 

Also remember that the "run continuously" mode is a debugging tool and has no use for regular execution.

Message 19 of 26
(1,415 Views)

Hi !

My! That is a simple and elegent solution. I guess it shows my lack of and the need to know about many of these unique functions... More homework to do...It sure made my code more difficult to debuig.

Incidently by vi lockup I meant there was no visible action even when I had the light bulb (highlight exec.) button on.I was using the continuous mode  just to test.

This was just one vi whose output goes to an eembedded hardware over a serial port.... I did not assign any terminals to it since i was not sure how the I/O would end up.

 

I do appreciate the multiple (prompt) responses. and the time you have taken from your own schedule.

Where is the kudos button. ? I will find it..

Thanks.

Bhal Tulpule

0 Kudos
Message 20 of 26
(1,407 Views)