LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

VI of the Day (9/23/2009) - Unflatten From String

A simple yet deceptively powerful function for today "Unflatten From String".  I started using the Flatten/Unflatten duo to programmatically save and load the state of the controls in a VI.  I would bundle everything into a cluster, flatten and save to file.  Loading was simply the reverse, load, unflatten and populate the control values (via locals).  In the meantime, new functions have been added to flatten to/unflatten from XML.  I would probably choose that route now to increase human readability of the configuration file.  The second use, which is not outdated, is the conversion of binary data to numbers.  Many of us do this quite often, read a binary file from known or unknown origin and convert to a number or array of numbers.  You may instinctively think of Type Cast, only to discover that you get garbage out.  After exploring all the possible number formats you think big-endian/ little-endian and start adding code like this example I found in a VI that ships with LV

 

UnflattenHard-fixed.png 

 

Reversing the string and pulling off chunks is one way to do this, or with Unflatten From String you could do this

 

Unflatten-fixed.png

 

Nice and tidy. 

 

VIOTD groundrules here

Message 1 of 1
(2,836 Views)