LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Changing button status on completion of one loop?

Ok, this seems like a simple question (and probably is) but i cant for the life of me figure out how to do it.
 
I have made a VI, which when run waits for the push of a button to start (the button is inside a while loop which is wired to stop if true). The program then runs and the button status changes to true (and says something like "please wait"). The entire program is encased in a big while loop, so when the program has finished doing what it is doing, it does another loop. What i'd like is to be able to change the status of the button from "please wait" to its initial false value in order for the user to press the button again and run the program. Does that make sense?
 
Its basically a sort of single shot program. You press the button, it says please wait, does what it does and then starts again and waits for the user to press the button again to run again. However at the moment the button stays in its true "please wait" status and the program loops indefinitely (apart from if i cancel it or use the STOP button wired to the outer while loop which will stop the entire program loop).
 
Thanks!
0 Kudos
Message 1 of 20
(3,733 Views)
Sorry, i forgot. I've attached a screenshot showing the part with the button (its the "acquire waveform" control). Thanks!
0 Kudos
Message 2 of 20
(3,729 Views)

The way your block diagram operates (from the partial look you gave us), the inner loop goes on and on until someone presses the Aquire button.  Then the inner loop is done and the rest of the code after that loop executes.  Don't know what happens next but after the outer loop iteration is done, it starts over and the inner loop runs over and over until the Aquire button is pressed again.  All this is dependent on the Aquire button mechanical action set to a latch type.  Latch means that the button will turn True when pressed, and then turn back to false when the code reads the button.  If it is set to a switch type, the button will stay True the first time it is pressed, and the inner loop will only execute once on the next outer loop iteration.

If you want to trigger an Aquire when a user presses a button, use an event structure.  The button press would trigger the event and the code in the event case would do the aquiring.  Also, you should put delays in your loops (even 1mS) so the program does not hog the CPU.

- tbob

Inventor of the WORM Global
Message 3 of 20
(3,715 Views)
Thanks, tbob! I have changed the status to latch until released and the button is reset on the next loop, however something odd is happening in that it reads the value true once more before resetting the status so the program actually loops twice rather than once, any ideas? Thanks.
0 Kudos
Message 4 of 20
(3,701 Views)
Did you put a small delay in your loop?  try 100 mS.
- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 20
(3,694 Views)
Ah, i put in 20ms. I'll try 100ms when im back in the lab tomorrow, thanks. When you say delay, how do you impliment it? I put in a flat sequence structure inside the loop through the visa session with a wait(ms) function.
0 Kudos
Message 6 of 20
(3,691 Views)

You don't need a flat sequence structure, just put the delay anywhere inside the loop.  Only the timer value should be wired to it, nothing else.

Message Edited by tbob on 02-14-2007 09:46 AM

- tbob

Inventor of the WORM Global
0 Kudos
Message 7 of 20
(3,690 Views)
Excellent. Thank you very much for the help! I shall try this tomorrow 🙂
0 Kudos
Message 8 of 20
(3,685 Views)
Thanks again. Just to let you know i've now tried this with event structures and it works a lot better! However, I still have a problem with the button changing status. I have attached a screenshot of the problem area. When i press "acquire waveform" the button depresses (ive got it set to latch when released) however once the waveform has been read i'd like it to return to its false status. This does not happen, the button stays true! Please help! thanks.

(Oh, and please excuse the messy wires, i havent had time to clean it up yet :))

Message Edited by Exulus on 02-19-2007 07:21 AM

0 Kudos
Message 9 of 20
(3,660 Views)
I just tried a sample vi here with the button set to latch when released, and it changes back to false as soon as it is read.  One thing you can try is to unwire the Aquire Waveform button and leave it unwired.  On the left side, change the Type selection to New Value and wire this to where the Aquire button was wired.  Try this.  It is best to do it this way because there is some timing involved as to when the button changes back to false after it is read.  Using New Value ensures that the True value will be used.
- tbob

Inventor of the WORM Global
0 Kudos
Message 10 of 20
(3,643 Views)