-
Notifications
You must be signed in to change notification settings - Fork 666
gs-usb WinUSB support and timeout=none is forever #2031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BenGardiner
wants to merge
11
commits into
hardbyte:main
Choose a base branch
from
BenGardiner:gs_usb_WinUSB_and_timeoutNone
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+147
−32
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b335bbd
Update gs_usb driver to support WinUSB by not forcing libusb1 backend
Copilot eecde92
Add pyusb as explicit dependency in gs-usb optional group
Copilot 2408840
gs_usb: treat timeout=None as forever
BenGardiner d7e2e3a
add news fragment
BenGardiner 1e68110
formatting fixes
BenGardiner f0cbee0
gs_usb module needed in tests deps now
BenGardiner 4367d90
Fix gs_usb shutdown to always call parent BusABC.shutdown()
Copilot 9618934
note pyusb not WinUSB in news and news frags are a sentence not a lis…
BenGardiner ea01de5
put gs-usb dep into tox.ini (@zariiii9003)
BenGardiner 75fe619
combine _scan_gs_usb_devices() and _find_gs_usb_device() (@zariiii9003)
BenGardiner 3e5b1c0
don't instantiate a GsUsb device for every one detected (@zariiii9003)
BenGardiner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| make gs_usb use pyusb (allows WinUSB instead of requiring libusbK on windows) also timeout=None means foreever |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| """Tests for the gs_usb interface.""" | ||
|
|
||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| from can.interfaces.gs_usb import ( | ||
| GsUsbBus, | ||
| _find_gs_usb_devices, | ||
| ) | ||
|
|
||
|
|
||
| @patch("can.interfaces.gs_usb.usb.core.find") | ||
| def test_find_devices_does_not_force_backend(mock_find): | ||
| """Verify that _find_gs_usb_devices does not pass a backend argument, | ||
| allowing pyusb to auto-detect the best available backend (WinUSB, libusbK, etc.).""" | ||
| mock_find.return_value = [] | ||
|
|
||
| _find_gs_usb_devices() | ||
|
|
||
| mock_find.assert_called_once() | ||
| call_kwargs = mock_find.call_args[1] | ||
| assert ( | ||
| "backend" not in call_kwargs | ||
| ), "backend should not be specified so pyusb can auto-detect" | ||
| assert call_kwargs["find_all"] is True | ||
|
|
||
|
|
||
| @patch("can.interfaces.gs_usb.usb.core.find") | ||
| def test_find_devices_with_args_does_not_force_backend(mock_find): | ||
| """Verify that _find_gs_usb_devices with bus/address does not pass a backend argument.""" | ||
| mock_find.return_value = [] | ||
|
|
||
| _find_gs_usb_devices(bus=1, address=2) | ||
|
|
||
| mock_find.assert_called_once() | ||
| call_kwargs = mock_find.call_args[1] | ||
| assert ( | ||
| "backend" not in call_kwargs | ||
| ), "backend should not be specified so pyusb can auto-detect" | ||
| assert call_kwargs["bus"] == 1 | ||
| assert call_kwargs["address"] == 2 | ||
| assert call_kwargs["find_all"] is True | ||
|
|
||
|
|
||
| @patch("can.interfaces.gs_usb.usb.core.find") | ||
| def test_find_devices_returns_raw_usb_devices(mock_find): | ||
| """Verify that _find_gs_usb_devices returns the raw USB devices.""" | ||
| mock_dev1 = MagicMock() | ||
| mock_dev2 = MagicMock() | ||
| mock_find.return_value = [mock_dev1, mock_dev2] | ||
|
|
||
| devices = _find_gs_usb_devices() | ||
|
|
||
| assert len(devices) == 2 | ||
| assert devices[0] is mock_dev1 | ||
| assert devices[1] is mock_dev2 | ||
|
|
||
|
|
||
| @patch("can.interfaces.gs_usb.usb.core.find") | ||
| def test_find_devices_returns_empty_list_when_no_devices(mock_find): | ||
| """Verify that _find_gs_usb_devices returns an empty list when no devices are found.""" | ||
| mock_find.return_value = [] | ||
|
|
||
| devices = _find_gs_usb_devices() | ||
|
|
||
| assert devices == [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't actually fix the issue you wanted to fix though. Both
Noneand0are falsy, sotimeout_mswill be 0 for both. According to the comment (i don't know whether it is correct) 0 means blocking.Otherwise the PR looks much better now, thank you for also adding type annotations. You could remove gs_usb from the mypy exclude list in pyproject.toml now.