Control USB port's power?

Kristina Brooks picture Kristina Brooks · Dec 18, 2009 · Viewed 36.1k times · Source

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.

Answer

bluebrother picture bluebrother · Dec 18, 2009

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.