Skip to content

Commit a93f91e

Browse files
committed
script: Add wsl2 devices support SiliconLabsSoftware#73
Relates-to:SiliconLabsSoftware#72
1 parent 073d9b8 commit a93f91e

2 files changed

Lines changed: 91 additions & 21 deletions

File tree

README.md

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,34 +103,31 @@ ZPC> zwave_add_node
103103
(...)
104104
```
105105

106-
Set endnode to learn mode and the controller should see it:
106+
### WSL2 build
107107

108-
```sh
109-
(...)
110-
Please verify the DSK and insert the missing part (first 5 digits)
111-
Usage: zwave_accept_dsk <insert the first two byte of the DSK in [decimal]>
112-
ZPC> zwave_accept_dsk (...)
113-
```
108+
How to use a z-wave controller with ZPC running in WSL2 ?
109+
110+
You can use this [script](./scripts/wslusb.ps1).
114111

115-
Then you will have to learn how to use couple of shell commands
116-
"attribute_store_log" and "attribute_store_set_desired",
117-
as explained in the reference documentation.
112+
Start by installing the usbipd service as described at: https://learn.microsoft.com/en-us/windows/wsl/connect-usb
118113

119114
```sh
120-
ZPC>attribute_store_log
121-
(...)
122-
ZPC>attribute_store_log_search OnOff
123-
(...)
124-
│ │ │ │───(110) ZCL OnOff OnOff ..................................... 0
125-
(...)
126-
ZPC>attribute_store_set_desired 110,1
127-
(...)
128-
```
115+
# You can list devices using:
116+
117+
(Powershell)$ ./wslusb.ps1 -List
118+
119+
# Get the BUSID of the device you want to mount
129120

130-
### More
121+
(Powershell)$ ./wslusb.ps1 -Attach <busid>
131122

132-
Refer to [./doc](doc) for more (using shell, MQTT, WebApp etc).
123+
# Check that the device is correctly mounted into WSL2
133124

125+
(WSL2)$ lsusb # you should see your device here
126+
127+
# Detach the device with
128+
129+
(Powershell)$ ./wslusb.ps1 -Detach <busid>
130+
```
134131

135132
### Docker build
136133

scripts/wslusb.ps1

Lines changed: 73 additions & 0 deletions
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)