LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing cluster input as argument to dll

Solved!
Go to solution

Array Data pointer is simple the pointer inside the handle that LabVIEW passes:

 

double *arrayDataPointer;

 

This is principially the same as a C array Pointer.

 

Handle data pointer is very different:

 

#include "lv_prolog.h"
typedef struct
{
    int32_t dimSize;
    double elm[1];
} ArrayRec, *ArrayPtr, **ArrayHdl;
#include "lv_epilog.h"

ArrayHdl *ArrayHandlePointer;

 

 This is a pointer to the LabVIEW array handle!

 

Basically when you configure the parameter in a Call Library Node to pass the Array Data Pointer, what LabVIEW does is to pass the elm pointer in the Handle structure. It always uses handles for any variable sized data, but since you told it that your DLL only wants a data pointer, it passes the according element of its handle.

 

In the case of a LabVIEW DLL, everything works inside out and in fact if you pass an array data pointer into the DLL, which also always requires an according size integer as extra parameter, the DLL constructs a new handle internally and copies all the data from the passed in array data pointer into that handle before executing the according VI.

 

You could avoid that by allocating a handle in your calling process through the extra AllocateDoubleArray() or similar function that your DLL exports and then pass this handle to the DLL function, but to get that right will be an extra complication. You also will afterwards have to call the according DeAllocateDoubleArray() function to properly dispose of the handle or you are otherwise creating a memory leak.

Rolf Kalbermatter
My Blog
Message 21 of 24
(141 Views)

@Abhi_kool wrote:

FYI, the pack thing did the trick! Also something to keep in mind is that the output should be "Array data pointer", if I give it as "handle pointer" then the value is not put to output_array. I have no idea why this is so, but I assume it has something to do with memory management once again. But really thank you very much you two. I will start to look into the resources and links you have shared! 


Just one more thing in additional to the message from Rolf — there are good examples shipped together with LabVIEW located in "<LabVIEW >\examples\Connectivity\Libraries and Executables" Folder.

Lot of small C Code snippets with different data structures as well as according LabVIEW code shows how to call these. Take a look into "\Libraries and Executables\Source C Files\ARRAY1DHandle.c" (more simple) and "\Libraries and Executables\Source C Files\CLUSTERComplex.c" (slightly more advanced) — this will explain lot of things and good for understanding.

0 Kudos
Message 22 of 24
(123 Views)

This might be a dumb question. Let's say I have vi written for some RIO target, if I were to copy the VI and add it under "My computer" then, I compile the dll, will the python script still work?

 

I got a similar VI file (the ones we have been looking at in this example) and he has written it for some RIO target. I then added that VI file to my project and compiled it as dll. The header file looked very similar, but the python script wouldn't run, it threw an error.

 

The only difference was that in his code he fixed the array size (in the cluster). Despite fixing the array size the header looks almost the same as I had gotten, with the array being represented as a struct and the array element inside the struct being dynamically initialized. Somehow that throws off the python script from executing it.

0 Kudos
Message 23 of 24
(91 Views)

Sorry I can’t quite process your description. You mix and match RIO versus Windows, DLL and Python. That are 3 very different things and in each of those areas there could be umpteen reason why you can’t just do what you try to do.

Rolf Kalbermatter
My Blog
Message 24 of 24
(86 Views)