07-21-2025 01:47 PM
I am working on a series of VIs that all need to perform the same basic actions on a state cluster, namely bundle/unbundle by name. Each VI has a different state cluster, but they contain similarly named elements. i.e. each cluster will have the following named elements: DAQ Tasks, ShotNumber, Data, Config, where Data is a different datatype for each VI. For this VI let's say I want to unbundle ShotNumber, and rebundle it with a new value, but since Data is a different shape/type for each VI I can't just use a single subVI for this. My thought was to use a malleable VI with a Type Specialization Structure, but I quickly became lost in the weeds on this and it felt like I was over complicating it. Should I just have the cluster input be a variant, and then convert the variant to the correct type def based on some other logic? Or is there a better way to do this?
Solved! Go to Solution.
07-21-2025 04:03 PM
Hi,
Your approach seems correct to me.
I would just remove the Type Specialization Structure, to allow any cluster containing the appropriate named elements (the caller will be broken in case an incompatible data type is wired to the malleable VI).
Also, I would change the "Label" input data type to a type-defined enum rather than a string, since the bundled cluster elements are known at compile-time.
Finally, I would remove the "Actions" output, as it seems redundant with the "Label" input.
Regards,
Raphaël.
07-21-2025 04:55 PM - edited 07-21-2025 04:55 PM
If you delete the type specialization structure what should the input/output cluster be wired as on the front panel? Just an empty cluster? A cluster with the shared named elements I am going to unbundle?
07-22-2025 12:58 AM
I can think of two relevant options:
07-22-2025 01:16 AM - edited 07-22-2025 01:17 AM
Ooooh good call on that OpenG library. I use a lot of their cluster manipulation functions already (that same VI even) I didn’t think of just giving the polymorphic terminal a variant actually. I’ll test that out tomorrow, but I don’t see any reason why that wouldn’t work.
07-22-2025 09:22 AM - edited 07-22-2025 09:23 AM
@nwford_he wrote:
I am working on a series of VIs that all need to perform the same basic actions on a state cluster, namely bundle/unbundle by name. Each VI has a different state cluster, but they contain similarly named elements. i.e. each cluster will have the following named elements: DAQ Tasks, ShotNumber, Data, Config, where Data is a different datatype for each VI. For this VI let's say I want to unbundle ShotNumber, and rebundle it with a new value, but since Data is a different shape/type for each VI I can't just use a single subVI for this. My thought was to use a malleable VI with a Type Specialization Structure, but I quickly became lost in the weeds on this and it felt like I was over complicating it. Should I just have the cluster input be a variant, and then convert the variant to the correct type def based on some other logic? Or is there a better way to do this?
If there is a limited number of possible cluster types, you would create a type specialization case for each and unbundle/process the relevant cluster element right inside the type specialization. Now the cluster names don't even need to exactly match as long as you know what they are for each typedef.
We probably can give more specific advice once we know the operations that need to be supported and other details.
07-22-2025 12:40 PM - edited 07-22-2025 12:41 PM
OpenG worked! No malleable VI even needed. And since I already have the typedef I am sending as a message in there, I can always make sure that my names are synced up using the Get Data Name VI in the same library (it's almost like it was made for this since the output terminals of one line up perfectly with the input terminals of the other.) Thanks.
Updated code for anyone that stumbles upon this in the future.
07-22-2025 12:43 PM
Just bear in mind, nothing will beat a VIM with type specifiers for performance, but if that's not an issue, the OpenG solution should be fine.
07-29-2025 05:25 PM
@nwford_he wrote:
OpenG worked! No malleable VI even needed. And since I already have the typedef I am sending as a message in there, I can always make sure that my names are synced up using the Get Data Name VI in the same library (it's almost like it was made for this since the output terminals of one line up perfectly with the input terminals of the other.) Thanks.
Updated code for anyone that stumbles upon this in the future.
This seems a bit convoluted / impractical to me:
- When using your VI, the RT state cluster must be converted to and from a variant.
- It does not allow flexible data types for your common named cluster elements.
- The use of the string data type for "label" opens a possibility for typos in the element names, while it seems they are known at compile-time.
- The name obtained with "Get Data Name.vi" will simply give the cluster constant's name, which is independent from the type definition.
I see 2 methods (here for your example of writing a cluster element as a JSON string):
1. More efficient: Using a VIM (Malleable VI) and in place bundles / unbundles:
The VIM will adapt to any cluster that has at least the common named elements, with the correct data types (depending on restrictions).
2. More generic: Using a VIM (Malleable VI) and OpenG cluster functions:
Here it does not need specific implementation for each specific named element, but is less efficient because of the decomposition / recomposition of the cluster by the OpenG functions.
Attached is a benchmark to compare both methods.
Regards,
Raphaël.