Skip to content

Commit

Permalink
gs_usb, interface: support this interface on command-line with e.g. c…
Browse files Browse the repository at this point in the history
…an.logger by treating channel like index when all other arguments are missing
  • Loading branch information
BenGardiner committed Jun 9, 2024
1 parent 0aa4f06 commit a20f44a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions can/interfaces/gs_usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def __init__(
"index and bus/address cannot be used simultaneously"
)

if index is None and address is None and bus is None:
index = channel

self.index = None
if index is not None:
devs = GsUsb.scan()
Expand Down
3 changes: 2 additions & 1 deletion doc/interfaces/gs_usb.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ and candleLight USB CAN interfaces.

Install: ``pip install "python-can[gs_usb]"``

Usage: pass device ``index`` (starting from 0) if using automatic device detection:
Usage: pass device ``index`` or ``channel`` (starting from 0) if using automatic device detection:

::

import can

bus = can.Bus(interface="gs_usb", channel=dev.product, index=0, bitrate=250000)
bus = can.Bus(interface="gs_usb", channel=0, bitrate=250000) # same

Alternatively, pass ``bus`` and ``address`` to open a specific device. The parameters can be got by ``pyusb`` as shown below:

Expand Down

0 comments on commit a20f44a

Please sign in to comment.