LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview People to Help me...

Hi,

 

   Below is my the function "gf_get_server_info" that i need to call from the Dll.. Please let know how to pass this argument from the Labview environment..

 

typedef struct
{
   UNSIGNED32  ident_number[2];
   UNSIGNED16  version;
   UNSIGNED16  release;
   UNSIGNED16  update;
}  GF_SW_VERSION_INFO;

typedef struct
{
   UNSIGNED32           target_number;
   GF_SW_VERSION_INFO   info_boot_loader;
   GF_SW_VERSION_INFO   info_pld_firmware;
   GF_SW_VERSION_INFO   info_mvb_server;
}  GF_SERVER_INFO;


GF_RESULT FunctionDef   gf_get_server_info (GF_SERVER_INFO * server_info);

 

I need ur help..Please help....

0 Kudos
Message 1 of 11
(3,707 Views)

Its will be impossible to call such DLL directly from LabVIEW due to many reasons (alignment, array in cluster etc).

You have to develop Wrapper DLL.

Refer to How LabVIEW Stores Data in Memory

 

Andrey.

 

0 Kudos
Message 2 of 11
(3,683 Views)

Hi Andrey,

 

    Thanks for your reply.... Please let me know where i can find the details for writing a wrapper Dll...

 

thanks in advance.... 🙂

 

0 Kudos
Message 3 of 11
(3,670 Views)

I wouldn't say impossible, but a little tricky, mostly due to alignment issues. The arrays are fixed size, so it's not like you're dealing with a pointer.

 


@LV!!!!!!!! wrote:

Hi Andrey,

 

    Thanks for your reply.... Please let me know where i can find the details for writing a wrapper Dll...


 

You just write a DLL in C that calls your DLL. The wrapper DLL deals with simple datatypes that LabVIEW can handle. LabVIEW would call this wrapper DLL.

 

What else did you want to know?

0 Kudos
Message 4 of 11
(3,659 Views)

There are no "ready for use" recipes. In every case it depends from many factors.

 

As starting point you can read the following article:

Creating Dynamic Link Library (DLL) in Microsoft Visual C++ 6.0 for use in LabVIEW 

Also good example installed in "<Program Files>\National Instruments\LabVIEW x.x\examples\dll\data passing"

 

Basic knowledge of C and C compiler is required, of course.

 

Andrey.

 

0 Kudos
Message 5 of 11
(3,653 Views)

@smercurio_fc wrote:

I wouldn't say impossible, but a little tricky, mostly due to alignment issues. The arrays are fixed size, so it's not like you're dealing with a pointer.

 


Ah, I missed this, you're seems to be right. Any way I'll suggest to create wrapper, because its a good programming exercise itself and the code will be more clear without strange I16->I32 conversions.

Andrey.

 

0 Kudos
Message 6 of 11
(3,644 Views)

Just for reference, the way you do it without a wrapper dll is as follows:

 

First make a copy of the clusters that are intended just for calling the DLL and rewrite the arrays as scalars. LabView arrays have the number of array elements at the front, and C arrays don't. So instead of the 2-element array, you would have two scalar UINT32s, ident_number_0 and ident_number_1. Next call Flatten to String on the whole GF_SERVER_INFO cluster using platform-specific byte ordering, then convert the string to a byte array, then pass the byte array to the DLL.

 

As Andrey said, things can go wrong. For example GF_SW_VERSION_INFO has 112 bytes of data. The compiler is almost certainly going to pack this into 128 byte chunks in memory because it's faster. There is no way to know what size it really is without calling sizeof() using the compiler that built the DLL. Your structure must exactly duplicate the size that the DLL is expecting, e.g. by putting a UInt16 at the end of GF_SW_VERSION_INFO as padding. This is a pain, which is why people are recommending passing native LabView types to a DLL that you write and then letting your DLL call the external DLL.

 

Getting the data back out is the reverse of this process; byte array to string, unflatten string to cluster, convert special dll cluster to the "user" cluster.

 

Note the above only works with flat data types (no pointers).

0 Kudos
Message 7 of 11
(3,623 Views)

Since there are no variable-size items in your struct, you can define a cluster in LabVIEW that matches the struct exactly and should work fine when passed to the DLL.  Replace 2-element array in the struct with a cluster of two elements.  Everything else translates directly to LabVIEW data types.

 

EDIT added for clarity: Make a cluster that matches the GF_SW_VERSION_INFO struct first, with a 2-element cluster replacing the array.  Make that a type defintion.  Create a second cluster that matches GF_SERVER_INFO and include in it three instances of the GF_SW_VERSION_INFO cluster.  Pass that by reference to your DLL.

0 Kudos
Message 8 of 11
(3,611 Views)

 


@nathand wrote:

you can define a cluster in LabVIEW that matches the struct exactly 


 

This will not work in this case. You also may need gaps between clusters (and the size of gap depends from compiler alignment). For exampl, in case of CVI compiler:

 

Screenshot.png

 

Andrey.

 

Message 9 of 11
(3,574 Views)

Hi All,:manvery-happy:

 

    I tried writing the wrapper using the Import Shared Library Wizard.. It worked for simple and certain complex datatypes.. But need I  to write my own wrapper funciton for other function call inside the dll.. 😞

 

   Thank You All for your support...... 🙂 🙂

 

With Kind Regards,

 

Muraledharan R

0 Kudos
Message 10 of 11
(3,528 Views)