LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

event structure gets triggered twice

Solved!
Go to solution

Why wouldn't it trigger twice?  It starts false.  You push it and it goes true.  You spend time cycling through all of the booleans.  Then, you wait 200ms.  Then, you cycle through all of the booleans setting them to false.

 

If you're going to use this nonsense, move the delay.  Change the value to false immediately.  You also have the index of the changed boolean by using the iteration terminal from the first for loop.  Why are you cycling through all of the booleans instead of just setting the specific value to false instead?  You know the index.  You know the value.  Stop doing silly things.

 

Really, you want something that is going to poll the button.  Why are you going through all of this hassle to get away from a polling architecture when that's the exact behavior you want?  Ditch the event structure and use the polling style. 

 

If you want to use the event structure, you need to knock off the current system.  Use the "NewVal" entry to run one of two types of logic.  If NewVal = true, start executing the button and save the index to a FGV.  If NewVal = false, set the FGV to -1.  In the timeout case, use the FGV to determine which button needs to be added to the display.  If -1, add nothing.  If a legitimate index, add the value you wish.  But, this STILL might as well be polling.

0 Kudos
Message 11 of 26
(3,619 Views)

Natasftw, I used the 200ms delay because of front panel button press visual effect. Without the delay, the button press will not have visual effect at all. Performance is not my major concern here, what I want to achieve is to back space one digit for swift "BS" press and back space repeatedly for long "BS" hold. It's hard to understand your description, could you attach an example? Thanks.

0 Kudos
Message 12 of 26
(3,612 Views)

I think you missed the point on that piece.

 

If you put the delay before you rewrite the false value to the control, you create a much larger period of time where the value isn't being read.  If you hold it for less than 200ms, you'll trigger the event structure twice (value change from false to true.  value change from true to false.)  If you hold it for 200-400 ms, you'll trigger it three times (value change from false to true.  control is written false.  value change from false to true.  value change from true to false.)  This continues on for however long you hold it.  You'll always get one more read.

 

Again, you want a polling architecture for what you're hoping to accomplish.  You don't care WHEN the button is pressed.  You want to know what its value is every 200ms.  If it's true, run your function.  If not, don't.  You're making something very simple complicated by using a poor architecture design decision.

0 Kudos
Message 13 of 26
(3,588 Views)

natasftw,

 

The delay is before writing all buttons to false.

If I set the delay to zero second, it will still trigger twice.

If I set the delay to 2 seconds, it will only trigger twice.

0 Kudos
Message 14 of 26
(3,584 Views)

@guangdew1 wrote:

Natasftw, I used the 200ms delay because of front panel button press visual effect. Without the delay, the button press will not have visual effect at all. 


Get rid of all that extra code and change the buttons to latch action. A latch action boolean will show the changed value until the terminal is read by the code, so all you need to do is place the terminals inside a sequence frame tied to a small wait or reset them in the timeout event. See attached quick modification.

 

Message 15 of 26
(3,567 Views)

altenbach, thanks for your example, you code is definitely cleaner than mine. What about the back space issue, should I just move it out of event structure and use a independent while loop to handle it?

0 Kudos
Message 16 of 26
(3,552 Views)

@guangdew1 wrote:

What about the back space issue, should I just move it out of event structure and use a independent while loop to handle it?


What "issue"? If you want an autorepeat on the backspace, use code similar as I suggested earlier. I have a look later...

0 Kudos
Message 17 of 26
(3,549 Views)

altenbach, I want the repeated back space while holding the back space button. Your previous example used "switch until released", this mechanical action causes the event structure get triggered twice.

0 Kudos
Message 18 of 26
(3,544 Views)
It does not matter if the event fires twice. Just use conditional code that depends in the current value.
0 Kudos
Message 19 of 26
(3,537 Views)
Solution
Accepted by guangdew1

Here is how you can handle the backspace as well (I'm pretty sure Altenbach already showed you similar to this).  The BS button should be set to Switch While Pressed.  All other buttons should be Latch When Released.  You will see the buttons change colors when you press them down.  But the actual change does not happen until you release the button.  So I see no reason for those delays.


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 20 of 26
(3,533 Views)