06-27-2012 03:17 AM
I was wondering how you create a VI that can take any cluster or data item as a control? For example the "Write to Binary File", "Data" input takes any data type. How do you do this in your own VIs?
Thanks.
Solved! Go to Solution.
06-27-2012 03:42 AM
Christopher,
the mentioned VIs are polymorphic.
You might be interested in this white paper.
Please note the following passage:
Do not use variants in place of polymorphic VIs in situations where data types can be determined at design time. Polymorphic VIs yield cleaner, faster code and require less runtime error checking.
So your question can be 'solved' by one of the following options:
- Polymorphic VIs
- Variant
- Flatten/unflatten to/from string
- ...
hope this helps,
Norbert
06-27-2012 03:49 AM
For that purpose you can have Variant as a control that can take any data type. But in many case it will not give the expected result so you can create a polymorphic vi with the predefined data type.
06-27-2012 03:59 AM
The problem I was thinking about was:
I have a GUI front end with a number of panels and each panel contains a number of different controls. As part of each "panel" there is a save and load button. When these are selected, the values of the controls on that panel are saved to disc or loaded from disc (via a single generic "Save Data" VI and a single generic "Load Data" VI ). In this case the Generic "Save Data" and "Load Data" VI's would need to be designed with no concept of the input data control or output indicator until it was used. The VI's would also contain a marker to associate a file with a panel so that the data from an incorrectly selected file would not trash a panel.
I'll have a look into Polymophic and Varient VI's...
06-27-2012 04:02 AM
For this we generally create a cluster and bundle all the control values into that cluster and write it as a single element to a data log, binary or xml file and while starting retrive the data by reading the file and load it to the controls.
06-27-2012 04:08 AM
Christopher,
this sounds more like using VI server within your "save" and "load" functions.
You would simply pass the reference to the cluster to those VIs. Within the VIs, you would do something like this:
Of course, this is only a scetch of the functionality, without handling files and actual access to data.
Norbert
06-27-2012 04:13 AM
@P Anand wrote:
For this we generally create a cluster and bundle all the control values into that cluster and write it as a single element to a data log, binary or xml file and while starting retrive the data by reading the file and load it to the controls.
I might not want to save all the control values. Say I had 8 panels (each with their own Save button) with different controls on it. I might want to only save the contents of panels 2 and 6 for example but not the others...
06-27-2012 04:18 AM
@Norbert_B wrote:
Christopher,
this sounds more like using VI server within your "save" and "load" functions.
You would simply pass the reference to the cluster to those VIs. Within the VIs, you would do something like this:
Of course, this is only a scetch of the functionality, without handling files and actual access to data.
Norbert
So the "generic" Save VI could have a Cluster Refnum input which would accept any cluster of controls. Sound good. As I say this was just a curiosity about passing any types to a VI. The example was what I thought off the top of my head (based on the “Write Binary File” VI).
06-27-2012 04:21 AM
Christopher,
i think, you now got some good points to start with an think about the requirements vs. implementation. Now it is your task to collect some experience by creating small examples/"proof of concepts" in order to define the solution you are going to use.
Have fun with playing around 😉
Norbert
06-27-2012 07:42 AM
Since this thread has drifted from its original and is now entertaining the option of working via control references you may want to review this Nugget I wrote on how to exploit control references.
It starts out with the simple ideas, moves through some more advanced ideas and eventually ties it all together with tricks to handle arrays of cluster os arrays ... using a recursive approach.
So...
Look that thread over and stop reading when the topic get hairy.
have fun,
Ben