mirror of
https://github.com/RfidResearchGroup/ChameleonUltra.git
synced 2026-05-12 11:22:59 -07:00
Add com port auto detection on WSL1
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user