LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event-driven button value change event for press/release

Solved!
Go to solution

Hi all,

 

I've got the following code to open/close a few valves through a cDAQ.

For example, I want V1 to open when the button is pressed and to close when the button is released, the mechanical action for all button is set to Switch until released.

How can I best archieve this, as the code I've written fires the "value change" event only on button press and not when it's released, but logically it should fire twice as the value changes from "false" to "true" when pressed and from "true" to "false" when released

0 Kudos
Message 1 of 18
(3,708 Views)

You want "Switch Until Released"

0 Kudos
Message 2 of 18
(3,706 Views)

OK, I'll try it, anyway this is my code.

 

It's a subVI running in a subPanel

0 Kudos
Message 3 of 18
(3,670 Views)

You have a complete misunderstanding of dataflow. Your loop cannot go to the next iteration until ALL events have fired. So if you switch one button and off again, the off event must wait until all other event have fired and the loop has gone to the next iteration.

 

Also, your buttons are set to "switch when pressed", NOT "switch until released"!

 

Pleas tell us more generally what you want to do, not how you want to do it.

0 Kudos
Message 4 of 18
(3,663 Views)

Heck.  When  I first saw the image in message #1, I though that was just snapshots of each case of the event structure displayed side by side.  I didn't realize that is exactly how the VI was laid out with a dozen event structures!

Message 5 of 18
(3,657 Views)

Sorry, I don't have any drivers installed, so I cannot look at your DAQ assistant configuration, but maybe all you need is the following:

 

altenbach_0-1612813299232.png

 

 

Also PLEASE don't maximize the front panel and diagram to the screen. Extremely annoying!

 

0 Kudos
Message 6 of 18
(3,653 Views)

In principle, all you probably need is a polling loop run at a reasonable loop rate (i.e. my above image but without the event structure but a 50ms loop wait). I would also probably use lower level DAQ function.

0 Kudos
Message 7 of 18
(3,636 Views)

Ok, I'm trying to respond all at once.

First my bad, should have said that I'm fairly new to this kind of programming, I'm more used to classic code programming.

Said this, I thought that having a case for every single button (as done in classic code) was the right way to do it, and not having the same handler for every case.

 

The goal of this sub VI is to open/close some valves through a cDAQ-9185 with an NI-9485-SSR module, reads "press button -> valves open, button stays pressed -> press button -> valves closes, button releases" so i can manually controll each valve/pump

0 Kudos
Message 8 of 18
(3,626 Views)

Having a event case for every button is okay.  But you need them in the same structure.

 

You need to know the rules of Data flow.

 

1.  A node (and this might be a function, subVI, or a structure such as a while loop or event structure) can't execute until it has received all its inputs.

2.  A node can't complete and return any outputs until all the code inside of it has completed its execution.

 

The correct thing is to have 1 event structure with the 1 or more event cases as needed (either 1 event case handling any of the buttons, or multiple event cases each handling a button).

 

When you have 1 event case, the event structure completes when any event occurs and is executed, thus allowing the while loop to finish and iterate around to handle the next event.   When you have all those separate event structures, the while loop's iteration won't complete until ALL the event structures have completed which means any event in everyone of those structures.

0 Kudos
Message 9 of 18
(3,616 Views)

Ok, so if I understood correctly, in my original code the while loop waited for every interation to execute once every event to then go to the next iteration.

So the right thing to do what I intended is to put all in 1 event structures which handles every buttons value change event and always pass all values to the DAQ right?

 

Now how can I implement to set some default values into the DAQ, so lets say, V7 should be closed when I start this VI, is the correct way to create the property node for the button's value outside the while loop and feed it into a different DAQ node? Is there a way to do it through the same DAQ node through wich I execute the events?

0 Kudos
Message 10 of 18
(3,611 Views)