LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I easily convert a complex C Strcture to a LabVIEW Cluster?

I am compiling a Matlab project into a dll for distribution without the need for the Matlab engine. Matleb creates a C data type of mxArray that is not an easy type def to duplicate. I was wondering if there was a way to create a LV type def from a C type def. Or if anyone has experience with using compiled Matlab functions in LV.
0 Kudos
Message 1 of 5
(2,779 Views)
I wrote a test which gets the system memory status on a Windows NT machine. To do this I call the function GlobalMemoryStatus in the DLL "c:\winnt\system32\kernel32.dll".

This function returns a structure. I created the same structure in a cluster. Be careful with the order of your elements in the cluster. It must match the order of your C data type definition.

In the configuration of your "Call Library Function Node", choose "Adapt to Type" as the return parameter type.

See attachment.

I hope it will help you.
0 Kudos
Message 2 of 5
(2,779 Views)
Thanks for your help. My structure is a bit more complex and I am not sure how to inplement some of the C features into a LV cluster. Here is the C typedef code below (I should have included this to begin with:

struct mxArray_tag {
char name[mxMAXNAM];
int reserved1[2];
void *reserved2;
int number_of_dims;
int reserved3[4];
union {
struct {
void *pdata;
void *pimag_data;
void *reserved4;
int reserved5[3];
} number_array;
} data;
};
0 Kudos
Message 3 of 5
(2,779 Views)
The problem I can see in your structure is the union part. As far as I know, it is not possible to declare a union in LabVIEW.

Have a nice week end.
0 Kudos
Message 4 of 5
(2,779 Views)
My suggestion would be to write a wrapper DLL that would 'flatten/unflatten' your structure. In other words, LabVIEW would call a wrapper DLL and pass it simple data types, i.e. scalars, booleans, etc. This wrapper DLL would then put the data into the correct C Struct format and then call your original DLL.

Chris_Mitchell
Product Development Engineer
Certified LabVIEW Architect

0 Kudos
Message 5 of 5
(2,779 Views)