LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Struct form C to labVIEW

Hi,
 
perhaps can anybody help me in finding a solution for the following porobleme:
 
I got a C-function in a *.dll, which is called trough a LabVIEW Application.
The function looks like:
 
DWORD READ(MSG*    MSGbuffer)
 
the pointer is a struct typedef, which looks like:
 
typedef struct
{
 DWORD ID;
 BYTE MSGTYPE;
 BYTE PRIO[8];
}MSG;
 
How is it possible to get the whole struct to my LabVIEW application, I tried to build the struct as a cluster in LV and passed it to the DLL function, but it doesn't work!
What did I wrong???
 
Thanks a lot!
Chris Lambert
0 Kudos
Message 1 of 6
(5,072 Views)
I'm not sure, but I believe what you've described should have worked (that is, if you built your cluster of a U16, a U8 and an array of U8 with 8 elements and used the adapt to type and pointer to value options). I think you'd better post your code or check it against the examples.

___________________
Try to take over the world!
0 Kudos
Message 2 of 6
(5,063 Views)

A DWORD should be equivalent to a I32 in Labview.  A BYTE is a U8.  You do not need a cluster.  Create a Call Library Node and configure the parameters as follows:

For the DWORD, the parameter definitions are:  Type=Numeric, Data Type=Signed 32-bit Integer, Pass=Pointer To Value (if you expect a return value, otherwise set to Value)

For the BYTE:  Type=Numeric, Data Type=Unsigned 8-bit Integer, Pass=Pointer To Value or Value (return or no return)

For the Array of Bytes:  Type=Array, Data Type=Unsigned 8-bit Integer, Dimensions=1, Array Format=Array Data Pointer.

If you get a crash, try changing the calling convention.  There are 2 choices, C and WINAPI.  Even though it is a C DLL, depending on how it is written, the calling convention may have to be WINAPI.  I found this out the hard way, the wrong choice causes a crash.

If you have to use a cluster and your cluster does not contain strings and the byte array size is fixed, you could bundle all the elements into a cluster (be sure to use I32, U8, array of U8), and pass into the Call Library Node and set the parameter for Adapt To Type.

 

- tbob

Inventor of the WORM Global
Message 3 of 6
(5,047 Views)

@tbob wrote:

A DWORD should be equivalent to a I32 in Labview. 


I must have missed the "D".

___________________
Try to take over the world!
0 Kudos
Message 4 of 6
(5,031 Views)
Actually, I may have made a mistake.  DWORD may be a U32, not I32.  I think BYTE, WORD, and DWORD are unsigned, whereas int (I16) and float (I32) are signed.
- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 6
(5,004 Views)
I don't know if it really matters since they both use 4 bytes and it seems like LV is clever enough to have the sign bit at "the right place". At least as far as I've seen, in many windows API functions it makes no difference which integer representation you use (not that that's a reason to be lax about it, of course). I think windows (and that would probably only be windows, not custom DLLs) protects the user by having the right size for the parameter even if it wasn't defined right. I assume it might make a difference in functions where you have variable length structures. In any case, not using DLL calls on a regular basis, I have no real knowledge about how this works.

___________________
Try to take over the world!
0 Kudos
Message 6 of 6
(4,996 Views)