From: Robert R. <R.R...@Qu...> - 2021-09-22 13:55:14
|
Hi Matthias, Please see below for replies. At 10:28 AM 9/22/2021 +0000, lib...@li... wrote: >Date: Wed, 22 Sep 2021 11:18:38 +0200 >From: Matthias Bolte <mat...@go...> >To: Xiaofan Chen <xia...@gm...> >Cc: Robert Ritchey <R.R...@qu...>, libusb-devel > <lib...@li...> >Subject: Re: [libusb] libusb_open returns -12 > (LIBUSB_ERROR_NOT_SUPPORTED) >Message-ID: > <CABBroziihYB-fguK0Zqr1kNLh+tCbvLYXmnUfNBtu3uRLmZ3=g...@ma...> >Content-Type: text/plain; charset="UTF-8" > >Am Mi., 22. Sept. 2021 um 03:38 Uhr schrieb Xiaofan Chen <xia...@gm...>: > > > > On Wed, Sep 22, 2021 at 7:37 AM Robert Ritchey > > <R.R...@qu...> wrote: > > > > > > I am running under Windows and check for my device when I get a > > > DBT_DEVICEARRIVAL event and check to see if it is gone when I get a > > > DBT_DEVICEREMOVECOMPLETE event. > > > > > > The scenario is that I can open the device, do some transfers (actually > > > download firmware), then tell the device to boot. It disconnects, and I > > > release the interface and close it successfully. > > > > > > When the firmware boots I get DBT_DEVICEARRIVAL event and look for > > > my device. I can get the device list and descriptors but when I find my > > > device and try to open I get this error. > > > > > > LIBUSB_ERROR_NOT_SUPPORTED seems like a strange error code to > > > get for libusb_open. I have single stepped through it many times and it > > > seems right but I must be missing something. > > > > I could be wrong but I believe there is no solution for now until hotplug > > is supported by the Windows backend. > > Ref: https://github.com/libusb/libusb/issues/86 > >That is not true. I've successfully run libusb on Windows with the >same Windows device change notifications as used here for years now. > >A few things to check: > >- Why are you only checking the vendor ID before opening the device? >You should check the product ID too to avoid trying to open the wrong >device. I do check the product ID before I try to open the device to check the serial number. I only open my devices, both in the attach and detach. >- Are you sure that Windows has loaded the correct device driver for >your device. Preferably WinUSB, assuming we're talking about a vendor >specific device and not a class device. I do use WinUSB, I support the Microsoft extended descriptors to load the WinUSB driver. I have actually been running this code for 8 years now but my old version of attach and detach only looked for one device. I now need to support 2 devices. >- Currently your code assumes that no errors will ever occur and dies >with an assert on the first error it sees. Make your code more robust >and actually deal with errors correctly. Do not give up everything on >the first error, but only give up the specific device you're currently >checking. There was a bug in libusb that resulted in libusb >enumerating the same device multiple times, but only one of the >multiple instances of the same device could be opened successfully. >This bug has since been fixed in libusb, but maybe you're using an old >libusb version or there is a different version of this bug still >present. I receive no errors before I get the LIBUSB_ERROR_NOT_SUPPORTED error. As I mentioned, when I was checking for only 1 device I never had an error in 8 years. I never ran into the bug you described before. >- What libusb version are you using? There were several critical >improvements in the USB enumeration logic of libusb on Windows lately. >If you're not using the latest release 1.0.24 then you should start >there. If the problem persists, try the current git version to see if >this is due to a libusb bug that has been fixed, but not released yet. >If that doesn't help, test backwards through the libusb releases to >check if this is a bug in libusb that has been introduced in a recent >release. I am running a release I downloaded in 2014 and have never had an issue in all this time until I re-worked my code for multiple devices. That is why I thought I must have missed something in reworking my code that I have not been able to find over the last 3 days of debugging. >You can take a look at my project using libusb, but the code is not so >easy to follow, as it started with libusb 1.0.6 and went through to >libusb 1.0.24 and deals with 5 different operating systems: > >https://github.com/Tinkerforge/brickd Thank you. I am sure this will be helpful for me to see how you deal with errors returned. -Bob -------------------------------------------------------------------- Robert Ritchey Quest Engineering & Development, Inc. Suite B-8 6125 South Ash Avenue Tempe, AZ 85283 Tel: (480) 460-2652 -------------------------------------------------------------------- |