Skip to content

Commit

Permalink
Merge pull request #128 from danielhrisca/master
Browse files Browse the repository at this point in the history
restrict the USB search based on the vendor ID and product ID
  • Loading branch information
christoph2 committed Feb 10, 2023
2 parents d959b9a + 29ce7d9 commit 248ea55
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.20.0
current_version = 0.20.1
commit = True
tag = False

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
"uptime>=3.0.1",
]
name = "pyxcp"
version = "0.20.0"
version = "0.20.1"
readme = "README.md"
description = "Universal Calibration Protocol for Python"
keywords = ["automotive", "ecu", "xcp", "asam", "autosar"]
Expand Down
2 changes: 1 addition & 1 deletion pyxcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
from .transport import Usb

# if you update this manually, do not forget to update .bumpversion.cfg
__version__ = "0.20.0"
__version__ = "0.20.1"
22 changes: 16 additions & 6 deletions pyxcp/transport/usb_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Usb(BaseTransport):
"interface_number": (int, True, 2),
"command_endpoint_number": (int, True, 0),
"reply_endpoint_number": (int, True, 1),
"vendor_id": (int, False, 0),
"product_id": (int, False, 0),
}
HEADER = struct.Struct("<2H")
HEADER_SIZE = HEADER.size
Expand All @@ -34,6 +36,8 @@ def __init__(self, config=None):
super(Usb, self).__init__(config)
self.loadConfig(config)
self.serial_number = self.config.get("serial_number").strip()
self.vendor_id = self.config.get("vendor_id")
self.product_id = self.config.get("product_id")
self.configuration_number = self.config.get("configuration_number")
self.interface_number = self.config.get("interface_number")
self.command_endpoint_number = self.config.get("command_endpoint_number")
Expand All @@ -50,16 +54,22 @@ def __init__(self, config=None):
self._packets = deque()

def connect(self):
for device in usb.core.find(find_all=True):
if self.vendor_id and self.product_id:
kwargs = {
"find_all": True,
"idVendor": self.vendor_id,
"idProduct": self.product_id,
}
else:
kwargs = {
"find_all": True,
}

for device in usb.core.find(**kwargs):
try:
if device.serial_number.strip().strip("\0").lower() == self.serial_number.lower():
self.device = device
break
else:
print(
device.serial_number.strip().strip("\0").lower(),
self.serial_number.lower(),
)
except BaseException:
continue
else:
Expand Down

0 comments on commit 248ea55

Please sign in to comment.