NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
apapr
Posts: 8
0 Kudos
Accepted Solution

Type cast array to cluster

Is there any real difference between the 'array to cluster' function and simply type casting to a cluster?  The image below shows a simple example.  Aside from providing the names of each cluster element, the type cast function automatically sets the cluster size, which is a nice feature when working with a typedef.  I am really wondering whether there is any downside to type casting when the array and cluster elements are the same data type.

 

Thanks in advance.

Array to Cluster.png

Trusted Enthusiast
Darin.K
Posts: 3,340

Re: Type cast array to cluster

Type Cast man knows where I live, so my opinion is biased.  When I have to make such a conversion, which is practically never, but not equal to never, then I go with the Type Cast.  You hit the biggest points, meaningful labels and the ease of going from six to seven to eleven elements with the Type Def.  When I do this conversion it is typically because I need to do some property magic which arrays do not allow (all elements must share properties except value).  Creating a control from the Array to Cluster function is let's say a Clusterflop, from the Type Cast, exactly what I am looking for.  Besides, that Array to Cluster function obfuscates code, is always left at 9 elements, and otherwise needs to go away, or at least do this:

 

http://forums.ni.com/t5/LabVIEW-Idea-Exchange/Remove-Default-Behavior-from-Array-To-Cluster/idi-p/17...

 

First of all, ask yourself if you really should be doing this, if the answer is yes then I say Type Cast.

Member
apapr
Posts: 8
0 Kudos

Re: Type cast array to cluster

Hey Darin, thanks for the quick reply.  I actually have a pretty big typedef'd cluster which serves as the input to a statechart, and I need to replace certain cluster elements to allow a user to change timer values, etc. from the HMI.  The easiest way that I found to deal with this was to use arrays for the communication and then convert to a cluster in the RT loop with the statechart.  I'm not sure if this is the best approach, but it works very well.  I will follow your advice and stick with the type cast.  This way I won't have to manually edit the cluster size whenever I change the typedef.

 

By the way, I agree with your comments about the array to cluster function and gave your idea kudos a while back.  Thanks again!

By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page