01-03-2016 11:50 AM
What is the easiest & most efficient way to take a cluster of U16 numbers and dump
these into an array so that I can perform calculations on each of the elements of the array?
Thanks
01-03-2016 12:18 PM
Cheers
--------, Unofficial Forum Rules and Guidelines ,--------
'--- >The shortest distance between two nodes is a straight wire> ---'
01-03-2016 12:41 PM
Well, there is the simple "Cluster To Array" function. Though, I would also question the use of the cluster in the first place based on how you want to use the data in it.
01-03-2016 01:05 PM
What do you mean by "Perform Calculations"? If you are going to convert a Cluster to an Array, then all of the elements have to be the same type, say, for the sake of this discussion, Dbl. Do you want to add a constant to the Array? You can add a constant to a Cluster. Do you want to add another array of the same "type" to your array? You can add another Cluster of the same Type (use a TypeDef to insure this) to your Cluster.
It is a little more difficult, but you can even do things based on the position of the Elements in your Cluster and the number of Elements therein. For example, if you want to use a numeric method to set to 0 the third element in a Cluster of 5 elements, create a Cluster "Constant" all of whose elements except the third is 1, with the third being 0. Multiplying your Cluster by this "Zero-third-element" Cluster will zero the third element.
Arrays need not apply in these cases. What operation(s) did you have in mind?
Bob Schor
01-03-2016 02:02 PM
You can perform most operations on the cluster directly, no need to convert to an array. You need to be more specific on what you actually want to do with the data from the cluster.
01-04-2016 11:26 AM
I am sending commands to a device and reading TCP data.
Without getting into a lot of details, that data is 128 channels that is hexidecimal, little endian two compliment,.
and I want to display all 128 channels of data on the front panel (16 channels per indicator).
In my attached VI I am showng the raw data in these indicators but really want to show the calculated values.
I had set the clusters for analog data up for U16 data types but converted these over to I16 data types.
The calculations that I want to perform on each channel of data is to convert to 2's compliment and then multiple
that number by 3.3569335975 (adc bit value) and then subtract a correction factor of 1000.
I know that my VI is over complicated and can be done much simpler but with the time crunch that I have, there may not be enough time to rewrite the whole thing.
Not sure if I need the CH1 - Ch128 in the Analog data cluster to be data types I16 in order to do 2's compliment (signed data vaues)
but when I converted these over from U16, the following errors occurred but I am not sure why:
01-04-2016 11:39 AM
All of the data in your cluster must be of the same type.
But looking at your code, I don't see a reason for the cluster. You could just have the TCP Read read X*2 bytes (X being the number of elements in your array) and then use Unflatten From String to straight to your array of I16.
01-04-2016 11:39 AM
Why are thre so many inner type defs?
01-04-2016 11:43 AM - edited 01-04-2016 11:44 AM
Since all your inner elements are of the same basic type, you could possibly just typecast the cluster to an I16 array. See if that works.
01-04-2016 01:22 PM
01-04-2016 11:39 AM
Why are thre so many inner type defs?
Probably because I don't know what I am doing...