Skip to content

Windows: libusb Windows hotplug support #86

@mcuee

Description

@mcuee
Member

This is one of the long standing missing feature for Windows.

Activity

mcuee

mcuee commented on Nov 27, 2015

@mcuee
MemberAuthor

Last known tree back in the libusbx time.
https://github.com/dickens/libusbx-hp/tree/windows-hotplug-3

changed the title [-]libusb Windows hotplug support[/-] [+]Windows: libusb Windows hotplug support[/+] on Feb 25, 2016
changyp6

changyp6 commented on Mar 2, 2016

@changyp6

libusb hotplug for Windows is really important.
I have a program running on Linux/Window/MacOS, but Windows doesn't have hotplug support, I have to write my own device detection code for Windows.
But Windows only reports that there is a device arrived or there's a device removed, you have to find which one is added or removed.
So when I receive device remove event, I usb libusb_get_device_list() to get current device present in the system, and compare this list with the old one to find out which one is removed, and I use the same method to find which one is added, after I find the difference, my program will handle the removed/added device.

But if I unplug the device and plug it back to the same USB port very quickly, and Windows's driver searching program is disabled(to make system recognize device faster), my program can get device remove and device add event correctly, but libusb_get_device_list() will get a usb device list the same as the previous saved one.

Here is the reason:
When my program receives device remove event, and start to list all the USB devices, because the unplug/plug action is so fast, libusb_get_device_list() will give a list after the device is plugged back. So this USB device list is the same as the list before unplug/plug action, which means my program cannot find out which device is removed and which is added, there will be 2 missing actions for my program.

Because my program is event driven, this causes 2 events missing.

I really hope that hotplug feature can be implemented for Windows.

mcuee

mcuee commented on Mar 3, 2016

@mcuee
MemberAuthor
changyp6

changyp6 commented on Mar 3, 2016

@changyp6

I tried that before, I even tried to merge the change into libusb 1.0.19, but I failed to merge it to newer code. I still need to use latest branch, because there are tons of bug/leak fixes for Windows platform.

Hope Windows hotplug support can be implemented soon.

dickens

dickens commented on Mar 3, 2016

@dickens
Member

Will be part of the next release. Unfortunately it is a complicated set of
changes.

Regards,
Chris

changyp6

changyp6 commented on Mar 3, 2016

@changyp6

This is a great news!

added this to the 1.0.22 milestone on Mar 6, 2016
chrisba77

chrisba77 commented on Sep 2, 2016

@chrisba77

were there any changes regarding the hotplug issue since then? Currently having the problem with LibUsbDotNet that communication with an unplugged-replugged device is only possible again after reinstalling the driver using the Inf-Wizard OR restarting Windows. This device is a CardReader. On the other hand, i dont have issues hotplugging a USB Keyboard. Does anyone have suggestions?

diabolo38

diabolo38 commented on Sep 3, 2016

@diabolo38

@chrisba77 strange w/o any "hotplug" support you should be able to re-use the device without driver re-install reboot etc
if:
-release any claimed interface
-close the device
-call exit on the libsusb context

then run again lib usb init , device detect ,re-open re claim etc ..

That is what i do to get control again of unplugged and re-pluged device
not real nice but the simplest i did find.

chrisba77

chrisba77 commented on Sep 5, 2016

@chrisba77

@diabolo38 I do all this. And actually after plugging in the device again, communication is possible. BUT the read values coming from the device are not valid anymore.
After reading in a Tag / Card the device sends some HID reports with Number-Keys including a Return Hit. After unplug / replug, these values seem to be random. Checked with Port Sniffer that I read the right values coming from the device. But sent Key Hits are not valid anymore and change every time i read in the same Tag. Reconnecting or Restarting my Test-SW doesnt help. Only thing that helps is rerunning Inf-Wizard or a reboot.

diabolo38

diabolo38 commented on Sep 5, 2016

@diabolo38

@chrisba77 if device is hid using standard os hid device driver then the issue could be os driver or the device itlsef. I can't see such issue with non hid device at least.

97 remaining items

sonatique

sonatique commented on Dec 28, 2023

@sonatique
Member

Please see #1406 . Comments welcome.

fabiensanglard

fabiensanglard commented on Jan 29, 2024

@fabiensanglard

@mcuee while #1406 is being reviewed, is there an official recommended way to poll on system without hotplug?

I tried the method mentioned by @Aii-Wei above.

I tested and found that the device change can be detected according to idVendor, idProduct, port from libusb_get_port_number, address from libusb_get_device_address.

I can confirm that using <vid, pid, port, address> tuplet works on Windows and Linux (the address is increased every time the device is connected).

Note that it does not work on Macos (both port and address are constant).

mcuee

mcuee commented on Feb 6, 2024

@mcuee
MemberAuthor

@fabiensanglard

For Windows, I think we should focus on reviewing and testing PR #1406 to get it merged.

As for the work-around, let's see if @tormodvolden has some recommendations for platforms without hotplug support.

fabiensanglard

fabiensanglard commented on May 20, 2024

@fabiensanglard

I wrote a code sample to illustrate how to fallback on system without support for hotplug.

PR #1498

mosot624

mosot624 commented on Oct 3, 2024

@mosot624

Not sure if this is the right place to comment, but is the hotplug for windows fully implemented now if it isn't. Are we getting it this year or next year?

Timmmm

Timmmm commented on Oct 3, 2024

@Timmmm
Contributor

You mean this decade or next right? 😬😄

mcuee

mcuee commented on Jun 6, 2025

@mcuee
MemberAuthor

#1406 has seen some updates recently now that @sonatique is part of the admin team.

Let's hope that Windows Hotplug will be added within year 2025.

ValeZAA

ValeZAA commented on Jul 8, 2025

@ValeZAA
36.0.0 (Apr 2025)
adb
Re-written libusb USB backend (uses sync API instead of async API). Improves reliability and fixes memory exhaustion on Linux.
Libusb USB backend hot-plug now supports for Windows (enables USB speed detection).
Improved server-status now displays if mdns is enabled.

adb from google added hotplug

sonatique

sonatique commented on Jul 9, 2025

@sonatique
Member

@ValeZAA : Hello, I didn't get your point, sorry. Could you elaborate?

sonatique

sonatique commented on Jul 9, 2025

@sonatique
Member

Let's hope that Windows Hotplug will be added within year 2025.

@mcuee : do you have any idea about things I can do to actually see this happens?

markg85

markg85 commented on Jul 9, 2025

@markg85

@sonatique Please don't reply with just a quote. That's as helpful as just not saying anything at all. Use the edit button, please! Especially if your message before it was just a minute ago.

Thank you for your understanding.

mcuee

mcuee commented on Jul 14, 2025

@mcuee
MemberAuthor

Let's hope that Windows Hotplug will be added within year 2025.

@mcuee : do you have any idea about things I can do to actually see this happens?

Let's discuss with @tormodvolden to see how to make progress with this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @markg85@whitequark@thegecko@dickens@Timmmm

        Issue actions

          Windows: libusb Windows hotplug support · Issue #86 · libusb/libusb