LoginSignup
5
5

More than 3 years have passed since last update.

USB per-port power switching

Last updated at Posted at 2019-10-23

USBハブのポートには5vが給電されているが,ポート毎にon/offできる機能(ppps:per-port power switching)がサポートされているものがある。但し,全てのUSBハブでサポートされている訳ではないので注意が必要。
この機能を利用すると,USBハブに接続している機器の電源をプログラムから制御できるようになる。

コマンド

Linuxでは,pppsを制御するためのプログラムがいくつか公開されている。

Debianならaptで導入可能なはず。以降の例はRaspbian Buster上で確認。

使い方

$ uhubctl -h
uhubctl 2.0.0: utility to control USB port power for smart hubs.
Usage: uhubctl [options]
Without options, show status for all smart hubs.

Options [defaults in brackets]:
--action,   -a - action to off/on/cycle (0/1/2) for affected ports.
--ports,    -p - ports to operate on    [all hub ports].
--loc,      -l - limit hub by location  [all smart hubs].
--vendor,   -n - limit hub by vendor id [any] (partial ok).
--delay,    -d - delay for cycle action [2 sec].
--repeat,   -r - repeat power off count [1] (some devices need it to turn off).
--exact,    -e - exact location (no USB3 duality handling).
--reset,    -R - reset hub after each power-on action, causing all devices to reassociate.
--wait,     -w - wait before repeat power off [20 ms].
--version,  -v - print program version.
--help,     -h - print this text.

Send bugs and requests to: https://github.com/mvp/uhubctl

USB hubの確認

sudo uhubctl
Current status for hub 1-1.5 [05ac:1005 Apple Inc. Keyboard Hub 000000000000, USB 2.00, 3 ports]
  Port 1: 0100 power
  Port 2: 0303 power lowspeed enable connect [05ac:021d Apple Inc. Apple Keyboard]
  Port 3: 0100 power
Current status for hub 1-1.2 [05e3:0610 GenesysLogic USB2.0 Hub, USB 2.00, 4 ports]
  Port 1: 0100 power
  Port 2: 0100 power
  Port 3: 0100 power
  Port 4: 0100 power
Current status for hub 1-1 [0424:9514, USB 2.00, 5 ports]
  Port 1: 0503 power highspeed enable connect [0424:ec00]
  Port 2: 0507 power highspeed suspend enable connect [05e3:0610 GenesysLogic USB2.0 Hub, USB 2.00, 4 ports]
  Port 3: 0303 power lowspeed enable connect [04d9:a052 Holtek USB-zyTemp 1.40]
  Port 4: 0303 power lowspeed enable connect [046d:c018 Logitech USB Optical Mouse]
  Port 5: 0503 power highspeed enable connect [05ac:1005 Apple Inc. Keyboard Hub 000000000000, USB 2.00, 3 ports]

これで,1-1.5にAppleのキーボード(USB hub付き)と1-1.2にもppps対応のハブ(実際はbuffalo BSH4A05UBK)が接続されていることがわかる。

portへの給電off

1-1.2として認識されているUSB hubのポート3をoffにする。
sudo uhubctl -l 1-1.2 -p 3 -a 0

pppsをサポートするUSBハブ

動作確認したUSBハブ

メーカー 製品 ポート USBバージョン VID:PID
buffalo BSH4A05U3BK 4 3 05e3:0610
Apple 3 2? 05ac:1005
Elecom U2H-J4SLWH 4 2 0409:0059

非対応らしいUSBハブ

メーカー 製品 ポート USBバージョン VID:PID
Anker A7513 7 3.0 1c04:2074

動作確認は,Rasbianに手元にあったUSBハブを接続して確認していますが,結果を保証するものではありません。

応用

USB連動タップは,USBポートに5vが給電されているかどうかで電源のon/offを制御している。pppsでUSBポートへの給電を制御することで,100vの機器もon/off制御できるようになる。

デモ動画

uhubctlでUSBハブに接続した機器をon/offする様子のデモ動画です。
uhubctl-demo.gif

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5