07-16-2012 09:19 PM
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.
Solved! Go to Solution.
07-16-2012 09:40 PM
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:
First of all, ask yourself if you really should be doing this, if the answer is yes then I say Type Cast.
07-16-2012 10:02 PM
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!