09-18-2019 12:04 PM
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?
Solved! Go to Solution.
09-18-2019 12:21 PM
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.
09-18-2019 12:31 PM
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.
09-18-2019 12:35 PM
Isn't that what this is supposed to stop from happening?
09-18-2019 12:39 PM
@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.
09-18-2019 12:44 PM
@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.
09-18-2019 01:04 PM
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.
09-18-2019 01:31 PM
@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