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.
已解决! 转到解答。
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...
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
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):
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.
If you use the unflatten route of Darin's second example, you can specify the byte order.
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).
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!!