Hi!

After updated libusb from 1.0.11 to 1.0.17 in my Debian Wheezy, I have got
the same problem as described in next thread:
http://developer.intra2net.com/mailarchive/html/libftdi/2011/msg00609.html

A sample program:

#include <stdio.h>
#include <stdlib.h>
#include <ftdi.hpp>

int main(void)
{
    Ftdi::Context *ftdic = new Ftdi::Context;

    int ret = ftdic->open(0x0403, 0x6001);
    if (ret < 0) {
        fprintf(stderr, "open error %d\n", ret);
    }
    delete ftdic;
    return EXIT_SUCCESS;
}

ftdic->open() returns -5

I suppose that this is because there is call get_strings_and_reopen() which
calls ftdi_usb_get_strings() which calls libusb_open() for already opened
device. A solution may be to call ftdi_usb_close_internal() from
ftdi_usb_get_strings() function before reopen it or to check if it is
already opened and don't open twice. I tried both but prefer second and
simple do like this:

--- libftdi1-1.1/src/ftdi.c.orig 2014-02-05 22:24:11.000000000 +0600
+++ libftdi1-1.1/src/ftdi.c      2014-05-15 14:42:13.534444380 +0600
@@ -413,8 +413,9 @@
     if ((ftdi==NULL) || (dev==NULL))
         return -1;

-    if (libusb_open(dev, &ftdi->usb_dev) < 0)
-        ftdi_error_return(-4, "libusb_open() failed");
+    if (ftdi->usb_dev == NULL)
+        if (libusb_open(dev, &ftdi->usb_dev) < 0)
+            ftdi_error_return(-4, "libusb_open() failed");

     if (libusb_get_device_descriptor(dev, &desc) < 0)
         ftdi_error_return(-11, "libusb_get_device_descriptor() failed");


-- 
wbr
  Denis Sirotkin


--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to [email protected]   

Reply via email to