02-03-2010 11:01 AM
I have a large number of variables (say 20 or 30) that I would like to initialize, cluster and then pass to my various state cases. Is there a way to define the variables in something like the type definition that you guys taught me how to do for enums that would make for easy maintenance? Would you just create a type definition with the variables as controls with their default values set in the type definition...but then how would you cluster them so they would become one variable (All Variables type def) when you brought them to the main program diagram?
Trying to be neater.
Thanks
Hummer 1
Solved! Go to Solution.
02-03-2010 11:03 AM - edited 02-03-2010 11:04 AM
Hi Hummer,
why don't you create the cluster as typedef with all those "variables" included?
And what's wrong with an init state in your state machine, where you cluster individual "variables"?
02-03-2010 11:14 AM
Thanks,
When I bring that cluster into the main diagram, it shows as a list of variable values ... I would rather it show as a reference of some kind to the single type def...how would I do that?
We're on the right track I think.
Hummer 1
02-03-2010 11:18 AM
Hi!
I'm not sure if this will help you at all. But your question is "How do you...". Well, I would probably wrap these "variables" up in LVOOP class(es). If you are familiar with type defs, an LVOOP class can be used in a similar way. You define your cluster as a ctrl that is part of the Class, then make data accessors to all the items in your cluster. LabVIEW makes data accessors automatically, which are great for trapping errors while writing back and forth from your cluster.
You can then drop your Class as an object constant in your block diagram (saves you the messy look of all those line items from your type-def in your block diagram).
I'm on quite a LVOOP kick with my last few projects. Its totally worth the time to learn. It has mostly replaced what I was using Action Engines for, and then some.
02-03-2010 12:25 PM
This looks interesting...how do you "unbundle" a class...I know how to do a cluster, but how do I get to the individual elements within the class to read and write them?
Thanksl.
Hummer1
02-03-2010 01:09 PM
You HAVE to use data accessors. Open your data cluster, righ-click on a control and select "Create Accessor". From there you can select all of your fields and LabVIEW will automatically make "Read <field>.vi" and "Write <field>.vi" with dynamic dispatch and error terminals.
To me, this seemed like a hassel at first. But this is actually a really good thing for troubleshooting and for creating single entrance points to read and write your data. Its actually a really good thing, and NI was smart so they designed it that way. The actual cluster data can only be unbundled by a child VI within the Class (because it is "private" data).
02-03-2010 01:11 PM
The Unbundle by Name and Bundle by name functions will not attach to the class box...in the help menu it says something about being members of the same ... The main front panel and the class/ctrl are in the same project ... how do I get them to talk to each otehr?
Not Humming yet...
Hummer 1
02-03-2010 01:15 PM
Hi Hummer1,
I like the LVOOP idea, but you can also just do it like this. Since it's a typedef, you just open the custom control, make changes, and they propagate through...just like they did with the enum typedef.
Did I misunderstand your question?
d
02-03-2010 01:20 PM
So, by the accessor method...(made the read accessors ok)...you have to pull one accessor in for each variable you want to read and then another for each one you want to write?
Hummin now...
Hummer 1
02-03-2010 01:24 PM
Thanks Dian...
when I tried it that way, when you pull the type def into the block diagram of the main program, the entire list of variables (without names) shows up in a cluster...What I was hoping for was a single icon...like a reference to the typedef that could then be attached to the wire leading to all my states that need variables...Can you do that somehow?
Thanks.
Hummer 1