From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing an Array of Clusters from LabVIEW to a DLL.

Solved!
Go to solution

I have to pass array of structures to function in DLL. Attached is the VI i have created.

I am using "call library function node" to send parameters to DLL function.

In configuration of "call library function node" for array of clusters i have selected "Adapt to type" for type,

"Pointers to handles" for Data format.

 

With the above configartion its not working.

 

When i searched in web i found this below link

http://digital.ni.com/public.nsf/allkb/5FE3C48E8E1C3D018625722900681AF6?OpenDocument

 

As per above link i should get the option to choose "Array Data Pointer" from the Data format pulldown menu.

But i am not getting that option in type "Adapt to type" hence i have selected "Pointers to handles".

I am using labview 7.1Version.

 

In attched example parameter pMsg is a array of clusters.

 

 

0 Kudos
Message 1 of 43
(6,196 Views)

Do you have documentation, and the function prototype from a .h file, for the function you are trying to call?

You should not pass the data as a pointer to a handle.  Instead, try typecasting your cluster array to an array of U8 and passing that to the DLL as an array data pointer.

0 Kudos
Message 2 of 43
(6,184 Views)

Hi,

 

The following document is very important for understanding: How LabVIEW stores data in Memory

 

Andrey.

0 Kudos
Message 3 of 43
(6,177 Views)

Function prototype from .h file.

 

PassThruWriteMsgs(unsigned long ulChannelID,    PASSTHRU_MSG   *pMsg,    unsigned long *pulNumMsgs,  

 unsigned long ulTimeout);

 

typedef struct{

unsigned long ulProtocolID;

unsigned long ulRxStatus;

unsigned long ulTxFlags;

unsigned long ulTimeStamp;

unsigned long ulDataSize;

unsigned long ulExtraDataIndex;

unsigned char ucData[PASSTHRU_MSG_DATA_SIZE];

}PASSTHRU_MSG; 

 

pMsg is a array of clusters we need to pass to that function.

 

How to type cast array of cluster to array of U8 can anybody give an example attachment.

 

I am using labview 7.1 version.

0 Kudos
Message 4 of 43
(6,158 Views)

Use the "Type Cast" function.  I don't remember which palette contains it in LabVIEW 7.1, search the help or palettes for it.  Wire your cluster as the left input.  Wire an empty array of U8 as the type input (from the top).  The output will be an array of U8 containing identical data to your cluster.

0 Kudos
Message 5 of 43
(6,148 Views)

I did as explained here but still not working.

here i have attched vi.

 

I am using labview 7.1 version.

Function prototype as explained below

 

PassThruWriteMsgs(unsigned long ulChannelID,    PASSTHRU_MSG   *pMsg,    unsigned long *pulNumMsgs,  

 unsigned long ulTimeout);

 

typedef struct{

unsigned long ulProtocolID;

unsigned long ulRxStatus;

unsigned long ulTxFlags;

unsigned long ulTimeStamp;

unsigned long ulDataSize;

unsigned long ulExtraDataIndex;

unsigned char ucData[PASSTHRU_MSG_DATA_SIZE];

}PASSTHRU_MSG; 

 

pMsg is a array of clusters we need to pass to that function. 

 

When we pass single message it will work ,if we pass more than one message in array than exception will come.

 

As per below link i should have the option to choose "Array data pointer" data type in the "Adapt to type" type.

But i dont have it.Is it avalilable in higher version of labview?since i am using labview 7.1.

http://digital.ni.com/public.nsf/allkb/5FE3C48E8E1C3D018625722900681AF6?OpenDocument

 

If i pass first element from the array its not working.

Basically first element of the array gives the base address.

 

Please help me to sort out this problem.

 

 

 

0 Kudos
Message 6 of 43
(6,126 Views)

Please stop repeating yourself.  There is no need to mention in every message that you are using 7.1, and certainly no need to do so twice in one message.  There is also no need to repeat information you have already provided such as the function prototype.

 

The "Adapt to Type" option is available in later versions of LabVIEW; I don't know when it was introduced.  However, there should be no problem passing it as array data since you are just trying to pass the address of the data to the DLL.  How do you have the pMsg parameter configured in the Call Library Function Node?  When I open your VI in LabVIEW 9, it shows up as "Adapt to Type" with the Data Format set to Handles by Value.  It should be Array Data Pointer.  I don't know what the options are for 7.1.

 

If it is working for one message but not for multiple messages, then you probably need to add padding at the end of the cluster to align the next element of the array the way the DLL expects it.  Currently your cluster is 30 bytes.  Most likely it needs to be a multiple of 8 bytes.  Try adding a 16-bit integer at the end of the cluster to bring the entire cluster to 32 bytes and see if that works.

0 Kudos
Message 7 of 43
(6,117 Views)

pMsg is configuread as type "Adapt to type" and "Pointers to handles" for data format.

 

In last posts attached vi has configured as "Adapt to Type" with the Data Format set to Handles by Value.

 

By setting data format to "Pointers to handles" or  "Handles by Value" behaviour is same.

 

In labview 7.1 we have 2 options for "Adapt to Type" they are "Handles by Value" and "Pointers to handles"

There is no "Array Data Pointer".

 

Attached one works if we send single message its failed to send if we pass multiple message.

 

Have a look into vi it has been changed from the last post.From the array of clusters I am sending first single cluster.

same as sending base address of an array.

 

0 Kudos
Message 8 of 43
(6,107 Views)

You would probably have this working by now if you did as I suggested and passed the array of U8 as an ARRAY, not adapt to type.

 

Sending the first element of the array is NOT the same as sending the base address of the array in LabVIEW, since LabVIEW may copy the single array element to another location before passing it to the DLL function.

0 Kudos
Message 9 of 43
(6,101 Views)

Also, you may need to insert "swap words" followed by "swap bytes" after bundling the cluster, before building it into the array, so as to get the byte ordering from what LabVIEW uses to what most Windows DLLs expect.

 

Did you try my earlier suggestion that you add two bytes of padding to the cluster definition?

0 Kudos
Message 10 of 43
(6,096 Views)