author: https://github.com/BerndNW18 source: MicrosoftDocs/WSL#1868 (comment)
Hi, here is my complete solution on how to forward a USB port to WSL2, using the latest usbipd-win. Note that my use-case is connecting to an rplidar fromSlamtec, which uses a Silicon Labs CP210x USB-to-serial Interface board to connect to the actual Lidar device. ACTIVATING USB FORWARDING TO WSL2 Purpose: make USB to Serial Bridge accessible in WSL2 to test the RPLidar SDK build on WSL Linux (Ubuntu)
- Install usbipd-win on the Windows-host: https://github.com/dorssel/usbipd-win/releases
- Install USBIP tools and hardware-database in Linux (WSL) bernd@myOmen:~$ sudo apt install linux-tools-generic hwdata bernd@myOmen:~$ sudo update-alternatives --install /usr/local/bin/usbip usbip /usr/lib/linux-tools/*-generic/usbip 20
- Open Powershell (Administrator)
- PS C:\WINDOWS\system32> usbipd list Output: BUSID VID:PID DEVICE STATE 2-2 10c4:ea60 Silicon Labs CP210x USB to UART Bridge (COM3) Not shared 2-6 30c9:0069 HP Wide Vision HD Camera, Camera DFU Device Not shared 2-8 0461:4f03 USB Input Device Not shared 2-10 8087:0033 Intel(R) Wireless Bluetooth(R) Not shared 3-2 046d:081b Logi C310 HD WebCam Not shared 4-1 05a7:1020 Bose USB Audio, USB Input Device Not shared 4-2 046d:c52b Logitech USB Input Device, USB Input Device Not shared 4-3 04e8:329f Samsung CLP-320 Series Not shared
- We're interested in sharing the CP210x, so run PS C:\WINDOWS\system32> usbipd bind -b 2-2 where "2-2" is the value in BUSID column from usbipd list
- PS C:\WINDOWS\system32> usbipd list Output: BUSID VID:PID DEVICE STATE 2-2 10c4:ea60 Silicon Labs CP210x USB to UART Bridge (COM3) Shared 2-6 30c9:0069 HP Wide Vision HD Camera, Camera DFU Device Not shared "Shared" means ready to be forwarded, but still parked
- PS C:\WINDOWS\system32> usbipd attach --wsl --busid 2-2 #this will now forward the USB-device. You will hear the "unplug" chime in Windows. Output: usbipd: info: Using WSL distribution 'Ubuntu' to attach; the device will be available in all WSL 2 distributions. usbipd: info: Using IP address 172.26.144.1 to reach the host.
- PS C:\WINDOWS\system32> usbipd list #check if it worked Output: BUSID VID:PID DEVICE STATE 2-2 10c4:ea60 Silicon Labs CP210x USB to UART Bridge (COM3) Attached 2-6 30c9:0069 HP Wide Vision HD Camera, Camera DFU Device Not shared
- Open WSL
- bernd@myOmen:~$ lsusb Output: Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 003: ID 10c4:ea60 Silicon Labs CP210x UART Bridge Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bingo!
- bernd@myOmen:~$ ls -l /dev/ttyUSB* #check permissions crw-rw---- 1 root dialout 188, 0 Dec 8 11:30 /dev/ttyUSB0
- check if you're in the group (dialout): bernd@myOmen:~$ groups bernd adm dialout cdrom floppy sudo audio dip video plugdev netdev docker
- change to RPLidar SDK folder where the built demos are
- run one of the sdk-demos to check if the connection works: bernd@myOmen:~/rplidar/rplidar_sdk/output/Linux/Release$ ./simple_grabber --channel --serial /dev/ttyUSB0 256000 Output: SLAMTEC LIDAR S/N: E6BAED95C4E493CDA5E69EF0776A4B69 Version: SL_LIDAR_SDK_VERSION Firmware Ver: 1.32 Hardware Rev: 6 Lidar health status : OK. (errorcode: 0) waiting for data...
- [histogram data is shown] Do you want to see all the data? (y/n) n -> works. Yay! CLEANUP (un-forward USB)
- PS C:\WINDOWS\system32> usbipd detach --busid 2-2
- PS C:\WINDOWS\system32> usbipd list Connected: BUSID VID:PID DEVICE STATE 2-2 10c4:ea60 Silicon Labs CP210x USB to UART Bridge (COM3) Shared 2-6 30c9:0069 HP Wide Vision HD Camera, Camera DFU Device Not shared
- PS C:\WINDOWS\system32> usbipd unbind --busid 2-2
- PS C:\WINDOWS\system32> usbipd list Connected: BUSID VID:PID DEVICE STATE 2-2 10c4:ea60 Silicon Labs CP210x USB to UART Bridge (COM3) Not shared 2-6 30c9:0069 HP Wide Vision HD Camera, Camera DFU Device Not shared