LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I stop button controls responding to both mouse down and mouse up?

Hi,

On my front panel I have several buttons which are all set to 'Switch Until Release' type. I've come across the problem where they sometimes stick on even when the mouse has been released (see earlier posting) and this has been confimed by NI as a LV bug.

To get round this I manually write FALSE to the button controls once my LV prog has read them but I now find that some of the buttons having been cleared go true again on the release of the mouse button as though the mouse release can also set them true.

Is there any way I can stop them responding to the mouse release?

Thanks,
Dave.
0 Kudos
Message 1 of 8
(3,825 Views)


@Dave123 wrote:
To get round this I manually write FALSE to the button controls once my LV prog has read them ...
Isn't that equivalent to a latch action? Whay don't you set your buttons to e.g. latch when released?
 
Could you attach a simplified version of you code that shows the problem?
0 Kudos
Message 2 of 8
(3,820 Views)
you should use the mechanical action latch when released
0 Kudos
Message 3 of 8
(3,801 Views)
Hi,

Thanks for your reply, sorry for the slow response, I've been away from my desk since last week.

I'd like to use latch when released buttons but I'm using local variables of the buttons so I can read the current values of them in different parts of the program.

So to simulate latch when released I've written my program to set to FALSE the state of the button once it has read that it has been pressed.

I've created a simple program (ButtonForceClearExample.vi - attached) to illustrate what's happening.

In this program there are two buttons and one LED indicator.

The program sits in a loop until the STOP button is pressed.

When the Toggle button is pressed the LED is set to the opposite of its current boolean value. The program waits briefly then sets the toggle button to false and continues round the loop.

Keep the toggle button held down for a second or two, release it and you should see the button goes true again (and is promptly cleared in the case). Why does a mouse button release set the button to true?

Dave.

Message Edited by Dave123 on 11-16-2005 03:55 PM

Message Edited by Dave123 on 11-16-2005 03:56 PM

0 Kudos
Message 4 of 8
(3,785 Views)
here is an example of what you should do
0 Kudos
Message 5 of 8
(3,772 Views)


@Dave123 wrote:
I'd like to use latch when released buttons but I'm using local variables of the buttons so I can read the current values of them in different parts of the program.

So to simulate latch when released I've written my program to set to FALSE the state of the button once it has read that it has been pressed.

This sounds like a very bad idea if other parts of the code need to react on the state of a pseudo-latch action boolean. There is simply no guarantee that other parts of the code even see the transition due to possible race conditions. What if the boolean gets reset before the other code can read it? What if the other code reads the true multiple times because it loops faster than 200ms?

How many other places do you possibly need to read it? Maybe you can use latch action combined with an event structure to cause parallel code to react to the value change? (see attached example, LabVIEW 7.0). Maybe you should rethink your code, there might be better alternatives.



@Dave123 wrote:
Keep the toggle button held down for a second or two, release it and you should see the button goes true again (and is promptly cleared in the case). Why does a mouse button release set the button to true?

Easy! In this case, you should use "switch when pressed" as mechanical action. You use switch until released, which confuses LabVIEW.
 
Switch when released does two things: (1) It switches to true as long as you keep the button pressed. (2) When you release the button, it switches to off. Now, if your code inverts the switch via a local variable while it is still pressed, the release tries to invert the current state and turns it off-to-on again by mistake.
 
This might be a slight flaw (bug) in the LabVIEW code. Releasing the button should force a FALSE to the button, not an iversion of the current state.
 
 
Message 6 of 8
(3,757 Views)


@altenbach wrote:


@ Dave123 wrote:
I'd like to use latch when released buttons but I'm using local variables of the buttons so I can read the current values of them in different parts of the program.

So to simulate latch when released I've written my program to set to FALSE the state of the button once it has read that it has been pressed.

This sounds like a very bad idea if other parts of the code need to react on the state of a pseudo-latch action boolean. There is simply no guarantee that other parts of the code even see the transition due to possible race conditions. What if the boolean gets reset before the other code can read it? What if the other code reads the true multiple times because it loops faster than 200ms?

How many other places do you possibly need to read it? Maybe you can use latch action combined with an event structure to cause parallel code to react to the value change? (see attached example, LabVIEW 7.0). Maybe you should rethink your code, there might be better alternatives.




- Thanks.
My program is written such that only one part of the program at a time needs to see the button press. The program then moves on and another area monitors the button presses. When a button is pressed and cleared in one part of the program another part of the program is not expected to see it.



@ Dave123 wrote:
Keep the toggle button held down for a second or two, release it and you should see the button goes true again (and is promptly cleared in the case). Why does a mouse button release set the button to true?

Easy! In this case, you should use "switch when pressed" as mechanical action. You use switch until released, which confuses LabVIEW.
 
Switch when released does two things: (1) It switches to true as long as you keep the button pressed. (2) When you release the button, it switches to off. Now, if your code inverts the switch via a local variable while it is still pressed, the release tries to invert the current state and turns it off-to-on again by mistake.
 
This might be a slight flaw (bug) in the LabVIEW code. Releasing the button should force a FALSE to the button, not an iversion of the current state.
 
 




- I agree, writing FALSE to the button should set it to FALSE and not invert it assuming it is still ON.

Thanks,
Dave.
0 Kudos
Message 7 of 8
(3,734 Views)


@Dave123 wrote:

- I agree, writing FALSE to the button should set it to FALSE and not invert it assuming it is still ON.


Yes, the behavior is somewhat unexpected and I made a quick note over in the bug thread .
 
Still, the main flaw was in your code, because you create a race condition by modifying the control via a local variable while it is still under control of the user. If you select "switch until realeased" the operator must expect that the boolean remains TRUE while the button is pressed. It seems like a bad idea for the program to fight the user and pull the carpet from under his feet via a local variable. 🙂
Message 8 of 8
(3,719 Views)