LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to know which boolean control was pressed

Solved!
Go to solution

Hello all!

 

Recently I've encountered a following problem:

 

I have around 100 Boolean switches scattered on the front panel. User can turn on only a specific, predetermined, number of switches (have to check it) at the same time. Then after pressing a button, labels of selected switches will be written to a txt file, new row for each press of the button.

 

Any help will be appreciated!

0 Kudos
Message 1 of 10
(3,298 Views)

Hi IG.B

 

Your best bet is creating a reference to the controls and passing them to property node.

Here you can read all the properties of the control like its name, label value, ...

 

More info on property nodes:

https://zone.ni.com/reference/en-XX/help/371361P-01/glang/property_node/

 

Creating a reference to a control:

https://zone.ni.com/reference/en-XX/help/371361R-01/lvhowto/creating_control_reference/

 

Would you mind telling us how you read the buttons? (Event structure, Polling, ...)

 

Kind regards,

Natan Biesmans, CLA

Surely not everyone was kungfu fighting.
0 Kudos
Message 2 of 10
(3,271 Views)
Solution
Accepted by topic author IG.B

Interesting assignment... I would probably use a Boolean array for all of your controls. then you can watch the array for changes (OR Array Elements)  then search for the element that is a 1 and get it's Index and use that to select your text for the file.\

 

Something like this...

 

Boolean1.png

========================
=== Engineer Ambiguously ===
========================
0 Kudos
Message 3 of 10
(3,264 Views)

You could make an event in an event structure that includes all of the switches. Then when one is switched you can use the reference to get the control name.You can then have logic to add/subtract the control name from an array, which you can use to determine how many buttons are on. This array can be passed via a shift register, and when your write button is pressed you can read these control names and write them to the file.

0 Kudos
Message 4 of 10
(3,250 Views)

How do you place a hundret Button controls on your front panel? Isn't it better, to use a 2D- Array of Buttons? This would ease the problem dramatically.

Greets, Dave
0 Kudos
Message 5 of 10
(3,218 Views)

I overlooked that this was 100 buttons. Yes, I agree that an array is a better solution.

0 Kudos
Message 6 of 10
(3,205 Views)

If the Booleans are truly scattered then consider creating an array of reference to the controls and pass that to a "Event registration node" set for "value change".

 

Wire that event reg wire to an event structure and configure an event for value change from the dynamic event. 

 

Inside the event select the "control ref" and wire that to a property node set to read the label.

 

Using that approach we do not have to configure an event for each of the hundred controls, only one event required.

 

Bonus is it scales well.

 

Double Bonus if you build the array of references using a sub-VI that "in the darkness binds them" into a an array.

 

Trivia Time!

 

Spoiler

 

In LV 6.1 we were limited to only 600 control and indicators max. You do not want to learn how I ran across that limit.

 

I used the approach described above to pass my first CLA exam when the CLA exam was really an extreme LV trivia test.

 

 

 

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 7 of 10
(3,199 Views)

Thanks for your idea! I did something very similar, using controls labels to create the string.

0 Kudos
Message 8 of 10
(3,147 Views)

@daveTW wrote:

How do you place a hundret Button controls on your front panel? Isn't it better, to use a 2D- Array of Buttons? This would ease the problem dramatically.


Using 2D array will group the controls on the screen. Is there an option to place them in different positions on the screen? (Am I missing something?)

0 Kudos
Message 9 of 10
(3,144 Views)

@IG.B wrote:

@daveTW wrote:

How do you place a hundret Button controls on your front panel? Isn't it better, to use a 2D- Array of Buttons? This would ease the problem dramatically.


Using 2D array will group the controls on the screen. Is there an option to place them in different positions on the screen? (Am I missing something?)


I've made a dozen applications where I had dozens of bools on the front panel. Every bool had a specific function named with the label. You can't do that with separate elements in an array. This problem and solution might be useful to me.

PaulG.

LabVIEW versions 5.0 - 2020

“All programmers are optimists”
― Frederick P. Brooks Jr.
0 Kudos
Message 10 of 10
(3,127 Views)