Skip to content

Commit

Permalink
pyDAPAccess: use platform.system() for backend OS detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
flit committed Mar 10, 2021
1 parent dba0713 commit dadeca0
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pyocd/probe/pydapaccess/interface/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pyOCD debugger
# Copyright (c) 2006-2013 Arm Limited
# Copyright (c) 2021 Chris Reed
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,6 +17,7 @@

import os
import logging
import platform
from ..dap_access_api import DAPAccessIntf
from .hidapi_backend import HidApiUSB
from .pyusb_backend import PyUSB
Expand All @@ -40,21 +42,22 @@
USB_BACKEND = ""

# Select backend based on OS and availability.
system = platform.system()
if not USB_BACKEND:
if os.name == "nt":
if system == "Windows":
# Prefer hidapi over pyWinUSB for Windows, since pyWinUSB has known bug(s)
if HidApiUSB.isAvailable:
USB_BACKEND = "hidapiusb"
elif PyWinUSB.isAvailable:
USB_BACKEND = "pywinusb"
else:
raise DAPAccessIntf.DeviceError("No USB backend found")
elif os.name == "posix":
# Select hidapi for OS X and pyUSB for Linux.
if os.uname()[0] == 'Darwin':
USB_BACKEND = "hidapiusb"
else:
USB_BACKEND = "pyusb"
# Default to hidapi for OS X.
elif system == "Darwin":
USB_BACKEND = "hidapiusb"
# Default to pyUSB for Linux.
elif system == "Linux":
USB_BACKEND = "pyusb"
else:
raise DAPAccessIntf.DeviceError("No USB backend found")

Expand Down

0 comments on commit dadeca0

Please sign in to comment.