|
From: Shane O'N. <sha...@in...> - 2009-10-30 16:24:37
|
I am trying to use LibUSB 0.12.2 with LabVIEW (from National Instruments).
In order to be able to pass a pointer to usb_dev_handle to LabVIEW
(which doesn't deal with pointers) I am interpreting the return code of
a custom-written "open" funciton as I32. This is standard practise with
LabVIEW and normally works no problem.
The code in question works in ways I would not expect.
struct usb_dev_handle *Opendev(int vid, int pid)
{
struct usb_bus *bus;
struct usb_device *dev;
char message[100];
for (bus=usb_get_busses();bus;bus=bus->next)
{
for (dev=bus->devices;dev;dev=dev->next)
{
if (dev->descriptor.idProduct == pid)
{
if (dev->descriptor.idVendor == vid)
{
current = usb_open(dev);
sprintf(message, "Pointer = %08x.", current);
MessagePopup(message, message);
}
}
}
}
return current;
}
current is of data type "usb_dev_handle *current".
This code SHOULD return a 32-but pointer to a usb_dev_handle structure
whenever a device is found with the same VID and PID as supplied to the
function. I can then use this I32 as an input parameter for functions
within the Libusb0.dll file (such as usb_control_msg). This works
whenever I have a valid pointer returned from the function above but for
some reason I cannot get it to return a proper value.
There are plenty of occasions where the value of "current" as displayed
by the message box is valid but the function still returns NULL.
Is there something obviously wrong with what I'm doing here of might
this be a bug in the compiler / IDE I'm using (LabWindows CVI 9.0). I'm
strongly tending towards a bug in either LabVIEW or LabWindows CVI if
nobody can point out some glaring mistake to me.....
Thanks
Shane.
|