Skip to content

Commit 34c727f

Browse files
committed
Add wsl2 devices support
1 parent 901105b commit 34c727f

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,30 @@ ZPC> zwave_add_node
9191
(...)
9292
```
9393

94+
### WSL2: Mount devices from windows
95+
96+
You can use [./scripts/wslusb.ps1].
97+
98+
Start by installing the usbipd service as described at: https://learn.microsoft.com/en-us/windows/wsl/connect-usb
99+
100+
```sh
101+
# You can list devices using:
102+
103+
(Powershell)$ ./wslusb.ps1 -List
104+
105+
# Get the BUSID of the device you want to mount
106+
107+
(Powershell)$ ./wslusb.ps1 -Attach <busid>
108+
109+
# Check that the device is correctly mounted into WSL2
110+
111+
(WSL2)$ lsusb # you should see your device here
112+
113+
# Detach the device with
114+
115+
(Powershell)$ ./wslusb.ps1 -Detach <busid>
116+
```
117+
94118
### Docker build
95119

96120
The fastest (less than 20min) way to build z-wave-protocol-controller from scratch

scripts/wslusb.ps1

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# This script can be used to attach and detach a device to your WSL2 distribution
2+
3+
[CmdletBinding()]
4+
param(
5+
[Parameter(Mandatory= $false, HelpMessage = "Busid of the device you want to bind")]
6+
[Alias("b")]
7+
[string]$Busid,
8+
9+
[Switch]$Attach,
10+
[Switch]$Detach,
11+
[Switch]$List
12+
)
13+
14+
# Unblock the script file
15+
Unblock-File -Path $MyInvocation.MyCommand.Path
16+
17+
Function List-devices {
18+
usbipd list
19+
}
20+
21+
Function Attach-device {
22+
param(
23+
[string]$Busid
24+
)
25+
Write-Host "Attaching device $Busid"
26+
usbipd bind --busid $Busid --force
27+
usbipd attach --wsl --busid $Busid --auto-attach
28+
}
29+
30+
Function Detach-device {
31+
param(
32+
[string]$Busid
33+
)
34+
Write-Host "Detaching device $Busid"
35+
usbipd detach --busid $Busid
36+
usbipd unbind --busid $Busid
37+
}
38+
39+
if ($Attach -or $Detach -or $List)
40+
{
41+
if($List)
42+
{
43+
List-devices
44+
}
45+
if ($Detach)
46+
{
47+
if ($Busid)
48+
{
49+
Detach-device -Busid $Busid
50+
}
51+
else
52+
{
53+
Write-Host "Busid not specified"
54+
}
55+
}
56+
if ($Attach)
57+
{
58+
if ($Busid)
59+
{
60+
Attach-device -Busid $Busid
61+
}
62+
else
63+
{
64+
Write-Host "Busid not specified"
65+
}
66+
}
67+
}
68+
else
69+
{
70+
Write-Host "No argument specified. Use -Attach, -Detach or -List"
71+
Write-Host 'Ex: ./wslusb.ps1 -b "5-3" -Attach'
72+
}

0 commit comments

Comments
 (0)