LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

1D array to Cluster of Clusters

Solved!
Go to solution

I'm looking to turn a long array of u8 received from a 3rd party application into a cluster of status elements (cluster of clusters)

 

I don't like how I'm repeating the split 1d array and array to cluster conversion. Although this works for 3 elements, I wouldn't want to do it for 20. Can I set up the conversion in a more extensible way?  

 

JScherer_0-1585659110414.png

 

0 Kudos
Message 1 of 9
(3,734 Views)

Hi JScherer,

 

the conversion can be made much simpler:

 

When you want to repeat a process step you should use a loop!

So place the conversion into a (while) loop and repeat until the remaining array is empty (or smaller then needs to be). You can also use a FOR loop when you calculate the number of conversions from array size…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(3,721 Views)

Well, the problem is that you can't really use a loop efficiently, because clusters are fixed in size and you cannot e.g. have an array  where each element is a cluster with a different number of elements.

 

Maybe you want to re-think your data structures. For example you could have an output array where each element is a cluster of an array. Now each element can be of different size.

 

altenbach_0-1585667951360.png

 

0 Kudos
Message 3 of 9
(3,691 Views)
Solution
Accepted by topic author JScherer

To steal from altenbach, you can do this with post-card sized code.  You just need the Byte Array To String followed by the Unflatten From String.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 9
(3,675 Views)
Solution
Accepted by topic author JScherer

@crossrulz wrote:

To steal from altenbach, you can do this with post-card sized code. 


Gerd already mentioned something very similar, but it was hard to notice because he also left the original code next to it. 😉

 

And, no you were not stealing anything because my solution would have looked as follows:

 

altenbach_0-1585676144415.png

 

Message 5 of 9
(3,672 Views)

Hi,

 


@altenbach wrote:

@crossrulz wrote:

To steal from altenbach, you can do this with post-card sized code. 


Gerd already mentioned something very similar, but it was hard to notice because he also left the original code next to it. 😉


Yes, by decision to allow comparison of original convoluted approach with that simple TypeCast replacement…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 6 of 9
(3,656 Views)

@GerdW wrote:
Yes, by decision to allow comparison of original convoluted approach with that simple TypeCast replacement…

I am just not a fan of the Type Cast function.  I have been burned too many times by Little Endian formats.  So I always go for the Unflatten From String to guard against that (simply add a constant to state the Endianness instead of adding who knows how much code to swap bytes and words, etc).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 9
(3,649 Views)

Yes, I would probably wire the size input to a case structure and only cast if the size=9. 😄

 

(Also note that unflatten also has an output for the remaining string that could be checked for length.)

0 Kudos
Message 8 of 9
(3,647 Views)

@altenbach wrote:

(Also note that unflatten also has an output for the remaining string that could be checked for length.)


I have also used it to "chain" conversions.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 9 of 9
(3,601 Views)