简体   繁体   English

如何检测硬件设备是否已通过 USB 端口从我的 PC 上插入或拔出

[英]How can I detect whether a hardware device has been plugged or unplugged from my PC through USB port

Current effort: 1, hidapi-1.1.jar 2, GetRawInputDeviceList当前努力:1、hidapi-1.1.jar 2、GetRawInputDeviceList

hidapi-1.1.jar is aborted in my app for some reason.由于某种原因,hidapi-1.1.jar 在我的应用程序中中止。

GetRawInputDeviceList isn't stable in Win10 referring https://stackoverflow.com/questions/32419314/getrawinputdevicelist-and-getrawinputdeviceinfo-fail-to-work-in-win10 GetRawInputDeviceList 在 Win10 中不稳定,参考https://stackoverflow.com/questions/32419314/getrawinputdevicelist-and-getrawinputdeviceinfo-fail-to-work-in-win10

I wonder is there any other method to reach my goal?我想知道还有其他方法可以达到我的目标吗? OS is windows, programming language is not limited.操作系统是windows,编程语言不限。

You can use the hotplug event notification API present in libusb .您可以使用libusb的热插拔事件通知 API。 Documentation is here: http://libusb.sourceforge.net/api-1.0/hotplug.html文档在这里: http : //libusb.sourceforge.net/api-1.0/hotplug.html

In a nutshell, this API lets your program get a callback whenever a device is connected or disconnected, and lets you filter for just the devices you care about (see libusb_hotplug_register_callback ).简而言之,这个 API 允许您的程序在设备连接或断开连接时获得回调,并让您仅过滤您关心的设备(请参阅libusb_hotplug_register_callback )。

Note that the hotplug API isn't supported on all OSes;请注意,并非所有操作系统都支持热插拔 API; if it isn't, you will have to fallback to enumerating devices using libusb_get_device_list .如果不是,您将不得不回libusb_get_device_list使用libusb_get_device_list枚举设备。

Actually SetupDiGetDeviceInstanceId can be used to monitor it.实际上可以使用SetupDiGetDeviceInstanceId来监控它。 For details, pls refer to https://msdn.microsoft.com/en-us/library/windows/hardware/ff551106(v=vs.85).aspx .有关详细信息,请参阅https://msdn.microsoft.com/en-us/library/windows/hardware/ff551106(v=vs.85).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Java通过USB端口与设备通信? - How can I use Java to communicate to device through USB port? 如何通过USB上的串行端口将数据从Android设备发送到PC - How to send data from an Android device to pc through serial port over USB 如何确定文件是否在USB大容量存储设备上? - How can I determine whether a file is on a USB mass storage device? 当我通过USB将数据从PC流到Arduino时,为什么我的串口一直断开? - Why my serial port keep disconnecting when I stream data from PC to Arduino via usb? 如何获取USB设备是连接到USB3.0还是USB2.0端口 - How to fetch whether a USB device is connected to USB3.0 or USB2.0 port 从开发PC拔出设备时,Android bindService在4.0.4上失败 - Android bindService fails on 4.0.4 when device is unplugged from development PC 如何禁用和启用 USB OTG 连接以打开和关闭硬件设备? - How can I disable and enable a USB OTG connection to power a hardware device on and off? 如何判断文件(从Dropbox网页读取)是否已在Java中更改? - How can I judge whether the file (read from dropbox webpage) has been changed or not in Java? 如何检测Mac是否有来自Java的Retina显示器? - How can I detect whether a Mac has a Retina display from Java? 如何使用 Java 检测 PC 已空闲 30 秒? - How to detect that a PC has been idle for 30 seconds using Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM