LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to clear Event case for double key press?

Solved!
Go to solution

I have a test which is called twice in a row.  The technician presses "space bar" when the test is complete.  I make this happen by using "key focus" on the OK button.  

If the technician quickly presses the space bar a second time before the test VI is complete then the second time this VI is called it immediately recognizes the second key press from the first time the VI was called.  Thus the VI exits before the test is completed the second time.  

 

What is the best way to prevent this from happening?

Do I have to use Register For Event and Flush Event Queue or is there an easier way that I am missing?

Mark | CLA
Download All
0 Kudos
Message 1 of 8
(2,870 Views)

I ran into this same issue.  I solved it by keeping a flag value in a shift register.  When a test is started, the flag is set to true.  After test is complete, the flag is cleared.  If the spacebar is pressured during a test, I ignore the event. 

aputman
0 Kudos
Message 2 of 8
(2,851 Views)

Hi Mark,

 

If I understood your question correctly, you should be able to solve it by disabling the OK Button as soon as the event triggers. Then you need to enable it at the beginning or end of the VI. Make sure it is enabled before trying to set key focus.

 

Capture.PNG

0 Kudos
Message 3 of 8
(2,833 Views)
Solution
Accepted by topic author Mark_L

Isn't that what this is supposed to stop from happening?

 

singlweCapture.PNG

========================
=== Engineer Ambiguously ===
========================
Message 4 of 8
(2,829 Views)

@RTSLVU wrote:

Isn't that what this is supposed to stop from happening?


That doesn't exist in older versions of LabVIEW so it wouldn't have helped me.  May be useful for the OP.

aputman
0 Kudos
Message 5 of 8
(2,823 Views)

@RTSLVU wrote:

Isn't that what this is supposed to stop from happening?


I don't think it helps in this case because as soon as you start handling the event it's not "in the queue" anymore.

0 Kudos
Message 6 of 8
(2,814 Views)

I did 2 things to fix this:

1. Set limit on the number of events for the value change to 1.

2. Set the key focus to FALSE inside of the event case.

 

1 prevents extra events during the 1.5 seconds before the Event Structure is eventually called.  2 prevents the button to be pressed (via the spacebar) while the event is being handled.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 8
(2,804 Views)

@Mark_L wrote:

....  

 

What is the best way to prevent this from happening?

Do I have to use Register For Event and Flush Event Queue or is there an easier way that I am missing?


"Best" you will have to decide.

 

But Dynamic Events can be "unregistered" inside an event case. Look at this Nugget by Ton to see an example.

 

I used that recently in an application where I registered for a User Event and once I received the event I was looking to find, I unregistered the User Event so my code was not being distracted by the events.

 

When it was time to pay attention to the User Event again, I re-registered for the event...

 

And the song started over again.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 8 of 8
(2,785 Views)