LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reset Switch Buttons when VI closes

Solved!
Go to solution
How can you reset switch buttons when you close the VI.  The problem that I experience is that the two buttons that I want to reset back to false control the exit of other loops and essentially the program.  I have tried using sequence structures and it will reset the switch value but it will not exit the program then because the two buttons that I need to be reset will not allow me to exit the program because they are now false.  I have used local variables with these buttons so I can not use latch which is unfortunate.  Does anyone have an suggestions?
0 Kudos
Message 1 of 9
(4,485 Views)

Your description is not clear. Can you show us some code, or at least a picture of it.

 

Why would a button state prevent exiting the program? Makes no sense! 😮

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

Set the button to the desired state (T/F). On the front panel, right click on the button. Select Data Operations/Make Current Value Default.

 

Otherwise you can use a sequence structure to set the value with a local variable in the 0th frame and run your loops in the 1st frame.

0 Kudos
Message 3 of 9
(4,481 Views)
You may create a local variable for each control, and wire the value at which you want it to be initialized. Make sure your initialization is placed outside any loop/structure.
Message 4 of 9
(4,478 Views)
Willy, I believe your first solution will work only if you close the VI, then open it again.
Message Edited by xdaf on 12-17-2009 05:33 PM
0 Kudos
Message 5 of 9
(4,475 Views)
I believe you want to create an event structure that catches the method you use to terminate the application. In the event structure you can set the values you want. I personally set all the critical values on startup. It guarantees the correct operation and is not dependent on any default values being set when you start the program up.
0 Kudos
Message 6 of 9
(4,470 Views)

I have tried several of the suggestions but I cannot get it to work.  I have attached the while loop and event structure used to exit the VI.  The constant F and two local variables to the right are the variables that I need set to false when the program closes.  Any ideas?

0 Kudos
Message 7 of 9
(4,448 Views)
Solution
Accepted by topic author rwm11

You should include the "write to local variables" on the right inside  flat sequence, and wire the loop stop boolean to the structure (by doing so, you force the execution of the flat sequence AFTER you exit the loop).

Anyway, I'm missing something: according to the picture you've posted, your controls should be initialized to false as you launch the program...

Message Edited by xdaf on 12-17-2009 06:22 PM
Message Edited by xdaf on 12-17-2009 06:22 PM
0 Kudos
Message 8 of 9
(4,445 Views)

You have a classic race condition. Since there is no data dependency, writing to the locals occurs in parallel with the execution of the while loop. LabVIEW does NOT execute left-to-right. Execution order is entirely dictated by dataflow.

 

There is no need for sequence frames and such. Simply place the FALSE diagram constant inside the loop and wire to the two locals outside the loop. This data dependency ensures that the locals cannot be written until the while loop has completed.

 

Think dataflow! 🙂

 

Othere things make little sense: for example why do you need to unbundle the status with every iteration of the loop? That operation belongs before the loop, in fact you should bypass the loop if the status is true.

0 Kudos
Message 9 of 9
(4,422 Views)