Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control USB port's power? [closed]

Tags:

c++

c#

usb

drivers

Does anybody know how to control USB pins on a certain USB port? I think it is definately possible in assembler but what about C++ or C#?

I want to be able to use USB battery as a power supply for an LED or something like that. So then a program would power it on and power it off making it flash.

I know it sounds pointless but I need to do it for something awesome.

I also know that it might require a custom driver.

like image 527
Kristina Brooks Avatar asked Dec 17 '09 23:12

Kristina Brooks


2 Answers

You can't simply toggle pins on a USB port. Period. USB is a serial protocol. The connector contains

  1. Power. The Host can control the power lines as it can cut the power in case of overload. This is something done by the USB host driver, which means the driver of the host adapter in the PC. This does not mean any custom device driver you might need for hardware that doesn't use any of the device classes the OS already ships drivers.
  2. Data. The data is sent via a serial protocol, so there is no way to control those pins if you're using USB.

If you want to get some IO ports you need more logic. You need at least something that follows the USB protocol, which means some kind of microcontroller (or a special USB device controller like the FTDI USB controllers. The FT232 and FT245 are especially nice to work with). For a low-end microcontroller based solution the V-USB driver for AVR controllers might be interesting.

For easy bit-banging IO pins on the PC use the parallel port. USB is really not made nor suited for that.

like image 56
bluebrother Avatar answered Sep 23 '22 02:09

bluebrother


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

USB 2.0 nominally supports per-port power switching:

Hub Descriptor: [...]   wHubCharacteristic 0x0089     Per-port power switching [...] 

Sadly, the author reports that while may hubs' firmware claims to support this, the manufacturers have cut corners on the circuit board.

like image 30
android.weasel Avatar answered Sep 23 '22 02:09

android.weasel