libftdi Archives

Subject: Re: Multiple interface issues

From: Steve Soloski <ssoloski@xxxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Sat, 31 May 2014 22:38:08 -0400
On 5/31/2014 8:10 PM, Xiaofan Chen wrote:
On Sun, Jun 1, 2014 at 3:52 AM, Steve Soloski <ssoloski@xxxxxxxxxxxxxx> wrote:
Just rebuilt libusb (1.0.18) and libFTDI (1.1) from the tarballs; cross
compiling on Linux using x86_64-w64-mingw32.

Same result when running under Win8 x64 - if libusbK.dll is in my path then
I get the following error when trying to open the device more than 32 times:

opening device 28 of 50...
opening device 29 of 50...
opening device 30 of 50...
opening device 31 of 50...
opening device 32 of 50...
ftdi_usb_open failed: -5 (unable to claim usb device. Make sure the default
FTDI driver is not in use)

However, I noticed something interesting...

When I try to connect to my device I always use Interface B first (it's my
control channel and needed to init my device); Interface A is only used (in
a separate thread) when trying to capture images. So, trying to open my
device like this:


     for (i=0; i<50; i++) {
       struct ftdi_context *ftdi = ftdi_new();
       ftdi_set_interface(ftdi, INTERFACE_B);

       fprintf(stderr, "opening device %d of 50...\n", i);
       ret = ftdi_usb_open(ftdi, 0x0403, 0x7C38);
         ...
       ret = ftdi_usb_close(ftdi);
       ftdi_free(ftdi);
     }


will fail after 32 open/closes with the error above.

However, I just tried not setting the interface to B and it works fine and
doesn't fail - even with libusbK.dll! Seems like there's something about not
having Interface A claimed that is causing issues... of course, since I
always open with B that doesn't do me much good! ;)

I think you hit one of WinUSB's limitation.

- with WinUSB configured to point to my composite device
(ie DeviceID = "VID_0403&PID_7C38"), this fails after 32 iterations
(way down in the guts of libusb - basically after 32 iterations it runs
out of valid interfaces).

- with WinUSB configured with two interfaces (ie DeviceID_0 =
"VID_0403&PID_7C38&MI_00" and DeviceID_1 =
"VID_0403&PID_7C38&MI_01"), this run without any issues.

To use WinUSB as the driver for the USB composite device parent,
you have to claim the first interface first (interface 0, or channel A).
Ref: 
http://msdn.microsoft.com/en-us/library/windows/hardware/ff540245(v=vs.85).aspx

Again, libusbk.sys does not have such limitation, you should
try libusbk.sys instead (you will need libusbK.dll).



Hmmm... but these errors are happening when libusbK is present (ie in windows\system32 and windows\syswow64), and if I remove libusbK then the errors go away. So I can run the above code with just WinUSB (no libusbK.dll) and it works fine; however if libusbK.dll is present then it fails. The reason the errors were happening before was due to the fact that libusbK was present.

I'll double check everything just to make sure I didn't screw something up... it sounds like libusbK would really make my life easier; but I just need to make sure I understand why this issue is happening. and I'm sure it's something on my side, I just don't know what it could be. I'll take another look at things tomorrow...

Steve





--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
Current Thread