LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way is cast (point to) different types of cluster structures?

I am building an application that is capable of using different A to D boards each from different manufactures. Only one A to d board is used at a time, where the selection of the which A to D board is determined by a case statement. I am using a state machine to control initialization processes and shut down procedures. Other processes are occurring not just the A to D. The problem I have is each A to D driver requires its own types of parameters and feedback variables, therefore each A to D must have its own cluster type passed from state to state. Since only one A to D board type is ultimately going to be used but the program will have the ability to support others. H
aving empty clusters not to be processed in state machine seems like wasted resources, let alone a lot of work.
Does anyone know of a technique such that I could point(er) to the correct cluster type determined by a case state? Or a methodology to get around this problem?
0 Kudos
Message 1 of 10
(3,723 Views)
There are two way to approach this problem. The one that I have used in the past is to use the flatten to string and unflatten from string functions. You must be careful with the unflatten function. If you give it an invalid string to unflatten, it may crash your application. The new way would be to use variants and variant attributes. the variant can contain any cluster type and the variant attribute can tell you which version is currently in the variant.
Stu
Message 2 of 10
(3,723 Views)
It works but with a bit of design better solutions are possible.
greetings from the Netherlands
0 Kudos
Message 4 of 10
(3,723 Views)
Thanks Stu this was the technique i was looking for. Quite powerful. Attached is a vi for others to look at. Thanks for your help
0 Kudos
Message 6 of 10
(3,723 Views)
Variant+attribute(s) is very elegant. I had one problem when I tried expand the usage. It's fine to pass the variant with attributes either internal to a VI or through a terminal. But when I tried to retrieve the combination using Get Control Value then reconstruct it, the attached attributes got lost. The two subvis have slightly different clusters. I'm trying to work out a general solution where I eventually don't have to remember which vi has what data structure. Any ideas?
Zuolan Wang
0 Kudos
Message 7 of 10
(3,723 Views)
Zuolan, I like your thinking... I can foresee myself using this technique a lot. In your example, you have an get control value going to a flattened string to variant. After the flattened string to variant, try putting a Variant to data with a variant constant as the type. The cluster attributes get reattached and you can parse the version number. It works!
0 Kudos
Message 8 of 10
(3,723 Views)
Also, upon reinspection of the vi. There can be a timing issue with the getcontrol value and the running of the vis in vi server, where the control value gets read before the vi has a chance to open and run. I put a sequence between the run vi and getcontrolvalue. This seems to fix the problem.
0 Kudos
Message 9 of 10
(3,723 Views)
Hpopenoe,
Glad you appreciated the idea (Which was in Stu's original answer too) and thanks for spotting the gap and the racing condition. It's working for me now. This is something I have been wanting to do for a while. As you said, I will be using it a lot. I want to setup a private site collecting these recipes. Send me a email on zwang@engr.arizona.edu if you are interested.
0 Kudos
Message 10 of 10
(3,723 Views)
An better way than using variant clusters or flatte/unflatten from string is to separate the way an interface should be handled from the function this interface has. e.g. You could have several statemachines that keep their own information and have a common interface to the user program.
INIT read the settings from somewhere (inifile for that interface)
DOIT does the thing needed (read data)
EXIT updates the settings and makes way for the other interfaces.
It is a bit of work to keep the information in the userprogram as little as possible but makes it also easy to extend your software with yet another interface.
The only info needed from "above" seems to me
the channels, the range and speed in which they need to be updated. All other info seems device dependent !
T
he most important feature you add, when thinking about your problem is clarity in programming while variant clusters and flatten/unflatten from string adds complexity.
In my opinion these conversion functions are the last option, when every other possibility is tried.
greetings from the Netherlands
0 Kudos
Message 3 of 10
(3,723 Views)
May be I'm wrong understanding, but why not to try reentrant vi feature for doing it and variant shift register and functional global as a storage of variant? (LV 6 only).
If I'm not clear with an idea, let me know.
Sergey
0 Kudos
Message 5 of 10
(3,723 Views)