-1
\$\begingroup\$

(Edited and expanded from original question for clarity)

USB interfaces as a means of controlling external hardware from a desktop or laptop computer are ubiquitous; many thousands of hardware models are available, ranging in price from 10-1 to 106 USD. It is reasonable to require that the +5V DC voltage line be able to be switched off from the host computer, but this is by no means guaranteed across every mainstream PC/laptop running every widespread OS.

I am looking to have a true cross-platform solution to be able to selectively power USB ports down and up from software, for totally arbitrary lengths of time. This is not because I am prototyping or breadboarding, and nor is this my first foray into electronics making an LED blink on and off; I require a long-term reliable solution.

I am looking for an efficient solution which minimizes:

  • Cost
  • Implementation time
  • Other general hassles, such as volume or amount of trailing wires

Based upon comments, I have thusfar ranked my options as follows:

Option 1

Buy a dedicated USB splitter, with fully cross-platform proprietary software, such as the Yepkit YKUSH hub:

YKUSH

  • $42
  • Negligble software compilation time + some time to "box up"
  • Compact and neat

Option 2

Buy a programmable USB hub:

programmable hub

  • $300
  • Small amount of time to implement command-line software control
  • Professionally boxed

At the moment, I would be tempted to get a 4-way USB hub, splice its power lines through a separate arduino-controlled relay (as I have an arduino that need never be unpowered).

Option 3

Buy a fairly off-the shelf hub compatible with uhubctl. Then either run Linux or program a way to make it work in Windows. A VM would also be a headache, because programs in Windows will have trouble interfacing with Linux programs inside the VM.

  • ~$20
  • Long time to implement cross-platform software
  • Professional USB hub

Option 4

Buy a USB hub and a Normally Closed 5V relay, controlled by e.g. an arduino to cut power to the USB hub as required:

arduino relay

  • ~$25
  • Long time to solder and tidy connections + short time to implement switching in arduino code
  • Fairy ugly due to splicing wires

(Surprisingly not suggested in responses given that this is an Electrical Engineering site)

\$\endgroup\$
  • 3
    \$\begingroup\$ Is this an XY Problem? \$\endgroup\$ – Jeroen3 Aug 31 '18 at 17:30
  • 1
    \$\begingroup\$ @Ale..chenski: no, it's not. It is perfectly understandable desire to be able to have software switching for something that can be done manually by unplugging and replugging USB cable. It's a shame that many hardware manufacturers decided to not implement that part of USB spec, and software vendors like Microsoft make it impossible to use even if hardware supports it. \$\endgroup\$ – mvp Sep 1 '18 at 9:16
  • 1
    \$\begingroup\$ @mvp Exactly. If I could accept that comment as an answer, I would. \$\endgroup\$ – Valentin Aslanyan Sep 1 '18 at 11:27
  • 1
    \$\begingroup\$ @Ale..chenski Ah yes, appeal to authority... 200 cardinals judged that the Earth is flat, so Giordano Bruno was burned at the stake. 200 IoT developers found it reasonable that a lightbulb has to receive firmware updates for 1 hour, so here we are... \$\endgroup\$ – Valentin Aslanyan Sep 3 '18 at 20:03
  • 2
    \$\begingroup\$ @ValentinAslanyan So far you haven't given any reason for disconnecting power to USB devices. "understandable desire" and "reasonable to require" are not reasons, they are opinions. To say that "authorities" made arbitrary unfounded decision while your opinion has all the merits is rather arrogant. Unless you can provide any real reason to supplement your case this discussion will lead nowhere. \$\endgroup\$ – Maple Sep 3 '18 at 20:16
2
\$\begingroup\$

On Windows, you can simulate disconnect event using utility devcon provided by Microsoft. Use it as outlined in this answer. However, it doesn't necessarily mean that power will be turned off.

On other platforms (Linux, Mac) you can use my utility uhubctl. It will work and actually turn power off per each port selectively for any USB hub that supports per port power control (check compatibility list for tested devices). Good news is that uhubctl supports USB 3 and many USB 3 hubs properly support per port power control.

\$\endgroup\$
  • 1
    \$\begingroup\$ It's not only the hub chip that needs support, the control pins must actually connect to FETs/switches on the board \$\endgroup\$ – Chris Stratton Aug 31 '18 at 13:18
  • \$\begingroup\$ Certainly. This is why uhubctl has supported devices list. \$\endgroup\$ – mvp Aug 31 '18 at 14:43
  • 1
    \$\begingroup\$ Uhubctl works like a champ in the project I'm working on, a very useful tool. \$\endgroup\$ – Wossname Aug 31 '18 at 16:48
  • \$\begingroup\$ This is not a "simulation" of port disconnect. Port disconnect is a logical state of any USB port, per USB specifications. Disabling a USB port turns it into non-transmitting port, and the corresponding software instance gets removed. Enabling the port can be done only by issuing a USB port reset, and following with new, fresh enumeration. This function can be performed regardless of whether the port has controllable VBUS power or not. The OP failed to explain why he needs to toggle VBUS power (which is the simplest external way to disable and force re-enumeration of a USB port). \$\endgroup\$ – Ale..chenski Dec 22 '18 at 5:37
  • \$\begingroup\$ @Ale..chenski: read this list of examples why people needed this functionality: github.com/mvp/uhubctl/blob/master/… \$\endgroup\$ – mvp Dec 22 '18 at 15:27
2
\$\begingroup\$

It's certainly possible in some cases, but it depends on the hardware you're running.

Some USB chipsets allow "per-port power control" (the name of this feature seems to change from one manufacturer to another). Your mileage may vary because this feature appears to be an optional part of the USB3 spec.

There is an unofficial and probably incomplete list of chips that support this feature here: https://github.com/mvp/uhubctl/blob/master/README.md

Uhubctl is a Linux based program that lets you turn on and off USB ports on compatible chipsets. Works for individual ports on PCIe-to-USB adaptor cards too. It can be run from the commandline or a shell script and you just nominate which port you want to turn on or off.

If your hardware contains one of the supported chips (and the manufacturer chose to implement it on your motherboard / PCIe card) then that is one option that works for me natively under Linux.

\$\endgroup\$
  • \$\begingroup\$ Thanks, this is certainly an option. While I am typing this reply on Linux, I need a Windows solution. I would have to buy one of the listed (and, simultaneously still stocked) hubs, then adapt the C code to Winapi, or preferrably to python... so will take quite some time. \$\endgroup\$ – Valentin Aslanyan Aug 30 '18 at 10:50
  • \$\begingroup\$ Do you have the option to run a Windows virtual machine on top of a Linux host PC? If so then the Linux software side takes care of itself and all you need do from the Windows side is send a TCP packet to the host machine (over the local LAN) to tell the host to powercycle the port(s). But yes, finding hardware that works might be tricky. I had to do it the hard way and build one of these chips into my project! \$\endgroup\$ – Wossname Aug 30 '18 at 10:58
  • \$\begingroup\$ Are you suggesting running a VM just to be able to unpower USB ports? :) That is in no way an efficient solution. \$\endgroup\$ – Valentin Aslanyan Aug 30 '18 at 11:13
  • 2
    \$\begingroup\$ Yes, uhubctl only needs libusb to compile and work, and it does compile on Windows. But on Windows, libusb is using winusb.sys, which doesn't support required USB control message directly to the hub. More details in uhubctl docs \$\endgroup\$ – mvp Aug 30 '18 at 16:57
  • 1
    \$\begingroup\$ Many hub chips have output pins to control power switches but that doesn't mean the board has those switches. \$\endgroup\$ – Chris Stratton Aug 31 '18 at 13:11
2
\$\begingroup\$

First, not all desktop PC have individual port power control, actually very few have it. You will have a better luck with external hubs, although it will be also a challenge.

Second, USB port power, connect, reset, enable etc. port function are integrated steps of USB protocol, and are implemented at kernel level. Enabling port power is the first standard function for any root (or normal) hub port, and turning it off is not in the standard USB protocol. Therefore you would need the usb driver source code to implement new custom calls and functions. If this is theoretically available for Linux/Android, it is highly problematic under Windows.

However, if this is for testing of individual basic USB functions under manual control and no "normal" USB class functionality is needed/required, there is a stand-alone software package called "USB3CV" - command verifier, available from USB.ORG, which replaces the standard Windows USB stack and allows to execute individual port commands via graphic interface. This again assumes that the hardware (USB hub) has individual port power controllers, which is hard to get in first place.

If you need a normal USB stack functionality but want to exercise systematic power-off (VBUS off/disconnect) of connected USB devices, your best option is to get a hub with individual port power control, and hack the control wires to your Arduino controller.

Again, it all depends what is the purpose of your exercise, there might be some caveats in the disconnect process.

ADDITION: In classic USB environment with Type-A ports the individual port power switching is OPTIONAL and should't be generally expected from on-the-shelf products. However, for all devices with Type-C downstream connectors the individual port power control is MANDATORY by USB 3.2 specifications. Therefore, Type-C is the way to go (into future).

\$\endgroup\$
  • \$\begingroup\$ +1 nice tip about the USB3CV tools. \$\endgroup\$ – Wossname Aug 31 '18 at 16:51

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.