LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how can i convert string data from UDP Read to Cluster of U16 U8 U16 and U16[] using unflatten from string

Highlighted

@crossrulz wrote:

So we are back to these questions:

1. Where did this data come from?

2. What is the EXACT protocol for the data?


You've answered question 1.  But you have not answered question 2.

 

Show the C code that forms the data to be sent.

0 Kudos
Message 11 of 12
(85 Views)
Highlighted

C doesn not know a Flatten or Unflatten like LabVIEW. The closest you have in C is the typecast which sort of works like the Typecast in LabVIEW but still with differences.

 

From the llittle information you have provided in piecemeal so far, this is what most likely does what you want.

 

Unflatten.png

And to make a point about how convinient it is to attach only pictures instead of a VI, I attached the solution as picture too.

 

One point to watch out!! I set the endianess to Little Endian because that is what most CPUs in use nowaday use by default. Depending on what CPU your device has this might have to be set to Big Endian. At least the Array data sort of looks like it might be indeed in Big Engian, but without knowing what it is we can't tell. If you change the endianes to Big Endian you have to also change the selector value in the case structure of course.

 

For the rest the main point is to split the Unflatten into two operations. LabVIEW does not allow embedded arrays and strings in a cluster to be unflattened without the size prepended to it. The boolean to disable that only works for the first datatype in the stream and only if it is a string or an array, otherwise it does nothing. And don't say it is a bug, it's not! There is no way to reliably unflatten data with embedded arrays if there is no size information embedded too. In your case it can be made to work since the array is at the end of the data but that is not usually the norm and to make the Unflatten code do that kind of conditional execution is worse than not to do it at all.

 

Also note that because of what I just explained the resulting flattened data is 2 bytes longer than the original string. That is because the 2 bytes for the header are missing but LabVIEW adds a 4 byte integer for the array size in the stream. If you want to not have that you have to split the Flatten into two operations just as with the Unflatten.

Rolf Kalbermatter
Averna BV
Message 12 of 12
(63 Views)