From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
01-14-2019 04:19 PM
I'm working on an application that has a large number (20-30) of boolean buttons on the front panel. When any of them are pressed, it drives an event structure that sends a message to one of several actors based on which button was pressed (using the Label Text property from the event reference to determine which button was pressed). Right now, I have to manually select each of the buttons to include in the event. However, this seems pretty inefficient/error prone. Is there a way that I could group all of these buttons into a single entity that I could then select from the event structure?
Solved! Go to Solution.
01-14-2019 04:38 PM
Kind of. You can put them all in a cluster. If only one of them can be pushed at a time, then you just need to look for the true value. Otherwise you will need a little more thoughtful logic to figure out which button was pressed.
01-14-2019 04:40 PM
You can also use dynamically registered events, then all you have to do is add another reference to the array:
01-14-2019 04:42 PM
I see 3 options:
Cluster has value change event and "controls" property to get reference of hte actually pressed button.
You can list multiple events in the same frame. It gives reference of the activated control.
You can register events dynamically and just add reference to the new button into array.
01-14-2019 04:47 PM
Ideas that were previously stated with some mods. Traverse for all booleans, then dynamically register. Have a default case that does nothing in case you want to action to occur with a boolean.
mcduff
01-14-2019 04:49 PM
Thanks! I had a feeling there was a way to do it with user events, but hadn't used them before.
01-14-2019 05:12 PM
@mcduff wrote:
Ideas that were previously stated with some mods. Traverse for all booleans, then dynamically register. Have a default case that does nothing in case you want to action to occur with a boolean.
mcduff
Maybe I am missing something but I don't see how this is useful. Wouldn't you would still need to group the button references in an array in order to compare the event control reference against to know which one was pressed since there is no guarantee of the order that the controls are parsed? Sorry but I'm just not getting it.
01-14-2019 05:17 PM
In this particular use case he says he uses the label text from the button to decide what action to take, and there's a CtlRef output in the event structure that gets you a reference you can get the text from.
01-14-2019 05:17 PM
The traverse VI finds all the booleans in the VI. You could do some filtering if you wanted after this step if you wanted, for example to eliminate indicators.
The traverse VI returns an array of references, you use this array to dynamically register for events, such as value change. When one of the value changes, use the control reference in the event structure to read the label of boolean. Use this label as a case structure to decide what to do next for a particular button.
What is nice about the traverse VI is you do not need to create an array of references, it finds them for you.
mcduff
01-14-2019 05:25 PM
@Gregory wrote:
Kind of. You can put them all in a cluster. If only one of them can be pushed at a time, then you just need to look for the true value. Otherwise you will need a little more thoughtful logic to figure out which button was pressed.
Use the not equal comparison and compare the old and new values. The latching action here is important also.
mcduff