LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Communicate using libusb0.dll

Hello,

 

I have to develop an application in LabVIEW witch manage the MOWAY robot. I communicate with a RC USB Key so i have to handle with the libusb0.dll. My problem is the "usb_device *dev" used to open every function of the Dll and this type is define by :

 

 

struct usb_device
{
    struct usb_device *next, *prev;

    char filename[LIBUSB_PATH_MAX];

    struct usb_bus *bus;

    struct usb_device_descriptor descriptor;
    struct usb_config_descriptor *config;

    void *dev;		/* Darwin support */

    unsigned char devnum;

    unsigned char num_children;
    struct usb_device **children;
};

 As you see this type is not retranscriptible in LabVIEW.

So i tried to wrap this Dll in C but it was not really a success.

 

If you have any idea, how to use this Dll in LabVIEW, i will be glad to hear it.

 

Thanks for your time.

 

0 Kudos
Message 1 of 5
(4,829 Views)

It seems this structure is used as a sort device descriptor, sometimes also called handle. As such it is most likely passed as a pointer to all usblib functions and in that case if you don't need to access any of the members in that structure from the LabVIEW diagram directly you can simply treat it as pointer sized integer. There will be one API function that creates this "handle" returning it either as return value of the function or in a double referenced parameter, one or mor functions that take a reference (pointer) to this structure to operate on the device and one function that also takes a pointer to this structure and deallocates all resources.

 

Only if you do need to access members in that structure directly from the LabVIEW diagram you indeed won't get around to write a wrapper DLL to do that.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 2 of 5
(4,812 Views)

Hello,

 

And thank you for having posted here.

 

I think those links should help you:

 

- Tutorial "Using Existing C Code or a DLL in LabVIEW" : http://decibel.ni.com/content/docs/DOC-1690

- Example "Running a C DLL in LabVIEW" : http://decibel.ni.com/content/docs/DOC-2028

 

Tell me if it has been helpful to you.

 

Regards,

Jérémy C.
NI France

0 Kudos
Message 3 of 5
(4,787 Views)

Hello,

Thank you for yours answers.

I tried the link you send me JérémiC so i finally get that :

 

 

#include "stdafx.h"
#include "usb.h"
#include <windows.h>

#ifdef _MANAGED
#pragma managed(push, off)
#endif

#define LIBUSB_DLL_NAME "libusb0.dll"
typedef usb_dev_handle * (*usb_open_t)(struct usb_device *dev);
static usb_open_t _usb_open = NULL;
typedef struct usb_bus * (*usb_get_busses_t)(void);
static usb_get_busses_t _usb_get_busses = NULL;



#define MY_VID 0x04D8
#define MY_PID 0x0014

extern "C" __declspec(dllexport)usb_dev_handle *open_dev(void);

BOOL APIENTRY DllMain (HMODULE hModule,
						DWORD ul_reason_for_call,
						LPVOID lpReserved
						)
{
	HINSTANCE libusb_dll  = LoadLibrary(LIBUSB_DLL_NAME);

    if (!libusb_dll)
        return FALSE;

    _usb_open = (usb_open_t)
                GetProcAddress(libusb_dll, "usb_open");
	_usb_get_busses = (usb_get_busses_t)
                      GetProcAddress(libusb_dll, "usb_get_busses");
	return TRUE;
}

usb_dev_handle *open_dev(void)
{
    struct usb_bus *bus;
    struct usb_device *dev;

    for (bus = usb_get_busses(); bus; bus = bus->next)
    {
        for (dev = bus->devices; dev; dev = dev->next)
        {
            if (dev->descriptor.idVendor == MY_VID
                    && dev->descriptor.idProduct == MY_PID)
            {
                return usb_open(dev);
            }
        }
    }
    return NULL;
}

#ifdef _MANAGED
#pragma managed(pop)
#endif

 

But i still have this error :"IntelliSense: argument of type "const char *" is incompatible with parameter of type "LPCWSTR""

 

I know that it's no longer a LabVIEW problem but i really need a solution to this program.

 

2 IntelliSense: argument of type "const char *" is incompatible with parameter of type "LPCWSTR"
0 Kudos
Message 4 of 5
(4,770 Views)

Hello,

 

Indeed it's not a LabVIEW problem. I invite you to post your problem on a suitable forum.

Jérémy C.
NI France

0 Kudos
Message 5 of 5
(4,763 Views)