34

I would like to power cycle an USB device through software on Windows.

I am doing development on a small USB power microcontroller. This chip will revert to native behavior on a power cycle and allow a code download. Since my code will crash the device when things go wrong -- making it ignore all USB commands -- I have to physically unplug the device from the system.

I want to do development remotely, and not have to be physically present.

So far I have tried using "devcon" to disable portions of the USB stack. While this takes the hubs into D3 (should be powered off!), there is still power being supplied to the device.

Are there any preexisting solutions or SetupAPI tricks that might help?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

5 Answers5

4

Some USB hubs have the ability to turn power off to its downstream devices.

"Is it possible to power up ports on a USB hub from Ubuntu?" https://askubuntu.com/questions/149242/is-it-possible-to-power-up-ports-on-a-usb-hub-from-ubuntu Which points to some c source for hub-ctrl.c

See: http://www.gniibe.org/development/ac-power-control-by-USB-hub/index

I tested this on Ubuntu with a Dream-Cheeky USB LED unit, and it did seem to turn the power off - although when turned on again, the device had remembered (!) its LED on/off state ??? - This did not happen when I unplugged and repluged the USB lead to the LED...

It looks like someone has looked at compiling this for Windows, but I could not find the result, sorry.

Community
  • 1
  • 1
irdroid3
  • 71
  • 4
3

You could do with a hardware relay and controlling it via software: http://pintant.cat/2012/05/12/power-off-usb-device/ (of course, will use 2 USB ports :-) one for the device, one for the relay).

Carles
  • 109
  • 1
  • 1
3

Since it's for development/test instead of production, I'd recommend having a solid-state_relay as part of a second device and using that to cycle the power on the USB connection.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
devstuff
  • 8,277
  • 1
  • 27
  • 33
  • We use this method, just power relay instead electricity we cat Vbus cable and insert it in the power relay. I know that there is dedicated USB relays for exactly this purpose, but i assume that they are pricey. – Ilya Jan 01 '09 at 09:22
  • 1
    Would there already exist USB hubs that power off the devices when the host takes the hub into low power mode? Since this is in a lab environment, using custom hardware will require a uphill battle. –  Jan 01 '09 at 19:56
  • i posted the link as separated answer. – Ilya Jan 02 '09 at 08:35
2

There is a simple solution to this on Windows if you buy this external USB hub. It has an undocumented feature that cycles power to all connected USB devices whenever the hub is "enabled" in Windows Device Manager. You can do this manually:

  1. Run "Device Manager"
  2. Expand "Universal Serial Bus controllers"
  3. Open Properties for the appropriate "Generic USB Hub"
  4. Select the "Driver" tab
  5. Click the "Disable" button
  6. Click the "Enable" button. The hub will briefly disable power output to all 4 of its USB ports, and then enable it again.

You can also do this programmatically from any Windows application that is running with administrator priveledges. Here is an example in C#.

I have successfully used this technique to cycle power to USB devices that were "locked up". It sure beats physically unplugging devices, especially on remote or unmanned PCs.

Fanblade
  • 451
  • 2
  • 9
  • 3
    The referenced page [https://www.amazon.com/B00007AKAZ](https://www.amazon.com/B00007AKAZ) doesn't exist. – Jackdaw Nov 25 '21 at 03:48
0

Unfortunately, it's not possible on stock PCs.

USB host chipsets do not have the capability to fully power-down. There is some signaling that you can do in USB 2.0 or 3.0 to ask the device to go into a sleep-state, but the port will provide power even when the PC is turned off. (That's so devices like iPods and whatnot can still charge if needed.)

Mark Maxham
  • 1,501
  • 2
  • 13
  • 19
  • 2
    This is not correct and depend on specific hardware. There is an option to turn off/on power for root hub sometime you can't do it per port and only for all root hub ports. But you definitely can power down the port – Ilya Jan 01 '09 at 09:15