Disable USB powered light from command line?

6

2

I have a nice little USB light which has no off switch, it is 'on' for the duration of being plugged in.

My question is, is there a way of disabling the USB port so as to turn off the light while it is still plugged in? Preferably, this could be done from the command line, but if it's possible at all that would be really cool regardless. I use Mac and Linux, but am interested to learn if this is possible in any OS, or if physical hardware prevents usage like this.

Jeff Welling

Posted 2011-07-24T13:38:26.107

Reputation: 555

I'm not sure what you mean... do you mean hard drive? How would the hard drive impact the ability to toggle power to the USB port? – Jeff Welling – 2011-07-24T14:04:35.830

1If you want to disable the whole thing, use a device manager type thing (dont know what it is in mc or linux). If you just want to disable the light, it depends o the hardware (USB drive) involved. – soandos – 2011-07-24T14:07:22.980

I only know how to do this in Windows. Are you interested in the Windows way? – Larssend – 2011-07-24T16:13:03.497

Well I don't think I'd have included the sentence at the end of the question otherwise.. ;) – Jeff Welling – 2011-07-24T22:41:10.477

If it shows up in your dev/ folder, try unmounting the device (e.g. unmount /dev/usbdev0 or something similar. – Breakthrough – 2011-07-25T00:27:50.570

Answers

5

In most cases, USB accessories like fans and lights aren't real USB devices - they just want a little bit of 5v power.

The way USB works for real devices is that they get a little bit of power to start, enough for them to turn on. Then they enumerate with the USB controller and request more power.

Since these fake USB devices aren't actually talking to the computer at all, the only way to turn it off would be to completely unpower that USB port, which as far as I know there is not usually a way to do in software.

Grant

Posted 2011-07-24T13:38:26.107

Reputation: 1 744

1Actually the USB 2.0 standard specifies that USB hubs should support either Ganged Power Switching, or even Per Port Switching. Most USB 2.0 chipsets seems to support this. Except that hardly any USB hubs actually have it wired up. There are a few that has but I cannot find any definite list. – Joakim Söderberg – 2014-11-25T13:58:05.290

3

I haven't actually tried this myself, but from the research I have done on the topic (to accomplish exactly the same thing as you), you will need:

  • A USB hub which supports "per-port power switching" - not many support this
  • A utility to actually toggle the power

Take a look at http://www.gniibe.org/development/ac-power-control-by-USB-hub/index, he is doing similar things, and includes some background on the topic, a list of supported hubs as well as the C source code to build the utility.

I couldn't find any of the USB hubs he had mentioned in the US, and after getting in touch with me confirmed that the D-Link DUB-H7 will work - you can get it on Amazon for example.

I haven't yet found a way to do this on Windows, but it looks like you're mostly interest in Linux anyways.

Lucky Luke

Posted 2011-07-24T13:38:26.107

Reputation: 150

I have a D-Link DUB-H4, which doesn't (afaik) support switching, though it presents as a 0451:2046 Texas Instruments, Inc. TUSB2046 Hub and the datasheet for the TUSB2046 does specify the chip is capable of per-port power control. That's not the same as the HUB supporting it though. Also, the link at gniibe.org is no longer active, I have mirrored the .c code at https://github.com/sfinktah/ac-power-control-by-USB-hub - original article at https://web.archive.org/web/20150424033015/http://www.gniibe.org/development/ac-power-control-by-USB-hub/index.html

– Orwellophile – 2019-09-01T12:35:19.643

edit: The D-Link DUB-H4 does support per-port power switching. – Orwellophile – 2019-09-02T08:48:33.960

Awesome answer! The only reason I accepted the other answer was because I was specifically interested in the possibility of disabling it purely from software without additional hardware, but I love how far you took this, it sounds like there's a lot of potential with that DLink DUB-H7 device hehe. Has lots of weekend-project potential :) – Jeff Welling – 2012-03-27T16:39:44.343

2

7-port USB hub D-Link DUB_H7 revision 2 (black) does NOT have Per-port power switching, it only supports Ganged power switching.

#lsusb -v

output shows twice a 4-port hub, here is the output for Hub Descriptor:

Hub Descriptor:
  bLength               9
  bDescriptorType      41
  nNbrPorts             4
  wHubCharacteristic 0x00e0
    Ganged power switching
    Ganged overcurrent protection
    TT think time 32 FS bits
    Port indicators
  bPwrOn2PwrGood       50 * 2 milli seconds
  bHubContrCurrent    100 milli Ampere
  DeviceRemovable    0x00
  PortPwrCtrlMask    0xff
 Hub Port Status:
   Port 1: 0000.0100 power
   Port 2: 0000.0100 power
   Port 3: 0000.0100 power
   Port 4: 0000.0100 power

darkvibez

Posted 2011-07-24T13:38:26.107

Reputation: 21

1So how do I turn off power to all ports in Linux? – Joakim Söderberg – 2014-11-25T09:38:46.110

1

Try using http://www.nirsoft.net/utils/usbdeview.zip. This executable displays all USB devices attached to your computer and allows you to disconnect them individually as required.

As noted from the read me:

USBDeview is a small utility that lists all USB devices that currently connected to your computer, as well as all USB devices that you previously used. For each USB device, extended information is displayed: Device name/description, device type, serial number (for mass storage devices), the date/time that device was added, VendorID, ProductID, and more... USBDeview also allows you to uninstall USB devices that you previously used, and disconnect USB devices that are currently connected to your computer. You can also use USBDeview on a remote computer, as long as you login to that computer with admin user.

Sunil

Posted 2011-07-24T13:38:26.107

Reputation: 19

2You should mention this program is for use on Windows. – Joakim Söderberg – 2014-11-25T09:38:12.923