« Utiliser un port USB dans WSL » : différence entre les versions

De knowledge
Aller à la navigation Aller à la recherche
(Page créée avec « = Accès à un périphérique USB (COM) depuis WSL2 = == Pré-requis == * Windows 10 ou 11 avec WSL2 installé * Périphérique USB connecté (ex: convertisseur USB-Série) * Outil usbipd-win installé sur Windows * (Optionnel) Désinstallation du filtre USBPcap si installé avec Wireshark == Étapes == === 1. Lancer PowerShell en mode administrateur === # Appuyer sur la touche Windows # Taper ''PowerShell'' # Clic dro... »)
 
Ligne 21 : Ligne 21 :
Exemple de sortie :
Exemple de sortie :
<pre>
<pre>
BUSID  VID:PID    DEVICE                               STATE
Connected:
5-1   2341:0043 Arduino Uno                          Not shared
BUSID  VID:PID    DEVICE                                                       STATE
5-2    1a86:7523 USB-SERIAL CH340                      Not shared
2-3    1a86:7523  USB-SERIAL CH340 (COM3)                                      Shared (forced)
2-5    1c7a:05a1 EgisTec Touch Fingerprint Sensor                              Not shared
2-10  8087:0033 Intel(R) Wireless Bluetooth(R)                                Not shared
 
Persisted:
GUID                                  DEVICE
c92d89c5-835f-48e0-9253-c3e6479422c3  USB Serial Converter
</pre>
</pre>


=== 3. Partager le périphérique avec WSL ===
=== 3. Partager le périphérique avec WSL ===
Si USBPcap est installé, ajouter l’option ''--force'' :
<syntaxhighlight lang="powershell">
<syntaxhighlight lang="powershell">
usbipd bind --busid 5-2 --force
usbipd bind --busid 2-3 --force  # --force necessaire si wireshark est installé
usbipd attach --wsl --busid 5-2
usbipd attach --wsl --busid 2-3
</syntaxhighlight>
</syntaxhighlight>


Ligne 46 : Ligne 50 :
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
sudo apt install screen
sudo apt install screen
screen /dev/ttyUSB0 9600
screen /dev/ttyUSB0 115200
</syntaxhighlight>
</syntaxhighlight>


Ligne 69 : Ligne 73 :
* Le port COM3 de Windows peut correspondre à ''/dev/ttyUSB0'' dans WSL2
* Le port COM3 de Windows peut correspondre à ''/dev/ttyUSB0'' dans WSL2
* USBPcap peut interférer avec usbipd-win → désinstallation recommandée si non utilisé
* USBPcap peut interférer avec usbipd-win → désinstallation recommandée si non utilisé
== Liens utiles ==
* [[https://github.com/dorssel/usbipd-win|usbipd-win GitHub]]
* [[https://technofossy.com/how-to-access-serial-ports-com-ttys-in-windows-subsystem-for-linux-wsl1-wsl2/|Guide Technofossy sur les ports COM dans WSL]]

Version du 17 août 2025 à 22:51

Accès à un périphérique USB (COM) depuis WSL2

Pré-requis

  • Windows 10 ou 11 avec WSL2 installé
  • Périphérique USB connecté (ex: convertisseur USB-Série)
  • Outil [[1]] installé sur Windows
  • (Optionnel) Désinstallation du filtre USBPcap si installé avec Wireshark

Étapes

1. Lancer PowerShell en mode administrateur

  1. Appuyer sur la touche Windows
  2. Taper PowerShell
  3. Clic droit → Exécuter en tant qu’administrateur

2. Lister les périphériques USB disponibles

usbipd list

Exemple de sortie :

Connected:
BUSID  VID:PID    DEVICE                                                        STATE
2-3    1a86:7523  USB-SERIAL CH340 (COM3)                                       Shared (forced)
2-5    1c7a:05a1  EgisTec Touch Fingerprint Sensor                              Not shared
2-10   8087:0033  Intel(R) Wireless Bluetooth(R)                                Not shared

Persisted:
GUID                                  DEVICE
c92d89c5-835f-48e0-9253-c3e6479422c3  USB Serial Converter

3. Partager le périphérique avec WSL

usbipd bind --busid 2-3 --force  # --force necessaire si wireshark est installé
usbipd attach --wsl --busid 2-3

4. Vérifier dans WSL

ls /dev/ttyUSB*

Le périphérique devrait apparaître comme /dev/ttyUSB0 ou similaire.

Test de communication

Avec screen

sudo apt install screen
screen /dev/ttyUSB0 115200

Quitter avec : Ctrl + A puis KY

Avec Python (pyserial)

sudo apt install python3-pyserial
import serial

ser = serial.Serial('/dev/ttyUSB0', 9600, timeout=1)
ser.write(b'*IDN?\n')  # Exemple de commande SCPI
response = ser.readline()
print("Réponse:", response.decode().strip())
ser.close()

Remarques

  • Le port COM3 de Windows peut correspondre à /dev/ttyUSB0 dans WSL2
  • USBPcap peut interférer avec usbipd-win → désinstallation recommandée si non utilisé