05-28-2019 09:04 AM
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!
Solved! Go to Solution.
05-28-2019 09:39 AM
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
05-28-2019 09:42 AM - edited 05-28-2019 10:11 AM
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...
05-28-2019 10:10 AM
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.
05-28-2019 01:59 PM
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.
05-28-2019 02:23 PM
I overlooked that this was 100 buttons. Yes, I agree that an array is a better solution.
05-28-2019 02:39 PM - edited 05-28-2019 02:43 PM
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!
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
05-29-2019 11:57 PM
Thanks for your idea! I did something very similar, using controls labels to create the string.
05-30-2019 12:07 AM
@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?)
05-30-2019 07:33 AM
@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.