LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sub VI: button values remain from last call

I am currently running a VI, which calls a Sub VI, I have created. The Sub VI consists of an event structure, which is triggered when a button is pressed (button value change). As there are parameters that are set by the user, that parameters need to be set before the whole VI is running. Therefore I created a flat sequence, which contains a while loop in first frame, which is stopped if the value of the button is true (same button that triggers the event structure).
What now happens is that sometimes the button keeps its value from the last call of the VI. Therefore the while loops is ended even though no button has been pressed.
I tried to create another frame in the flat sequence before the other frames, that initializes the value of the buttons - but it didn't solve the problem. Any idea what might be going on? To me it doesn't make any sense, since there is no way, that the value of the button might be true, because it is set to false in the frame before the while loop.

I'll just attach you an image, because the actual VI is huge and rather complex. I hope my problem is clear so far.
0 Kudos
Message 1 of 9
(4,563 Views)
I'll throw in a pic of the front panel, maybe that will make a few things more understandable. Actually, I am acquiring data for vibrational tests using that sub VI.

0 Kudos
Message 2 of 9
(4,560 Views)


sthu wrote:
I am currently running a VI, which calls a Sub VI, I have created. The Sub VI consists of an event structure, which is triggered when a button is pressed (button value change). As there are parameters that are set by the user, that parameters need to be set before the whole VI is running. Therefore I created a flat sequence, which contains a while loop in first frame, which is stopped if the value of the button is true (same button that triggers the event structure).
What now happens is that sometimes the button keeps its value from the last call of the VI. Therefore the while loops is ended even though no button has been pressed.
I tried to create another frame in the flat sequence before the other frames, that initializes the value of the buttons - but it didn't solve the problem. Any idea what might be going on? To me it doesn't make any sense, since there is no way, that the value of the button might be true, because it is set to false in the frame before the while loop.

You need to make sure is that the two buttons have the correct mechanical action (recommend "latch when released"). This way they only stay true until they new values is read by the code and then they will revert automatically to false. Your first frame is not needed.
 
Your code makes little sense. Where is the event structure you mentioned? RIght now you are polling the buttons millions of times/second, consuming 100% of the CPU whil doing basically nothing. Any UI polling loop needs a small wait statement!
 
All you really need is a single event structure (no sequence at all!) with a event that gets triggered by a value change of any of the two buttons.
 
You seem to treat controls as "variables" via disconnected value property nodes. This is a kludge used by text programmers and not great for LabVIEW. Use uninitialized shift registers. There is also a "first call?" primitive.


Message Edited by altenbach on 02-21-2008 08:58 AM
0 Kudos
Message 3 of 9
(4,549 Views)

Hi sthu,

I dont know how your rest of the code looks like but you can try these steps:

1. Completely remove the 1st Frame and the while loop in the second frame.

2. Put the event structure inside a while loop - this ensures the timeout event is executed until the buttons are clicked.

3. When the buttons are clicked, route the (TRUE) boolean value to the while loop condition through the event structure.

Also ensure the mechanical property of the buttons are set to "Latch When released".  If this does not work, write the FLASE value to the buttons after exiting the while loop.

Hope it helps.

Vikas

0 Kudos
Message 4 of 9
(4,545 Views)
unfortunately, that's not a possibility.
What I need to do is:
- when the sub vi is called, enter the polling loop, wait until button is pressed. (user will set values during that time)
- when button is pressed first time, exit polling loop, run some code
- button also triggers event structure, which will be excecuted when all needed data is processed by previous step
- every time when the button is pressed, trigger the event structure again

if i would add another event structure, which uses the same events I will end up in a stuck VI, because every event structure waits for some data, that it is not able to get.

I you have a look at the front panel I posted: the user sets all the values when the sub vi is called. then he presses the aquire data button.
Then some generell things are calculated based on the values the user entered. when done, the first acquisition is started. when the acquisition is done, the vi waits until the user starts another aquisition or repeats the last acquition.

My problem is:
if I call the subvi the first time - no problem.
but if I call it again, sometimes the value of the acquire data button remains from the previous call (that shouldn't happen) - therefore, the polling loop is ended when the subvi is called, not when the button is pressed. values changed by user are ignored!!
I tried to solve this problem by adding the first frame, which sets the value of the button to false (that didn't help, unfortunately)

buttons are set to "latch when released"

I hope everthing is a little clearer now.
0 Kudos
Message 5 of 9
(4,494 Views)


sthu wrote:
unfortunately, that's not a possibility.

What is "that's"? You should make sure to quote what yo are replying to. 😉
 
 
0 Kudos
Message 6 of 9
(4,468 Views)


sthu wrote:
I hope everthing is a little clearer now.

No. not at all!
 
Why don't you attach some code that demonstrates the problem??


sthu wrote:
- button also triggers event structure, which will be excecuted when all needed data is processed by previous step
- every time when the button is pressed, trigger the event structure again

From your last description, it reall sounds like you have some basic problems dealing with dataflow. You never need a polling loop. All you need is a single while loop containing a single event structure. Trust me!
0 Kudos
Message 7 of 9
(4,462 Views)

I completely agree with altenbach, you dont need a polling loop.. the event structure handles only one operation at a time.. so, you can ensure the Operation A, dependent on Operation B, is NOT executed before completing B.  You can "disable and grey" the button that does Operation A until the user presses the button for Opn B first - or something similar.

And yes, a code would be helpful.

Vikas

0 Kudos
Message 8 of 9
(4,447 Views)
thanks for your help..
I could think of implementing what you are saying, if I wouldn't use that tab selector and a producer/consumer structure combined.. In that case it gets rather complicated to just use that design.
anyways - I figured out that my problem only occurs if I run the vi in labview. If I create an excecutable it's all good. does that make sense? no.. but it even didn't make sense that the problem occurred at all..
I just have a day left, so I will not try to go for a whole redesign now..
0 Kudos
Message 9 of 9
(4,427 Views)