|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
LibUSB Win32 (And my inability to Program C) driving me crazy.....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. ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Libusb-win32-devel mailing list Libusb-win32-devel@... https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel |
|
|
Re: LibUSB Win32 (And my inability to Program C) driving me crazy.....Hello Shane,
* On Fri, Oct 30, 2009 at 05:24:12PM +0100 Shane O'Neill wrote: > 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". > 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 Do you use "current" in different occassions? Do you have some race condition: That is, two different code paths in two threads that both write to "current"? I would expect the problem in parallelism. Can't you define your "current" variable locally, inside of the Opendev() function? That would solve this problem. HTH, Spiro. -- Spiro R. Trikaliotis http://opencbm.sf.net/ http://www.trikaliotis.net/ http://www.viceteam.org/ ------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference _______________________________________________ Libusb-win32-devel mailing list Libusb-win32-devel@... https://lists.sourceforge.net/lists/listinfo/libusb-win32-devel |
| Free embeddable forum powered by Nabble | Forum Help |