LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Return array data from running DLL to Labview

Solved!
Go to solution

Hi.

There it is my test code.

I try to pass mixed cluster using PostLVUserEvent();

 

What's wrong?

Thanks a lot

Stas

0 Kudos
Message 21 of 26
(1,824 Views)

staslast wrote:

Hi.

There it is my test code.

I try to pass mixed cluster using PostLVUserEvent();

 

What's wrong?

Thanks a lot

Stas


I didn't check the C code but an Array in LabVIEW has one 32 Bit length per dimension. Your 2D Arrays  at the end of the cluster are really defined as 1D Arrays in the C structure.

 

You  of course need to make sure to match the datatype in your C code with the datatype of your events exactly.

Message Edited by rolfk on 12-10-2009 07:47 PM
Rolf Kalbermatter
My Blog
0 Kudos
Message 22 of 26
(1,814 Views)

WOW!

Thanks so much to everyone who contributed to this thread.

I am trying to do something very similar and this has been a great help to me.

One thing I discovered is that you need to be really careful when creating your event reference in Labview. When you are building your cluster the order the elements are in is crucial! If you get it wrong then Labview will throw errors that look like you are doing something wrong with your DLL.

In this example we defined our struct in C as follows:

typedef struct {

    int32    length;            // Length of array

    int32    data[1];        // Array

} arr1D, *arr1DP, **arr1DH;

So you might think that in your labview cluster, "length" should positioned above "data". This is wrong it's actually the other way round.

I spent ages fiddling with code until I realised this!

I hope this helps someone in future.

🙂

0 Kudos
Message 23 of 26
(1,432 Views)

@T2004 wrote:

WOW!

Thanks so much to everyone who contributed to this thread.

I am trying to do something very similar and this has been a great help to me.

One thing I discovered is that you need to be really careful when creating your event reference in Labview. When you are building your cluster the order the elements are in is crucial! If you get it wrong then Labview will throw errors that look like you are doing something wrong with your DLL.

In this example we defined our struct in C as follows:

typedef struct {

    int32    length;            // Length of array

    int32    data[1];        // Array

} arr1D, *arr1DP, **arr1DH;

So you might think that in your labview cluster, "length" should positioned above "data". This is wrong it's actually the other way round.

I spent ages fiddling with code until I realised this!

I hope this helps someone in future.

🙂


The physical position in a cluster is not important but the logical order position. However the arr1DH declaration is the declaration of a LabVIEW array handle, not a cluster containing an integer and an array. A LabVIEW native array is not just a pointer to the array data but a pointer to a pointer to a structure containing an int32 length followed directly by the array data.

 

So if you want to pass a LabVIEW cluster containing an int32 "start" followed by an Array of int32 then the according C structure that matches this cluster would be:

 

typedef struct {

    int32    length;         // Length of array

    int32    data[1];        // Array

} Arr1D, *Arr1DPtr, **Arr1DHdl;

 

tyepdef struct

{

   int32 start;

   Arr1DHdl array;

} MyEventData, *MyEventDataPrt;

 

If you did what I suspect you did in declaring a structure in LabVIEW containing an int32 and an array but using your original C struct then it is a miracle that you have not seen crashes as your DLL surely will operate on a very different memory layout than what LabVIEW expects to see. If all you wanted to do is to return the length of the array in your C struct then you do not need to declare a cluster in LabVIEW but can directly use an Array as event datatype since the array length is inherently available in the LabVIEW array anyhow.

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 24 of 26
(1,426 Views)

Thanks for the clarification Rolf!

You are quite right. What I should have said was the "logical order" not the physical order. (For those not in the know who may read this in future, one can re-order a cluster in labview by right clicking on it and selecting "Re-order controlls in cluster...". As previously mentioned I found that this was a crucial step!).

To clarify I am sending my structure into Labview using the PostLVUserEvent function from extcode.h in much the same way that nz_mark did way back on page one of this thread. Hence the way I have arranged my structure. 

Thanks again, all the advice in this thread helped me create a working DLL.

0 Kudos
Message 25 of 26
(1,410 Views)

Hi mark,

  I'm also trying to get the I32 array data to LabVIEW from a dll, when an event occurs. Can you please share your implementation?

0 Kudos
Message 26 of 26
(1,007 Views)