LabView_Fool Posted January 10, 2007 Report Share Posted January 10, 2007 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 Quote Link to comment
Darren Posted January 10, 2007 Report Share Posted January 10, 2007 Are you looking for the Bundle By Name function? That seems to be what you could use to replace all the other code in your VI. -D Quote Link to comment
LabView_Fool Posted January 10, 2007 Author Report Share Posted January 10, 2007 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. Quote Link to comment
JDave Posted January 10, 2007 Report Share Posted January 10, 2007 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 Quote Link to comment
LabView_Fool Posted January 10, 2007 Author Report Share Posted January 10, 2007 In C, it would look something like this: char dataArray[1024]; // serial data buffer clusterType myCluster; // some structure memcpy(&myCluster, dataArray, sizeof(clusterType)); // copy data into cluster Quote Link to comment
Darren Posted January 10, 2007 Report Share Posted January 10, 2007 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 Quote Link to comment
LabView_Fool Posted January 10, 2007 Author Report Share Posted January 10, 2007 Another problem with that solution is mapping/typecasting the 2D arrays. For some reason, Typecast only works on single dimensional data. Quote Link to comment
JDave Posted January 10, 2007 Report Share Posted January 10, 2007 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. Quote Link to comment
LabView_Fool Posted January 10, 2007 Author Report Share Posted January 10, 2007 Thanks. I wasn't aware of "Reshape Array". Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.