取消
显示结果 
搜索替代 
您的意思是: 

Convert an U8 array to a LabView data type

已解决!
转到解答

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. 

0 项奖励
1 条消息(共 11 条)
18,673 次查看

It can be done like this:

 

Example.png

These functions are found here:

 

Example1.png

Tim
GHSP
0 项奖励
2 条消息(共 11 条)
18,668 次查看

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...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 项奖励
3 条消息(共 11 条)
18,660 次查看

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

0 项奖励
4 条消息(共 11 条)
18,657 次查看

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):

typecast U8 array.png

typecast U8 array FP.png

5 条消息(共 11 条)
18,656 次查看
解答
接受人 Scott-D

Type Cast Man and his trusty sidekick Unflatten From String are itching for some action.

 

ConvertNumbers.png

 

Use Unflatten from string if you have problems with endianness. 

6 条消息(共 11 条)
18,650 次查看

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.

0 项奖励
7 条消息(共 11 条)
18,649 次查看

If you use the unflatten route of Darin's second example, you can specify the byte order.

8 条消息(共 11 条)
18,643 次查看

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).

0 项奖励
9 条消息(共 11 条)
18,640 次查看

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!!

0 项奖励
10 条消息(共 11 条)
18,630 次查看