11-14-2008 08:03 AM
Hello,
I'm trying to write a generic subVI that is reusable that can adapt to the input type (a cluster but with contents unknown) and an output type (again a cluster). I would have thought that this is easy as my VI can iterate through the controls property of the clusters and update contents appropriately, but LabVIEW checks the types of the main VI with that of the subVI and reports an error because they are different.
I thought maybe i could change the input type to the subvi is a variant and I somehow map it to a cluster, but I can't get something like that to work.
Ultimately, I'm reading data from a configuration file, the user provides a cluster that defines the datatype they want and an array that maps from the configuration file to the cluster (all in text form).
I've seen a few posts, but nothing concrete with examples, or with XML (which is a file format I can't use).
Thanks,
Jason.
11-14-2008 08:28 AM
Jason,
if the clusters are known (but may have different content at different instances), you'd go for polymorphic vis.
Please refer to "Building Polymorphic VIs" in the LabVIEW Help for further information.
hope this helps,
Norbert
11-14-2008 08:38 AM
Take look at the code I posted in this nugget that does something similar by using control references. I believe one of the methods I mentioned in that should help.
Ben
11-14-2008 09:38 AM
Hello Norbert,
I thought about polymorphic and reviewed some examples. It seems like a similar concept to C++'s overloaded functions. If this is the case, then it's just as easy to copy the VI and replace the clusters for each project as each project will have it's own unique cluster.
Taking a Class like approach, I would have hoped there is a mechanism where a cluster could be "type casted" to and tell labview to accept a generic cluster (if such a beast exists).
For the other post about references, this is so far the best solution, except that it adds extra complexity to the application (need to get the reference, then dereference). I still need to try it if it will actually work.
Thanks,
Jason.
11-14-2008 10:40 AM
Hello Ben,
Article is pretty good. From what I understand you need to supply a reference to the control to the SubVI, is it possible somehow to wire a generic cluster directly to the subVI and have it calculate the reference? It saves one step in the main application.
I thought about a variant, but getting the generic reference and typecasting it to a cluster results in a type mismatch. So I'd have to use "variant to data" and I'm back to the original problem.
Thanks for your help,
Jason.11-14-2008 10:47 AM
Hello Jason,
maybe you want to have a look at MGIs 'Write Anything' and 'Read Anything' VIs (http://www.mooregoodideas.com/File/index.html).
They use a variant data type to save data in configuration files.
Hope this helps.
Uli
11-14-2008 11:13 AM
I built a probe for any type of Variant that parses anything out returns it in a tree structure.
See the LAVA Code Repository for inspiration
Ton
06-23-2016 02:04 AM
You can find Read/Write Anything now here: http://www.mooregoodideas.com/category/technical-articles/readwrite-anything/