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__,
|
version = stcgal.__version__,
|
||||||
packages = find_packages(exclude=["doc"]),
|
packages = find_packages(exclude=["doc"]),
|
||||||
install_requires = ["pyserial"],
|
install_requires = ["pyserial"],
|
||||||
|
extras_require = {
|
||||||
|
"usb": ["pyusb>=1.0.0"]
|
||||||
|
},
|
||||||
entry_points = {
|
entry_points = {
|
||||||
"console_scripts": [
|
"console_scripts": [
|
||||||
"stcgal = stcgal.frontend:cli",
|
"stcgal = stcgal.frontend:cli",
|
||||||
|
@ -26,9 +26,15 @@ import argparse
|
|||||||
import collections
|
import collections
|
||||||
from stcgal.models import MCUModelDatabase
|
from stcgal.models import MCUModelDatabase
|
||||||
from stcgal.utils import Utils
|
from stcgal.utils import Utils
|
||||||
import usb, usb.core, usb.util
|
|
||||||
import functools
|
import functools
|
||||||
|
|
||||||
|
try:
|
||||||
|
import usb.core, usb.util
|
||||||
|
_usb_available = True
|
||||||
|
except ImportError:
|
||||||
|
_usb_available = False
|
||||||
|
|
||||||
|
|
||||||
class StcFramingException(Exception):
|
class StcFramingException(Exception):
|
||||||
"""Something wrong with packet framing or checksum"""
|
"""Something wrong with packet framing or checksum"""
|
||||||
pass
|
pass
|
||||||
@ -2048,6 +2054,11 @@ class StcUsb15Protocol(Stc15Protocol):
|
|||||||
def connect(self, autoreset=False):
|
def connect(self, autoreset=False):
|
||||||
"""Connect to USB device and read info packet"""
|
"""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="")
|
print("Waiting for MCU, please cycle power: ", end="")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user