|
From: Matthias B. <mat...@go...> - 2021-09-22 09:18:57
|
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. - 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. - 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. - 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. 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 |