Author Topic: source code to control HUB  (Read 7530 times)

Jim Davis

  • Member
  • ***
  • Posts: 3
source code to control HUB
« on: January 11, 2014, 03:09:05 pm »
Can anyone suggest sample source code to turn an external HUB port ON/OFF? I'll incorporate the relevant code into my project (either C# or VB). I've tried to use devcon but am missing (I think) a command to control the HUB.

Details: I am trying to eliminate a custom driver (XP through Windows 8) and reduce the current to less than 200mA (laptop limit using a Y cable). The external HUB in my apparatus is Gensys Logic GL850G (28 pin) to which is hardwired a Logitech webcam. There is an 8051 (Silicon Labs C8051F33 and for odd reasons a Prolific PL2303HXD) merely to turn the lights ON/OFF (800 mA) and battery charger ON/OFF.
I wish to eliminate the 8051 and turn the lights ON whenever the webcam is ON and turn the charger ON when the webcam and lights are OFF. The charger current and HUB will be limited to less than 200mA. The original design (not by me) allowed upto 500mA.


Thank you for any guidance.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: source code to control HUB
« Reply #1 on: January 11, 2014, 09:21:38 pm »
As I understand it, you have a laptop that connects to an external hub. One port on the external hub is hardwired to a webcam. Another port on the hub connects to a Prolific USB/serial bridge chip that controls a battery charger and some lights. You want to limit the current from the laptop to 200 mA.

Bus-powered USB 2.0 hubs can provide at most 100 mA/port so one way to limit the current to 200 mA  is to use a 2-port, bus-powered hub. (The hub itself will use a small amount of additional current.)

How to limit the current the other devices require is another question.

Are the lights bus-powered or self-powered?

Where does the (illegal) Y cable connect?

What controls the charger current?


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: source code to control HUB
« Reply #2 on: January 12, 2014, 11:18:08 am »
If you want to avoid installing a custom driver, a generic HID-class device can perform basic control functions from a vendor-provided application.

Generally, the way to reduce bus current is to design the devices and the software that controls them so they draw the desired amount of current, rather than enabling and disabling hub ports.


Jim Davis

  • Member
  • ***
  • Posts: 3
Re: source code to control HUB
« Reply #3 on: January 12, 2014, 03:36:57 pm »
The charger current will be trimmed (resistor choice for an LTC4060) by me to limit the current to, say 100mA.
The Y cable connects to 2 ports on the laptop (the same type Y cable used to bus power an external hard drive) the single end of the cable plugs to my device.
The lights draw 800mA, so are powered from a rechargeable battery in the device.
The lights and charger are currently controlled by an 8051 with RS232 to a Prolific serial to USB. The driver for the Prolific chip is problematic (especially Windows 7 & 8) for some of my clients customers as well as "lots" of current to run the 8051 and Prolific.

Jan is correct a better design would design devices to the draw only the desired amount of current. I am stuck trying to fix with someone else's design. The HUB and webcam (both inside the device) draw just under 200mA. My customer now wants the device work with laptops too. Hence my desire to turn off the webcam (and lights) and use the available current to charge the batteries.

thanks for any help.  jim...

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: source code to control HUB
« Reply #4 on: January 12, 2014, 09:26:18 pm »

Jim Davis

  • Member
  • ***
  • Posts: 3
Re: source code to control HUB
« Reply #5 on: January 15, 2014, 09:46:41 am »
The links Jan suggested were informative.  However the devcon program from Microsoft seems to require "silent" reboots. Reboots are unacceptable.
Since the HUB has registers to control the port power and light, I am thinking of modifying USBView or USBHIDIO2 (which I have previously used successfully, thanks Jan).
Any suggestions for the preferred program to start with?

thanks

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: source code to control HUB
« Reply #6 on: January 15, 2014, 09:57:29 am »
It's possible that those silent reboots are necessary.

Note that the IOCTLs to enable and disable ports have been deprecated:

http://msdn.microsoft.com/en-us/library/windows/hardware/ff537421%28v=vs.85%29.aspx

bpaddock

  • Frequent Contributor
  • ****
  • Posts: 66
Re: source code to control HUB
« Reply #7 on: January 16, 2014, 08:39:08 am »
It's possible that those silent reboots are necessary.

Note that the IOCTLs to enable and disable ports have been deprecated:

http://msdn.microsoft.com/en-us/library/windows/hardware/ff537421%28v=vs.85%29.aspx

Here is the source to the current version of DevCon which might be of some use:

http://code.msdn.microsoft.com/windowshardware/DevCon-Sample-4e95d71c