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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to code multiple choice numeric inputs / bit flags

Solved!
Go to solution

@tst wrote:

 

For the all options thing, you could add a special boolean in the cluster (or on the connector pane of the wrapper) which you look at and if it's T, you set all the others to T. Another option is to have the cluster as an output of a subVI (so that you can have a clean and safe way to bundle it by name) and then that subVI output two clusters - one with all F and one with all T. If the user wants all T, they simple take the second output and wire it in directly.

 

 


I'm reading over this again, now that I actually have to implement both this function and a similar (but worse) one (with far more inputs, and numerical, not boolean).  Anyway, there is something I don't understand -- what do you have in mind as having the cluster as an output of a subVI?  If takes all the inputs and builds a cluster, it is no better, interface-wise, than the function whose interface it is coming to smplify.  Or did you mean a sub-VI with no inputs at all, that just outputs two clusters that I can use as starting points and modify?

 

And why is ths a "clean and safe way" to bundle by name?

 

Thank you.

Batya

0 Kudos
Message 11 of 21
(890 Views)

@BPerlman wrote:

Or did you mean a sub-VI with no inputs at all, that just outputs two clusters that I can use as starting points and modify?

Yes, that is what I meant. You could also just put a constant of the cluster on the BD and use that for the bundling, but if it's a typedef and you want it to have specific values, you might have a problem if you modify the typedef, because that tends to cause constants of the typedef to lose their custom values. That's why it's safer - you can set all the values you want explicitly in the subVI.


___________________
Try to take over the world!
Message 12 of 21
(882 Views)

I think I understand now.

 

Thank you!!

 

Batya

0 Kudos
Message 13 of 21
(877 Views)

OK, I've set up one VI with the input as a cluster.  I made the control into a typedef.  I made a function which outputs a cluster with all the elements set to zero.  (This one is a cluster of integers, not booleans.  I have a few such functions; some are bools, some are ints.)

 

Now I want to create an instance which is all zeroes and then modify one of the elements to a different value, and then pass that modified cluster to my VI.

 

I don't see how to create the insnance and then modify one element.

 

What am I missing?  Enlighten me.

 

Thank you.

Batya

0 Kudos
Message 14 of 21
(874 Views)

Call the second subVI. Wire the output cluster coming from that VI into the top input of a bundle by name node. Use the node to set the value you want to change in the cluster and wire the resulting cluster into your first VI.


___________________
Try to take over the world!
Message 15 of 21
(854 Views)

Thank you!! (And thank you for the clear, respectfully worded answer to what must have sounded like a pretty dumb question!  The difference between a dabbler and someone who knows what they are doing 🙂  )  I didn't understand that "bundle by name" meant "replace by name".  I did do a basic labVIEW course, but I guess I don't remember everything.....)

 


Batya

0 Kudos
Message 16 of 21
(839 Views)

OK, I tried that for one of the functions I am working with -- and was no longer able to deploy (to the RT target) the VI which called the function.  I posted about it here (VI loaded with errors on target).

 

So I guess I'll have to go back to the old interface on that function (in that case, the old interface has a separate input to the VI for each input; it is not bitflags in this particular case, but integers), with the inputs defaulted to zero so you only have to wire the ones you want to use.  But it is a very "busy" wiring pattern.

 

So I guess for the boolean inputs I'll also make a "busy" wiring pattern (about the same number of inputs) with defaults.  I hope it will still be easier to use than than ORed bitfields, which make more sense in "C" than in LabVIEW I think.

 

Thank you.

Batya

0 Kudos
Message 17 of 21
(818 Views)

@crossrulz wrote:
Rings are integers.  This way you can have descriptions go along with your integers.  I just figured out that the OR Array Elements doesn't work with integers, but you can use FOR loop to do the job easily enough.




This really does look nice on the front panel, but does the user of the API who is wiring in my VI get to see the descriptions that go with the integers?

 

Thanks.

Batya

0 Kudos
Message 18 of 21
(812 Views)

@BPerlman wrote:

This really does look nice on the front panel, but does the user of the API who is wiring in my VI get to see the descriptions that go with the integers?

Thanks.

Batya


If the control on your subVI front panel which they are wiring into has the ring control, then when a user of your API right clicks and selects "create constant" a ring will be created. So, the answer is yes. Just make sure your front panel control isn't an array of integers but more specifically is an array of rings and you will be fine. 

 

This won't stop the user from wiring up an integer directly, but to some extent you can only save programmers from themselves so much ;). This may be a good use case for adding context help to your VI in the VI description.

Message 19 of 21
(795 Views)

Thanks.  We do add context help to most of our projects.  Not all programmers like to read help though 🙂

Batya

0 Kudos
Message 20 of 21
(790 Views)