0

What I want to write is an application that would be able to access my USB port.

To control when to charge my phone and when not to. And perhaps with time I would like to extend the application to control light bulbs, fans and the television in my room.

I want to learn how to work this out rather than just copy some line of codes and paste. I wish for a quick and very simplified tutorial on this, I would be highly grateful (small language please, You all know am still learning :-)).

The exact job I want to achieve is just to make the port send out power when needed. That is it should be switched off and on using codes if possible.

George
  • 3,757
  • 9
  • 51
  • 86

1 Answers1

2

It isn't possible to change the power status of a USB port from User mode code. It's not a .NET limitation, no user application can change the power status of a USB port. Actually, I think that the power state is controlled by the chipset itself and you can't turn it off without using a specialized chipset.

Besides, if your device short-circuited, you could burn your chipset and your motherboard.

The only (safe) solution is to use an external device that will control a relay to turn power on or off for your devices.

There are multiple answers to similar questions, eg Windows- Power off a USB device in Software

A good option is to use an external device like Arduino (or Netduino), .NET Gadgeteer or any number of external boards. Prices and capabilities vary of course.

If you want to build the device yourself, you can find numerous USB relays with a simple Google search

EDIT

Regarding serial ports, there is almost no relation at all between the two port types. Serial ports are not designed to provide power. You can use tricks to use a pin's voltage to power some external device, although this will lead to problems because there is not enough current to power most devices. Burning the chipset is another likely outcome.

A USB port on the other hand, is explicitly designed to provide power through specific wires which can't be controlled normally. This is why you can charge your phone from a desktop's USB port even if the machine has shut down.

EDIT 2: Sleep-and-charge ports As Ben Voigt noted, not all USB ports allow charging while shutdown.

There are multiple port types that support charging. Charging ports provide more current than plain ports but shut down when the computer is switched off. Sleep-and-charge ports on the other hand can provide power even when the computer is off.

Community
  • 1
  • 1
Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • hmm, but what about serial ports, If I am not mistaking, that's the way they work. They switch off and on pins – George Jul 12 '13 at 11:55
  • There is almost no relation at all between the two port types. Power in the USB port is not a separate controllable pin, which is why you can charge your phone from a desktop's USB port even if the machine has shut down. – Panagiotis Kanavos Jul 12 '13 at 12:02
  • @PanagiotisKanavos: You can't charge from a USB port which is turned off. Some machines have special circuitry to supply the USB power through a different path when the main power is off, but this is not part of the USB specification, is the exception rather than the rule, and usually this function IS controllable. – Ben Voigt Jul 12 '13 at 12:20
  • @BenVoigt, not quite. There are many port types and Sleep-and-charge ports are just one type – Panagiotis Kanavos Jul 12 '13 at 13:13
  • I wouldn't really call that a "port type". Port types are host, device, or OTG. Perhaps a "power circuit type". – Ben Voigt Jul 12 '13 at 13:31
  • Well, that's what Wikipedia calls them. The linked "Battery Charging Specification" doesn't call them anything. Guess they didn't care so much about wording – Panagiotis Kanavos Jul 12 '13 at 14:06