From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Switch Until Released Booleans and Default value invoke nodes

Solved!
Go to solution

I came upon a curious phenomenon today that I can't really explain. When my VI completes execution, I like to retain most of the controller values, except for those of Boolean switches used to pause, or safely stop my application. Until recently, I haven't been able to do this, and I figured it was because of race conditions. Using the Value property node (which I now know doesn't work for boolean switches) and Reinit to Default invoke node yielded no results, until I got to experimenting. What if the reinit to default executes asynchronously to the rest of the application, and being the last VI to execute doesn't allow it time to properly do its job?

 

So I set up a little flat sequence (attached), and found that if you throw a Wait in between the loop termination and the invoke node, it reinitializes to default as expected. Try it yourself on your machine. I've found that expect behavior occurs when you set the wait no less than 80ms, and sometimes as much as 150ms.

 

Does anyone know why this behavior occurs?

 

 

0 Kudos
Message 1 of 4
(2,763 Views)

Maybe because that's how much time it takes your finger to come off the mouse button?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 2 of 4
(2,748 Views)
Solution
Accepted by topic author ijustlovemath

Why are you using Switch Until Released?  That should only be used for applications where you want momentary push button behavior.

 

You should be using Switch When Released.

 

I think you do have a race condition because of the wrong behavior.  You press the stop button,  it is  True while you are holding down.  The true stops the loop, you have a very short wait, then the reinit to default occurs which returns the button back to its default state.  Meanwhile, you can't operate that fast and you are still pressing the button down while all of that happens,  Then when you go and release the button, even though the VI has now stopped, that release reverses the action and returns it to the other state  (since it is now false, it returns it true).

 

That is why the wait value you add seems to work if you make it long enough.  You've given yourself enough time to naturally release the button.

 

To prove it,  make the wait particularly long.  Then run your VI and press the button down, but take even longer to release it.  You'll see the same behavior as when you add the very short or no wait, and a much more natural button press or release.

 

Make your mechanical action Switch When Released, and your VI will run like you expect.

Message 3 of 4
(2,746 Views)

LOL I think i should get a Kudo for describing the "why", even though I was too lazy to describe the "how".  😉

 

[edit] on second thought, maybe i should get a negative kudo for being lazy. [/edit]

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 4
(2,721 Views)