0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【WSL2対応】UbuntuでUSBカメラなどのUSBデバイスを制御する方法(usbipd活用)

Posted at

はじめに

Windowsユーザーですが普段開発はWSL Ubuntuを使っています。Linux環境でUSBカメラを制御する方法をまとめます。

前提

  • Windows 11 を使用
  • WSL2 に Ubuntu をインストール済み

手順

wslにusbデバイスをアタッチする方法を示します。

usbipdのインストール

まず、管理者権限でPowerShellを開き、以下のコマンドを打ちこみます。

winget install usbipd

そして、WSL側では以下のコマンドを打ちこみます。

sudo apt install linux-tools-generic hwdata

BUSID

次に以下のコマンドを打ちこみ、Ubuntuで制御したいデバイスのBUSIDを確認します。

usbipd list

自分の場合は以下のようになりました。

BUSID  VID:PID    DEVICE                                                        STATE
1-1    046d:c52b  Logitech USB Input Device, USB 入力デバイス                   Not shared
1-2    046d:c52b  Logitech USB Input Device, USB 入力デバイス                   Not shared
1-6    056e:701b  ELECOM 5MP Webcam, Webcam internal mic                       Not shared
1-19   0411:0311  USB 接続 SCSI (UAS) マス ストレージ デバイス                   Not shared
3-3    2357:0604  TP-Link Bluetooth 5.4 USB Adapter                            Not shared

今回はWebcamが対象であるため、BUSID:1-6をメモします。

バインド

以下のコマンドを打ちこみ、対象のデバイスを共有可能な状態にします。

usbipd bind --usbid 1-6

このコマンドは管理者権限がないと実行できないので注意してください。

アタッチ

そして以下のコマンドでUbuntuに対象デバイスをアタッチして共有完了です。

usbipd attach --busid 1-6 --wsl Ubuntu

確認

WSL側で以下のコマンドを打ちデバイス情報が表示されれば成功です。

lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 056e:701b Elecom Co., Ltd ELECOM 5MP Webcam
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

おわりに

以前と異なり、USBデバイスを bind で「共有可能な状態」にしてからでないと attach できなくなっています。この記事が同じような環境で困っている方の参考になれば幸いです。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?