usb15: make USB support optional
This commit is contained in:
parent
9af984a191
commit
81c890337e
3
setup.py
3
setup.py
@ -29,6 +29,9 @@ setup(
|
||||
version = stcgal.__version__,
|
||||
packages = find_packages(exclude=["doc"]),
|
||||
install_requires = ["pyserial"],
|
||||
extras_require = {
|
||||
"usb": ["pyusb>=1.0.0"]
|
||||
},
|
||||
entry_points = {
|
||||
"console_scripts": [
|
||||
"stcgal = stcgal.frontend:cli",
|
||||
|
@ -26,9 +26,15 @@ import argparse
|
||||
import collections
|
||||
from stcgal.models import MCUModelDatabase
|
||||
from stcgal.utils import Utils
|
||||
import usb, usb.core, usb.util
|
||||
import functools
|
||||
|
||||
try:
|
||||
import usb.core, usb.util
|
||||
_usb_available = True
|
||||
except ImportError:
|
||||
_usb_available = False
|
||||
|
||||
|
||||
class StcFramingException(Exception):
|
||||
"""Something wrong with packet framing or checksum"""
|
||||
pass
|
||||
@ -2048,6 +2054,11 @@ class StcUsb15Protocol(Stc15Protocol):
|
||||
def connect(self, autoreset=False):
|
||||
"""Connect to USB device and read info packet"""
|
||||
|
||||
# USB support is optional. Provide an error if pyusb is not available.
|
||||
if _usb_available == False:
|
||||
raise StcProtocolException("USB support not available. "
|
||||
+ "pyusb is not installed or not working correctly.")
|
||||
|
||||
print("Waiting for MCU, please cycle power: ", end="")
|
||||
sys.stdout.flush()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user