LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling Dll Function

I want to call The function take a pointer to a pointer to an array of devices. The Code is available in following link http://www.eggntomatto.com/techforum/viewtopic.php?f=2&t=2
0 Kudos
Message 1 of 13
(3,736 Views)
Hi,
      It's possible to pack an array of bytes on the LabVIEW side, then pass its pointer or handle (pointer to pointer) to the DLL using the Call Library Function node.  The trick (maybe difficult) is to pack the data so the DLL will interpret it correctly.  To do that you have to know exactly what the DLL expects - in this case one or more LPSKYETEK_DEVICEs.
 Look in:
#include "SkyeTekAPI.h"
#include "SkyeTekProtocol.h"
#include "SkyeTekAPI.h"
and
#include "SkyeTekProtocol.h"
for the structure of LPSKYETEK_DEVICE.
 
If you have a C or C++ compiler handy, it may be easier build a LabVIEW-friendly DLL that exposes simple-data-types to LabVIEW, then builds the "LPSKYETEK_DEVICE" array and calls your target DLL.
Cheers!
#include "SkyeTekAPI.h"
#include "SkyeTekProtocol.h"
 
 
"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 2 of 13
(3,724 Views)
Could you please attach example file? It will be greatly helpful.
 
Thanks
0 Kudos
Message 3 of 13
(3,694 Views)

I have seen the structure it is in the folowing link http://www.eggntomatto.com/techforum/viewforum.php?f=2 now with this how to create LabVIEW supported DLL.

Bear me for asking step by step procedure.

Thanks

0 Kudos
Message 4 of 13
(3,692 Views)

Hi MSS,

      The first 512+ bytes are no problem (assuming TCHAR is one byte), but what is SKYTEK_DEVICE_FILE?  If it's a structure, then readFD and writeFD each need to be packed.  "user" and "internal" are pointers (probably 4 bytes each) - do they need be valid when calling the DLL, or is it ok if they're NULL (0) ?

MSS, LabVIEW can allocate the memory for this data-structure and pass a handle to your DLL, but the pointers and File-Descriptors (if that's what they are) may need to be defined/valid first.  Are you sure it's OK to pass zero for the pointers? 

typedef struct SKYETEK_DEVICE
{
TCHAR friendly[64];
TCHAR type[64];
TCHAR address[256];
unsigned char asynchronous;
unsigned int major;
SKYETEK_DEVICE_FILE readFD;
SKYETEK_DEVICE_FILE writeFD;
void *user;
void *internal;
} SKYETEK_DEVICE, *LPSKYETEK_DEVICE;

"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 5 of 13
(3,684 Views)

Hi

Thanks for you quick reply

Yes I think SKYTEK_DEVICE_FILE ia a structure but I could not locate it in .h files. If it is a structure, packing the readFD and writeFD, how to do?

I am not sure passing zero to the pointers. But I can find it out and post it.

Are you working in skyetek?

Thanks

0 Kudos
Message 6 of 13
(3,680 Views)


@MSS wrote:

Hi

Thanks for you quick reply

Yes I think SKYTEK_DEVICE_FILE ia a structure but I could not locate it in .h files. If it is a structure, packing the readFD and writeFD, how to do?

I am not sure passing zero to the pointers. But I can find it out and post it.

Are you working in skyetek?

Thanks



If you can't find a typedef or define for SKYTEK_DEVICE_FILE anywhere your interface would not even be usable in a normal C compiler and therefore of course also not from within LabVIEW.

Structure packing is in principle simply inlining into the main structure of whatever is in the sub structure. The difficulty here could be the byte alignment which needs to be known too.

Also those structures use TCHAR which would indicate that there is actually an API that accepts either ANSI or Widechar (16bit Unicode) types. LabVIEW itself only supports ANSII so you would need to interface to the ANSII versions of the Skytek API.

What I can say about this API is that it would be definitly better to write a wrapper DLL and interface it in that way with LabVIEW. Also anyone wanting to interface more complex APIs with LabVIEW should be able to write a wrapper DLL. If there is no knowledge about that you have bascally also not enough knowledge to interface such a DLL directly to LabVIEW. In fact interfacing directly to LabVIEW needs a lot more low level knowledge about what a C compiler does exactly when putting parameters into memory than if you would write the wrapper DLL and let the C compiler figure out those nitty gritty details when translating between the C API and a parameter API that is a lot more LabVIEW friendly.

Rolf Kalbermatter


Message Edited by rolfk on 05-04-2008 04:11 PM
Rolf Kalbermatter
My Blog
0 Kudos
Message 7 of 13
(3,671 Views)

Thanks Mr. Rolfk for your advice.

Where could  I get details about creating wrapper dll. is it easy to do. what are the things that I have to have to do that?

Regards

0 Kudos
Message 8 of 13
(3,653 Views)


@MSS wrote:

Thanks Mr. Rolfk for your advice.

Where could  I get details about creating wrapper dll. is it easy to do. what are the things that I have to have to do that?

Regards



I'm afraid there is no ready made tutorial about wrapper DLLs because they differ greatly depending on the actual API you want to interface too. The first thing you will need is some good C programming knowledge. Without that it is obviously difficult to write a DLL but if you don't have that knowledge interfacing to such a DLL without wrapper is even harder.

The next step is about how to create DLLs (shared libraries) in general. This is explained for most C compilers that you could get, in the examples that come with those compilers. It's no black magic nor rocket science but mostly just following a few steps that can and will differ for each compiler to some extend.

What you want to do in a wrapper is writing a number of C functions that take more LabVIEW friendly data types (flat structures only with no embedded string or array pointers, standard C string pointers and array pointers as separate function parameters etc. etc.) and then inside those functions construct the more complex data types your real API takes. There are quite some (simple) examples about interfacing to external code in LabVIEW in general and getting these to compile and run first is definitely a good start.

You may now say but hey this is hard and I can't do that since I do not know how and all I can answer to this is that if you do not know how to do such a wrapper DLL you can never hope to successfully interface to the complex API data structures without exactly such a wrapper. So you will have to learn some C and learn how to write such a wrapper and then you can start to do it without wrapper although at that point you will likely find that trying to figure out all those nitty gritty details about structure size, correctly setting up the memory in LabVIEW to pass those parameters to the API function and all is way to troublesome, time consuming and also bad for future maintainability that you will not even consider not to create wrapper DLLs anymore expect for the most quick and dirty test cases.

Rolf Kalbermatter
Rolf Kalbermatter
My Blog
0 Kudos
Message 9 of 13
(3,642 Views)

Hi MSS,

      Did your hardware come with programming examples?  If so, and they're in C, consider obtaining a C++ compiler (free.)  Get the examples working in C, then you'll be in a good position to "wrap" the functionality in a DLL for LabVIEW.  Once you know how to compile your examples, creating the DLL for LabVIEW will be a small step.  RIght now, though, it sounds like you have some learning to do!

Cheers   



MSS wrote:

Thanks Mr. Rolfk for your advice.

Where could  I get details about creating wrapper dll. is it easy to do. what are the things that I have to have to do that?

Regards




"Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)
0 Kudos
Message 10 of 13
(3,631 Views)