Academic Company Events Community Support Solutions Products & Services Contact NI MyNI
80 ratings:
 3.64 out of 5     Rate this Document

How Do I Force Windows to Remove and Redetect a USB Device?



Hardware: Digital I/O (DIO)>>Static>>USB-6501, CompactDAQ, Multifunction DAQ (MIO)>>Portable

Problem:
My USB device will occasionally lose connection to the computer, and I have to disconnect and then reconnect it before it will work.  Why does this happen, and how can I get Windows to redetect the device, without having to physically disconnect the device?

Solution:
This behavior occurs when the device loses power, but the computer does not.  For example, often when a computer goes into standby or power-save mode it will often shut down power to the USB ports.  Also, this can happen when a computer returns from having been hibernated.  In either case, the device is not redetected by the computer and thus you will not be able to communicate with it.  Follow the instructions below to redetect the device within Windows when this happens:
  1. Install the DevCon utility from Microsoft.  The DevCon utility is a command-line utility that acts as an alternative to Device Manager. Using DevCon, you can enable, disable, restart, update, remove, and query individual devices or groups of devices.  You can download DevCon from http://support.microsoft.com/kb/311272.

    If you are running Windows 7, it is recommended that you download DevCon as part of the Windows Driver Kit (WDK) 8.0. This can be downloaded from
    http://msdn.microsoft.com/en-us/library/windows/hardware/ff544707(v=vs.85).aspx.
     
  2. Open the Windows Device Manager by going to Start » Run, type in devmgmt.msc, and then click the OK button.
     
     
  3. You will now need to determine which USB hub (port) the troubled device is connected to. To do this, expand the Universal Serial Bus controllers group at the bottom of the list.

     
  4. In sequence, double click on every USB Root Hub entry and click the Power tab to see if your device is listed.

     
  5. When you have found the hub that has your device listed, click the Details tab and select Device Instance Id from the drop down menu. If you are running Windows 7, select Device Instance Path instead of Device Instance Id. Record the name shown in the list between the first and second \ sign, for example ROOT_HUB20.

     
  6. Next, start a Command Prompt by going to Start » Run, type in cmd, and then click the OK button.
     
  7. In the Command Prompt window, first change directory to the folder that contains the devcon.exe file that you downloaded. If you are using a 64-bit operating system, you need to ensure you are calling the 64-bit version of devcon.exe.  Once you have navigated to the proper directory, type in  the following command followed by enter, replacing ROOT_HUB20 with what you recorded in step 4.

         devcon restart *ROOT_HUB20*
        

     
  8. Note: If your user interface devices such as a mouse or keyboard, or any other USB devices such as a USB Network Adapter are on the same root hub as the USB device you are trying to re-detect, then you will lose connectivity to your mouse or keyboard while the restart is performed.

  9. Now, Windows will remove and re-detect the hub and any USB devices attached to it, re-enabling them in the process. If this does not work, you probably selected the wrong hub in step 4.  Repeat steps 3 - 6 until the restart is successful.

  10. Once you know which root hub your device is connected to, you can implement this solution programatically in LabVIEW using the System Exec VI, which allows you to pass commands to the command prompt. The System Exec VI can be found in the Libraries and Executables Palette.




Related Links:
External Link: The DevCon command-line utility functions as an alternative to Device Manager
External Link: Windows Device Console (Devcon.exe)
KnowledgeBase 3D8J0A3U: USB-92xx Devices May Not Wake from Hibernation

Attachments:





Report Date: 12/04/2007
Last Updated: 05/16/2014
Document ID: 4G3CHJPO

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit