Skip to content

Commit fde8b4a

Browse files
committed
script: Add wsl2 devices support #73
Relates-to:#72
1 parent 901105b commit fde8b4a

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

README.md

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

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

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

scripts/wslusb.ps1

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

0 commit comments

Comments
 (0)