08-16-2017 09:23 AM
Go and compare your diagram with that from Nathan!
You can not place an array in a cluster and hope that LabVIEW Unflatten will treat that as an embedded fixed size array. Instead LabVIEW expects in the data stream a 32 bit integer that contains the number of array elements in that case. Make a cluster of 3 floating point values instead of the array and you will be fine!!
08-16-2017 09:48 AM
Ah, I did read that, but I forgot when I switched back to my code. I have made the change and everything works. However, this leads me to a new question. What if instead of 3 or 20 values, I have 1000? How does one make such a cluster (typdef)?
08-16-2017 09:54 AM - edited 08-16-2017 09:55 AM
@tysonl wrote:
What if instead of 3 or 20 values, I have 1000? How does one make such a cluster (typdef)?
Not really! There are tricks but they are cumbersome. Instead you process the byte buffer in multiple Unflatten operations.
First the part that is simple to represent as a cluster/struct. Then you get the bytes from the string at the correct offset and with the correct length and then pass it to Unflatten with an array constant as data type but set the input "data includes array size or string size (T)" set to false.This tells the function to simply take as many elements from the binary string buffer as possible, without trying to read first an int32 that indicates the number of array elements.
08-16-2017 10:34 AM
@tysonl wrote:
What if instead of 3 or 20 values, I have 1000? How does one make such a cluster (typdef)?
That is why I said what I did here: https://forums.ni.com/t5/LabVIEW/How-to-efficiently-read-network-data-into-struct-and-correct/m-p/36...
08-16-2017 10:39 AM - edited 08-16-2017 10:41 AM
I have tried your suggestion rolfk and it works. Some code is attached below. The next issue is handing data that contains a mix of values and arrays. I could configure my device to transmit the array sizes before the arrays. That way I could receive the size, flatten it, append it onto the front of the array, and then unflatten the array with the appended size flag turned on. I will probably experiment with this later.
EDIT: @crossrulz - I did see your post. I used your post and rolfk's post to develop the above.
THANKS!
08-16-2017 10:43 AM - edited 08-16-2017 10:55 AM
@tysonl wrote:
The next issue is handing data that contains a mix of values and arrays. I could configure my device to transmit the array sizes before the arrays. That way I could receive the size, flatten it, append it onto the front of the array, and then unflatten the array with the appended size flag turned on. I will probably experiment with this later.
You mean with data arrays that are not fixed size?
You could then do something like this:
struct { int32_t counter; int32_t status; int32_t length; float array[256]; } DataStruct; DataStruct data; data.counter = something; data.status = something_else; data.length = sizeof(data.array) / sizeof(data.array[0]); // or some other dynamic size of elements in the data array; send(s, &data, offsetof(DataStruct, array) + data.length * sizeof(data.array[0]));
And now you could define a cluster in LabVIEW that contains two int32 in the beginning and then an actual single precision array and wire this directly to a single Unflatten function, since you added the additional int32 length value that LabVIEW expects to find in the data stream when unflattening arrays inside a cluster.