Jump to content

Byte Array to Cluster


Recommended Posts

Does anyone know how to easily map an array of bytes to a cluster? I'm new to LabVIEW and I'm coming from a C/C++ programming background. My first attempt at solving this problem was by using the Typecast component, which didn't work and gave me an error message complaining about polymorphic data. I contacted NI support, but they tell me I'll need to parse the individual members, bundle, and then pipe into the cluster :headbang:

See attached subVI.

Download File:post-6545-1168445184.vi

Link to post
Share on other sites

Thanks, Darren.

No it's not the Bundle by Name that I'm looking for -- the array of bytes my VI receives is coming over the serial port and it's received as a single dimensional array of bytes. The array of bytes that I receive over the serial port are the members of my cluster and I'm looking for a simple solution for mapping the data into my cluster.

Link to post
Share on other sites
Thanks, Darren.

No it's not the Bundle by Name that I'm looking for -- the array of bytes my VI receives is coming over the serial port and it's received as a single dimensional array of bytes. The array of bytes that I receive over the serial port are the members of my cluster and I'm looking for a simple solution for mapping the data into my cluster.

Looking at the code, I am wondering how you would know how to parse out the different components at all. Some are arrays, so how do you parse it at all? If each piece was of the same size then you might find some way of doing what you want. But my intuition is that you will have to parse it out and bundle it individually.

David

Link to post
Share on other sites

Ah, ok. In that case, I don't know of anything you can do other than to extract each item out of the serial string and cast it to the appropriate datatype, then bundle all of those individual items into a cluster. I don't think you would be able to use Unflatten from String directly because the string data doesn't directly correspond with a cluster datatype containing all those elements.

-D

Link to post
Share on other sites
Another problem with that solution is mapping/typecasting the 2D arrays. For some reason, Typecast only works on single dimensional data.

You can't convert a 1 D array directly to a 2D array because you need to specify the dimensions. Look at the "Reshape Array" function in the Array palette. First convert your 1D array slice to a 2D array of the proper dimension, then you can bundle it into the cluster.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.