Jump to content

Programmatically select all boolean (best way to avoid race condition)


mthheitor

Recommended Posts

Hello :)

 

The attached code will select all boolean from my VI and get the value of each one. Then build a array of boolean that will be used in another VI.

My doubt is about the order of the boolean. In my example there four boolean: 1) "Home", 2) "Ensaio", 3) "Análise" and 4) "Configurações".

How can I ensure the order of the boolean inside the array?

I mean, if a user delete the boolean named "Ensaio" (2nd element of the array) and add another one, it will be the second element of the array or will be last one?

 

Note 1: I'm using this code because the other users will add or remove boolean from the Front Panel, and I don't want them mess around with the block diagram.

Note 2: Each boolean is customized, having different images each one.

 

 

captura.PNG

Link to comment

An indicator has two "labels". The label and caption.

Show the caption (should be defaulted to the same as the labe and hide the label). Then rename the controls to 1_Home, 2_Ensaio etc (The caption will be what the user actually sees without the numbers).

Now you can get the label name, split off the number and put it into a cluster with the value (if you have less than 10 controls, you don't need to convert to a numeric). Make sure the number is the first item in the cluster because LabVIEW will automatically sort on the first element so you can use the sort array directly. From there you can sort the cluster and now you know your clustered booleans are in numerical order.

Link to comment
6 hours ago, mthheitor said:

My doubt is about the order of the boolean. In my example there four boolean: 1) "Home", 2) "Ensaio", 3) "Análise" and 4) "Configurações".

How can I ensure the order of the boolean inside the array?

I mean, if a user delete the boolean named "Ensaio" (2nd element of the array) and add another one, it will be the second element of the array or will be last one?

The method you invoke on the Panel reference always returns the Controls in the order that they were created.

aka. If you delete the second element and create a new one (even with same label), it will be added to the end of the list. 

Link to comment

to the OP: Be mindful that the "Traverse for GObjects" serves the array in the reverse order from Panel:Controls[] method, probably because of the way it stores the references in the recursion loop.

@infinitenothing You're totally right. Tab order it is, with newly created controls added at the end of the list.

Edited by Francois Normandin
Link to comment
  • 4 weeks later...

So a while ago I wrote a XNode that would add functionality to the traverse for GObjects.  One thing it would do is order the references based on their positioning on the front panel or block diagram.  The most common use for me was for something like a grid of buttons.  I would want them ordered from left to right and top to bottom so I made an enum input to the XNode that orders them after finding them.  It would also return the reference as a boolean so no casting was needed after.  Of course this goes with the normal "XNodes are experimental" statement but you could look at the code and see how I did it if you wanted to not use it.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.