LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Unflatten structs from serial data that includes array?

I'm going to be returning to LabVIEW development after 6 years and have question regarding an issue I remember running into as I'll be facing it again.

I'm going to be working on a project where I'm reading some data off a serial port that represents flattened structures that I'd like to unflatten in LabVIEW.

As I recall, this works fine when the data doesn't include arrays.

But, for example

struct
{
unsigned char a;
unsigned char b;
unsigned int c;
unsigned char string[SOME_FIXED_LENGTH];
unsigned int d;
}

if I create a mirroring cluster type in labview and wire the data and the type into the unflatten, the above won't work because the unflatten node expects a type precedin
g the array in the data.

I'm open to anything that works generically. I supposed I could use CINs which might work out better any ways as I'll have a lot of various data structures that I could auto generate C code for and then compile into CINs.
0 Kudos
Message 1 of 2
(2,381 Views)
> struct
> {
> unsigned char a;
> unsigned char b;
> unsigned int c;
> unsigned char string[SOME_FIXED_LENGTH];
> unsigned int d;
> }
>
> if I create a mirroring cluster type in labview and wire the data and
> the type into the unflatten, the above won't work because the
> unflatten node expects a type preceding the array in the data.
>

The thing I'd do is to make the cluster like above, but make a cluster
instead of an array. LV doesn't really have fixed size arrays, at least
not yet, but clusters are identical to the fixed array above.

It is usually easiest to build this cluster on the diagram with a bundle
with u8s and u32s wired up for the other elements. Make an array
constant or an initialized array of SOME_FIXED_LENGTH e
lements and
convert it to a cluster using the Array to Cluster conversion node. Be
sure to popup on the node and configure it to make the correctly sized
cluster. Wire that into the bundle as well. This now matches your
struct above. Now you can use unflatten or convert.

Greg McKaskle
Message 2 of 2
(2,381 Views)