Does anybody know how to control USB pins on a certain USB port? I think it is definately possi开发者_运维知识库ble 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.
You can't simply toggle pins on a USB port. Period. USB is a serial protocol. The connector contains
- 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.
- 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.
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.
USB is not trivial, so I guess you'll have some problems (mis)using it. You would be /much/ better off (IMHO) with standard serial ports, which have been used for stuff like that for ages, with plenty of examples available. If you don't have serial port available on your target machine, you can use USB->Serial interface cable.
That being said, you'll probably want to take a look @: http://sourceforge.net/projects/libusbdotnet/
LP, Dejan
I think trying to switch the USB power on and off is not such a great way to do it: it is possible that your USB controller is able to do this, but it wouldn't be a "normal" thing to do.
Probably the easiest way is to use something like a FTDI FT245 USB->parallel chip. If you're just trying to flash some blinking lights, maybe go out and buy a standard USB -> parallel printer cable and interface to that ... you'd get 8 bits of output with very easy software control, and quite a lot more with only a bit of work.
Or go the whole hog and get a microcontroller with built in USB ... the possiblities are endless!
There is no software control over the power and ground pins of a USB port, at least on PC chipsets. That is handled in hardware by the USB controller. Look at getting a USB Parallel Port adapter if you want software control over TTL voltages.
I think that you are looking for an USB device. A simple charger could be made, by putting or boost regulator to bump up the 5v higher or regulator to drive to a lower charging voltage. Turning it on or off would require a USB device.
It may be possible to turn on and off power to the device by doing whatever happens when you "safely remove hardware" a USB device, but I'm not 100% sure this turns off the power, it may just send a signal to the device tell it it's disconnected, which makes it turn itself off.
The best bet for what you're trying to do is to build a USB device that actually communicates with the computer (possibly via a custom driver, but you can probably also use a standard driver like a HID device). You would have the computer send "on" or "off" (or anything else you can dream up) to your device, which would interpret the signals as you see fit (probably by turning on and off that LED you were talking about). This isn't as hard as it sounds. You can buy microcontrollers with USB interfaces on board, such as the Arduino, or some of the high-end PICs. Many of the manufacturers of these sorts of microcontrollers have documents available explaining how to do USB interfacing with them.
What you need is either a development board with programmable I/O pins (a.k.a. PIO) or a UART (RS232).
The easiest method is to connect the LED to the Clear To Send (CTS) and either Ground or VCC. The output on the CTS line will turn the LED on or off depending on whether the other end is connected to ground or not. The normal I/O pins could be used, but they are for serial data transmission in the UART. The UART usually builds an 8-bit character from these pins; but passes the RTS (Request To Send) and CTS values directly through.
When using a PIO, all you have to do is set a bit in a variable and write that variable to the address of the PIO set. You may also have to latch in the bits. Some PIO pins will remember the value until the next value is written (called latched), others remember the value as long as it is written out.
There is no way to do it for the actual power and ground pins. And you should probably read this portion of the Wikipedia USB article.
The question is controlling the amperage of USB most answers failed to put into account the varience of mA of USB and it's effect on volts.
Common USB 1.0 and 2.0 output equals 500 mA or 0.5 A. 500mA times 5 volts equals 2.5 watts of power.
1 A will give you the full 5 watts and USB 2.0 can be manipulated by ASUS Ai Charger to output 1.2 A or 1200 mA to give you a 6 watts out put.
精彩评论