12-10-2013 10:42 AM - edited 12-10-2013 10:45 AM
Dear users,
how can I simplify (or modify) the following code for better overview and maintenance:
The structure on the top is a code manipulating my cluster (the uninteresting code is blocked). On the bottom, there are clusters of multiple type defs, which I use. So, I created multiple subVIs to accept my type defed clusters (all together 4 pieces). I bound all my subVIs into a single polymorphic VI and use it as wished. In all of my subVIs, I modify the items of the cluster in the same order.
But when changing the code in one of the subVIs, I have to change the code in the other subVIs, too. Is there any way to create a single VI that is going to accept multiple type defs clusters?
Thank you for listening!
Cheers,
Solved! Go to Solution.
12-10-2013 11:24 AM
Another way to do it is to make the input a Variant. The entire thing could be handled within one subVI. The disadvantage is that outside the subVI, you must specify the type you are wiring, so that the subVI knows how to unpack the Variant. The way you have it, this is handled automatically by the polymorphic VI, as this is determined by the wire you connect to that input.
So outside the subVI, you have a Ring or Enum listing your data types, and this gets wired to a case structure with different code for each type.
12-10-2013 11:35 AM
You could also go with a LVOOP design using dynamic dispatch. The input would be a variant but processing would be the correct because the obkect type would determine the correct instance to use. You could use methods in the parent class to do the generic processing which would mean updates would only be required to be made in a single VI (method).
12-11-2013 07:00 AM
@garrettmarsh wrote:
Another way to do it is to make the input a Variant. The entire thing could be handled within one subVI. The disadvantage is that outside the subVI, you must specify the type you are wiring, so that the subVI knows how to unpack the Variant.
Thank you, garrettmarsh, thank you, Mark_Yedinak. I dived into LVOOP (well, let's say, I made a few splashes), but I won't start to implement that way: It seems to be an overkill for my subtle issue.
But because the list of my type-defed clusters is limited, I came up with the following extendable solution using a variant:
So, I can correctly read any of my cluster type defs. The remaining unsolved thing is the output. The output could be only one of the available type defs (note the difference in the numbers within the icons). But so far, it seems that I have to choose the output upfront, instead of dynamically. Any thoughts here? Can be any output a variant, too? The idea is to maintain also the cluster format and its type definition.
12-11-2013 07:36 AM
Hi ghighuphu,
I think the easiest and fastest way is using a variant for input and output.
Kind Regards,
Philipp
AE | NI Germany
12-11-2013 01:58 PM - edited 12-11-2013 01:59 PM
Just like an input an output must be of a single type. Your output can be a variant as well. However anything that will use that output will need to know which cluster that data is. Also, you can simply wire your cluster name to the case statement and use the names of the typedefs as the case selector. The FOR loop lookup is not required.
12-12-2013 06:41 AM
What I would do is go back to your polymorphic setup and turn any code that is common amonst the different polymorphic cases into a subVI. Then you just have to edit the subVIs.
12-12-2013 06:57 AM
05-13-2024 01:34 PM
These days you'd use a Malleable VI to achieve this.
05-14-2024 07:15 AM
@littlesphaeroid wrote:
These days you'd use a Malleable VI to achieve this.
Old threads being resurrected...At least this is additive.
A malleable may do the job. What I did with one of my setups was to make a polymorphic for each data type and then had a malleable VI that most of the polymorphic cases used.