Skip to content

Commit a20f44a

Browse files
committed
gs_usb, interface: support this interface on command-line with e.g. can.logger by treating channel like index when all other arguments are missing
1 parent 0aa4f06 commit a20f44a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

can/interfaces/gs_usb.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ def __init__(
3838
"index and bus/address cannot be used simultaneously"
3939
)
4040

41+
if index is None and address is None and bus is None:
42+
index = channel
43+
4144
self.index = None
4245
if index is not None:
4346
devs = GsUsb.scan()

doc/interfaces/gs_usb.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ and candleLight USB CAN interfaces.
88

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

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

1313
::
1414

1515
import can
1616

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

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

0 commit comments

Comments
 (0)