07-22-2011 10:30 AM
@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?
07-22-2011 11:03 AM - edited 07-22-2011 11:04 AM
@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:
You can create local variables by right clicking on the control and selecting Create > Local Variable.
Hope this helps.
11-12-2013 03:30 PM
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
11-12-2013 03:54 PM - edited 11-12-2013 03:56 PM
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
11-12-2013 04:10 PM - edited 11-12-2013 04:19 PM
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.
11-13-2013 05:40 AM
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
11-13-2013 11:25 AM
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?
11-13-2013 02:01 PM
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
11-13-2013 02:21 PM - edited 11-13-2013 02:29 PM
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.
11-13-2013 02:55 PM
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