From 2f0d4edb043f4979864e4e56edd3db22d3a7a037 Mon Sep 17 00:00:00 2001 From: mkozlowski <10508687+m-kozlowski@users.noreply.github.com> Date: Mon, 21 Aug 2023 19:57:03 +0200 Subject: [PATCH] Add com port auto detection on WSL1 --- software/script/chameleon_cli_unit.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/software/script/chameleon_cli_unit.py b/software/script/chameleon_cli_unit.py index d4f7808..ad5dc48 100644 --- a/software/script/chameleon_cli_unit.py +++ b/software/script/chameleon_cli_unit.py @@ -8,6 +8,7 @@ import timeit import sys import time import serial.tools.list_ports +from platform import uname import chameleon_com import chameleon_cmd @@ -187,11 +188,22 @@ class HWConnect(BaseCLIUnit): def on_exec(self, args: argparse.Namespace): try: if args.port is None: # Chameleon auto-detect if no port is supplied - # loop through all ports and find chameleon - for port in serial.tools.list_ports.comports(): - if port.vid == 0x6868: - args.port = port.device - break + platformname = uname().release + if 'microsoft-standard-WSL2' in platformname: + #wsl2 serial support is broken anyway + pass + elif 'Microsoft' in platformname: + process = subprocess.Popen(["powershell.exe","Get-CimInstance -ClassName Win32_serialport | Where-Object {$_.PNPDeviceID -like '*VID_6868&PID_8686*'} | Select -expandproperty DeviceID"],stdout=subprocess.PIPE); + res = process.communicate()[0] + _comport = res.decode('utf-8').strip() + if _comport: + args.port = _comport.replace('COM', '/dev/ttyS') + else: + # loop through all ports and find chameleon + for port in serial.tools.list_ports.comports(): + if port.vid == 0x6868: + args.port = port.device + break if args.port is None: # If no chameleon was found, exit print("Chameleon not found, please connect the device or try connecting manually with the -p flag.") return