Skip to content

Comments

gs-usb WinUSB support and timeout=none is forever#2031

Open
BenGardiner wants to merge 7 commits intohardbyte:mainfrom
BenGardiner:gs_usb_WinUSB_and_timeoutNone
Open

gs-usb WinUSB support and timeout=none is forever#2031
BenGardiner wants to merge 7 commits intohardbyte:mainfrom
BenGardiner:gs_usb_WinUSB_and_timeoutNone

Conversation

@BenGardiner
Copy link
Contributor

@BenGardiner BenGardiner commented Feb 23, 2026

Summary of Changes

This changes gs_usb handling of timeout=None to 'forever' by passing 0 to the underlying layer as suggested by @zariiii9003 in #2026 .

But first I needed to make gs_usb use WinUSB instead of libusbK because I didn't want to zadig anymore. I had no clue how to do this so I got copilot claude opus 4.6 to make those base changes. Here's what they said in BenGardiner#1

The upstream gs_usb package hardcodes backend=libusb1.get_backend() in GsUsb.scan() and
GsUsb.find(), which forces the libusb1 backend and requires libusbK on Windows. WCID-compatible devices (e.g. candleLight) auto-install WinUSB, but the forced backend prevents it from working.

Additionally, the gs_usb interface directly imports usb (pyusb) but pyusb was only a transitive dependency via the gs-usb package, causing No module named 'usb' on import.

can/interfaces/gs_usb.py: Replace GsUsb.scan() / GsUsb.find() with local _scan_gs_usb_devices() / _find_gs_usb_device() that call usb.core.find() without specifying a backend, letting pyusb auto-detect (WinUSB, libusbK, libusb, etc.)
pyproject.toml: Add pyusb>=1.0.2 as explicit dependency in the gs-usb optional group since we now import usb directly
doc/interfaces/gs_usb.rst: Update Windows driver guidance to reflect both WinUSB and libusbK support
test/test_interface_gs_usb.py: Add tests verifying no backend is forced in device discovery

I have tested here on a 500Kbps medium load bus; I used the same device and setup with all of the cantact, candle and gs_usb python-can drivers and got the same results

Related Issues / Pull Requests

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Refactoring
  • Other (please describe):

Checklist

  • I have followed the contribution guide.
  • I have added or updated tests as appropriate.
  • I have added or updated documentation as appropriate.
  • I have added a news fragment for towncrier.
  • All checks and tests pass (tox).

Additional Notes

I will add news frag once I know what the PR # is.

Copilot AI and others added 4 commits February 23, 2026 10:11
Replace GsUsb.scan() and GsUsb.find() calls with local helper functions
that call usb.core.find() without specifying a backend, allowing pyusb
to auto-detect the best available backend. This enables WinUSB support
on Windows in addition to libusbK.

Update documentation to reflect WinUSB support and add unit tests.

Co-authored-by: BenGardiner <243321+BenGardiner@users.noreply.github.com>
The gs_usb interface directly imports `usb` (pyusb) for USB device
discovery, so pyusb must be an explicit dependency rather than relying
on it being a transitive dependency of the gs-usb package.

Co-authored-by: BenGardiner <243321+BenGardiner@users.noreply.github.com>
pass '0' when timeout=None (as proposed by @zariiii9003
 in hardbyte#2026 (comment))
BenGardiner and others added 3 commits February 23, 2026 10:28
BusABC has a class-level _is_shutdown = True attribute. When __init__
was not called (as in test mocks), GsUsbBus.shutdown() resolved this
class attribute and returned early, never calling super().shutdown().

Restructure shutdown() to always call super().shutdown(), using the
pre-call _is_shutdown state only to guard interface-specific cleanup.

Co-authored-by: BenGardiner <243321+BenGardiner@users.noreply.github.com>
@BenGardiner
Copy link
Contributor Author

I'm not even sure these unit tests proposed by the LLM are needed for gs_usb interface.

(I also wonder if a removal or deprecation of gs_usb here should be considered because cantact is in tree and is more performant and python-can-candle works is more portable and more performant still)

@BenGardiner BenGardiner changed the title Gs usb win usb and timeout none gs-usb WinUSB support and timeout=none is forever Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants