02-08-2021 10:22 AM
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
Solved! Go to Solution.
02-08-2021 10:26 AM - edited 02-08-2021 10:27 AM
You want "Switch Until Released"
02-08-2021 12:00 PM
OK, I'll try it, anyway this is my code.
It's a subVI running in a subPanel
02-08-2021 12:30 PM - edited 02-08-2021 12:34 PM
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.
02-08-2021 12:44 PM
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!
02-08-2021 12:51 PM - edited 02-08-2021 01:41 PM
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:
Also PLEASE don't maximize the front panel and diagram to the screen. Extremely annoying!
02-08-2021 01:39 PM - edited 02-08-2021 01:40 PM
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.
02-08-2021 02:49 PM
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
02-08-2021 03:38 PM
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.
02-08-2021 04:11 PM - edited 02-08-2021 04:14 PM
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?