How to control power to a USB port of a macbook?
I had a USB LED light and I want to turn it on and off. When I connect the LED to the USB port of the macbook, it turns on, but the IO Registry Explorer cannot detect the LED light.
So I would like to directly control the power to the USB port. What is the easiest way to control (turn off/on) the power to a USB port on a mac? I prefer to use C or Objective-C.
As @unwind you should study first something about the USB and as he wrote USB it's a shared bus by several peripherals, so in order to communicate with the right one (in your case the LED device) you will need to properly identify it. The device will provide some information like PID, VID, serial number, and other stuff and this how your computer will know with whom is speaking it. So, the USB slave device itself must have a form of intelligence, not being just a dumb device. In other words it's not just cutting power to an USB hub, you can have several different devices attached and you have to select the proper one.
You need a microcontroller with an USB stack that should talk with the computer and later turn on or off the LED. A good starting point of course can be Arduino or I would recommend a different chip from Atmel: http://www.atmel.com/products/microcontrollers/8051architecture/usb_mcus.aspx and they have planty of examples, including the LED one. Of course you can find many others USB chips.
Seriously, go read up on USB. It's not a "dumb port" that you can control pin-by-pin from userspace, it's a shared bus.
You need more hardware to implement an actual USB device. Look at an Arduino perhaps, or any of the various more focused "I/O over USB" solutions.
链接地址: http://www.djcxy.com/p/14274.html