Home   |   Jungo Corporate Web Site   |   Connectivity Software Store   |   Contact us   |   Search:
Home Connectivity Software Support WinDriver Support Technical Documents

Technical Document #86



Doc ID: 86
Product: WinDriver
Version:  --

How do I detect that a USB device has been plugged in or disconnected?

If you are using version 5.20 or later of WinDriver, you can use WinDriver's API to register to listen to specific Plug-and-Play and/or power management notifications from the OS, including notifications of device insertion/removal, and implement a relevant call-back in your application to handle such situations. When using version 6.0 and above, use WDU_Init() to register to listen for the notifications you are interested in. In versions 5.20 - 5.22, use event_register(). Please refer to the WinDriver User's Manual for the WinDriver version that you are using for a detailed description of the relevant APIs.

In earlier versions of WinDriver - version 5.05b or below - WinDriver did not provide specific API support for Plug-and-Play and power management events. In these versions, WD_UsbScanDevice() detects the devices which are connected to the computer at the time of the function call. If another device is later connected to the computer, or a device is disconnected, these changes will not automatically be detected. WD_UsbScanDevice() must be called again in order to detect the changes. However, since WinDriver USB drivers are user mode WIN32 applications, they can get a notification of insertion/removal. Windows sends all applications a WM_DEVICECHANGE message. Once the application receives this message it should call WD_UsbScanDevice() to check if the device was inserted/removed (this is only good for Windows). You should therefore be able to implement PnP device insertion/removal support with earlier versions of WinDriver as well, using the Win32 API. You can also send a GET_DESCRIPTOR request to the device (using WD_UsbTransfer() to verify if the device is connected. Please note that in order to handle the device after it has been disconnected, you must first call WD_UsbDeviceUnregister() to free the previous handle to the device, then re-scan the USB bus to locate the device (using WD_UsbDeviceScan()), get the device's configuration information (by calling WD_UsbGetConfiguration() and re-register the device by calling WD_UsbDeviceRegister().

Back to Top

WinDriver, Windows, USB, PnP, power management, Win32, API, version 5.20, version 6.0, WDU_Init, event_register, WD_UsbScanDevice