Skip to content

Task/thdubois/wsl2 devices doc #73

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,32 @@ ZPC>attribute_store_set_desired 110,1
(...)
```

### WSL2 build

How to use a z-wave controller with ZPC running in WSL2 ?

You can use this [script](./scripts/wslusb.ps1).

Start by installing the usbipd service as described at: https://learn.microsoft.com/en-us/windows/wsl/connect-usb

```sh
# You can list devices using:

(Powershell)$ ./wslusb.ps1 -List

# Get the BUSID of the device you want to mount

(Powershell)$ ./wslusb.ps1 -Attach <busid>

# Check that the device is correctly mounted into WSL2

(WSL2)$ lsusb # you should see your device here

# Detach the device with

(Powershell)$ ./wslusb.ps1 -Detach <busid>
```

### More

Refer to [./doc](doc) for more (using shell, MQTT, WebApp etc).
Expand Down
73 changes: 73 additions & 0 deletions scripts/wslusb.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# SPDX-License-Identifier: ZLib
# This script can be used to attach and detach a device to your WSL2 distribution

[CmdletBinding()]
param(
[Parameter(Mandatory= $false, HelpMessage = "Busid of the device you want to bind")]
[Alias("b")]
[string]$Busid,

[Switch]$Attach,
[Switch]$Detach,
[Switch]$List
)

# Unblock the script file
Unblock-File -Path $MyInvocation.MyCommand.Path

Function List-devices {
usbipd list
}

Function Attach-device {
param(
[string]$Busid
)
Write-Host "Attaching device $Busid"
usbipd bind --busid $Busid --force
usbipd attach --wsl --busid $Busid --auto-attach
}

Function Detach-device {
param(
[string]$Busid
)
Write-Host "Detaching device $Busid"
usbipd detach --busid $Busid
usbipd unbind --busid $Busid
}

if ($Attach -or $Detach -or $List)
{
if($List)
{
List-devices
}
if ($Detach)
{
if ($Busid)
{
Detach-device -Busid $Busid
}
else
{
Write-Host "Busid not specified"
}
}
if ($Attach)
{
if ($Busid)
{
Attach-device -Busid $Busid
}
else
{
Write-Host "Busid not specified"
}
}
}
else
{
Write-Host "No argument specified. Use -Attach, -Detach or -List"
Write-Host 'Ex: ./wslusb.ps1 -b "5-3" -Attach'
}