02-27-2012 12:17 PM
In my code the input is an fixed length of U8 array reflecting data in memory, I need to convert it to a predefined data type. For example, the first 2 U8 elements in the arrary need to comvert to an U16 data, next 4 U8 elements to U32 data. I am just wondering if there is any easy way to do that kind of conversion.
Solved! Go to Solution.
02-27-2012 12:23 PM
It can be done like this:
These functions are found here:
02-27-2012 12:29 PM
In the first case use the Join Numbers function to join the bytes. In the second case, use the Join Numbers function three times: twice to join the consecutive bytes and once more to join the words into a single long word.
Mike...
02-27-2012 12:30 PM
Create a cluster constant where the elements are of the proper type and in the right order, Then simpy typecast your array to that cluster
02-27-2012 12:31 PM - edited 02-27-2012 12:31 PM
Aeastet - that's not what the poster wants at all.
Scott - try a typecast to a cluster as shown here (as usual, the snippet tool messed up the cluster, but if you drag it to a block diagram it will work):
02-27-2012 12:41 PM
Type Cast Man and his trusty sidekick Unflatten From String are itching for some action.
Use Unflatten from string if you have problems with endianness.
02-27-2012 12:41 PM
I guess I didn't make myself clear. I tried using Type cast to receved an U8 array and created a cluster ( contains U16 and U32 data) to define my needed data type. The output looks good, but U16 and U32 are byte-swapped. Sounds like to solve this is to manually swap U8 array before Type cast. But I wonder if there is any LabView function I can use to avoid manual swap by rewriing U8 array.
02-27-2012 12:44 PM
If you use the unflatten route of Darin's second example, you can specify the byte order.
02-27-2012 12:45 PM
Unflatten from string is easy, but you can also wire an entire cluster to "Swap Bytes" and "Swap Words" and you'll get that same cluster with reversed endianness (Swap Words will ignore U16 values).
02-27-2012 12:55 PM
It works!!! thank you guys so much! I use Unflatten from string with "native, jost order" to solve the byte swap problem.
Have a great day!!