How Do I Force Windows to Remove and Re-detect a USB Device?

Updated Nov 8, 2017

Reported In

Hardware

  • USB-6501
  • cDAQ-9132
  • cDAQ-9133
  • cDAQ-9138
  • cDAQ-9139
  • cDAQ-9135

Driver

  • NI-DAQmx

Other

windows

Issue Details

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 re-detect 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 re-detected by the computer and thus you will not be able to communicate with it. 

Follow the instructions below to re-detect 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 here.  

  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* 

     


    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.

  8. 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.

  9. 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.

WAS THIS ARTICLE HELPFUL?

Not Helpful