07-05-2011 07:51 AM
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.
Solved! Go to Solution.
07-05-2011 11:32 AM
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.
07-05-2011 12:47 PM
Hi,
The following document is very important for understanding: How LabVIEW stores data in Memory
Andrey.
07-06-2011 05:06 AM
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.
07-06-2011 08:49 AM
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.
07-07-2011 08:16 AM
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.
07-07-2011 12:22 PM
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.
07-08-2011 06:12 AM
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.
07-08-2011 08:27 AM
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.
07-08-2011 12:08 PM
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?