interfaces/cantact: Handle None timeout by setting to 0xFFF...#2026
interfaces/cantact: Handle None timeout by setting to 0xFFF...#2026zariiii9003 merged 1 commit intohardbyte:mainfrom
Conversation
|
But The cantact lib calls |
|
Hi @zariiii9003 ; yes i think you're 100% right. I wonder: should these other cases of drivers treating None as 0 be fixed also?
|
|
The usb2can implementation seems correct to me. If our The gs_usb implementation seems wrong indeed. The candle_bus implementation also seems incorrect, but that's not part of this repo. |
|
thank you @zariiii9003 . I fixed this change to cantact with a force-push. I made this BIRLab/python-can-candle#5 for python-can-cantact I am not sure how to fix gs-usb and also these days I find it hard to test it since it requires libusbK. I don't use it almost ever since the cantact (and now python-can-candle) drivers work with the exact same devices... |
|
Thank you! Please add a short news fragment and i'll merge. Regarding gs-usb: it seems to be similar to usb2can, to block forever the read function needs to be called with 0: |
timeout=None means block forever
pass '0' when timeout=None (as proposed by @zariiii9003 in hardbyte#2026 (comment))
pass '0' when timeout=None (as proposed by @zariiii9003 in hardbyte#2026 (comment))
pass '0' when timeout=None (as proposed by @zariiii9003 in hardbyte#2026 (comment))
pass '0' when timeout=None (as proposed by @zariiii9003 in hardbyte#2026 (comment))
* Update gs_usb driver to support WinUSB by not forcing libusb1 backend 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> * Add pyusb as explicit dependency in gs-usb optional group 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> * gs_usb: treat timeout=None as forever pass '0' when timeout=None (as proposed by @zariiii9003 in #2026 (comment)) * add news fragment * formatting fixes * gs_usb module needed in tests deps now * Fix gs_usb shutdown to always call parent BusABC.shutdown() 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> * note pyusb not WinUSB in news and news frags are a sentence not a list (@zariiii9003) * put gs-usb dep into tox.ini (@zariiii9003) * combine _scan_gs_usb_devices() and _find_gs_usb_device() (@zariiii9003) * don't instantiate a GsUsb device for every one detected (@zariiii9003) * remove gs-usb from mypy (@zariiii9003) * gs_usb: explicitly handle timeout=None separate from =0 (@zariiii9003) --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: BenGardiner <243321+BenGardiner@users.noreply.github.com>
Summary of Changes
There are definitely cases of client code that end up passing timeout=None to _recv_internal(). Several other interfaces/*.py are prepared for this e.g. canalystii usb2can canlib_vcinpl2 gs_usb.py
For cantact I think the right thing to do is set default timeout to 0 if None is provided.
There are definitely cases of client code that end up passing timeout=None to _recv_internal(). Several other interfaces/*.py are prepared for this e.g. canalystii usb2can canlib_vcinpl2 gs_usb.py
For cantact I think the right thing to do is set default timeout to 0 if None is provided.
Type of Change
Checklist
tox).