Repository navigation
Unify listen-only mode into can.Bus(listen_only=...) - #2149
Open
zariiii9003 wants to merge 8 commits into
Open
zariiii9003 wants to merge 8 commits into
zariiii9003 wants to merge 8 commits into
Conversation
zariiii9003
force-pushed
the
listen-only-split-v3
branch
from
November 22, 2026 22:51
07961cd to
689d3e6
Compare
zariiii9003
force-pushed
the
listen-only-split-v3
branch
from
November 23, 2026 00:14
689d3e6 to
e7dce5a
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary of Changes
Makes listen-only mode part of the official bus API and moves it out of
BusState, as proposed in #736: alisten_onlyflag replaces the use ofBusState.PASSIVEas a mode switch, soBusStateno longer mixes the CAN error state with a configuration option.Listen-only mode is the bus monitoring mode of ISO 11898-1 (§10.14): the node receives frames but never drives the bus dominant, so it sends no ACKs, error or overload flags (unlike restricted operation mode, §10.15). The name
listen_onlyfollows iproute2 and the existing vendor options.Contract, documented on
BusABC: an interface supports listen-only mode only if its constructor declares alisten_onlyparameter. For every other interface, built-in or third-party,BusABC.__new__raisesCanInterfaceNotImplementedErrorforlisten_only=Truebefore the constructor runs, so no driver or device is opened; this works forcan.Busand for direct instantiation.Falseis always accepted. In listen-only mode nothing is put on the wire andsend()raisesCanOperationError.listen_only=Truemonitordriver_modelisten_only)bus.listen_only = ...state=argument,bus.state = BusState.PASSIVEoperation_mode="silent"/"loopback_and_silent"listen_onlyCanInterfaceNotImplementedErrorcan.cli: new--listen-only/--<prefix>-listen-onlyswitch (iproute2 keyword);can.logger --passive/--activeare deprecated and hidden from--help,--passivenow opens the bus withlisten_only=True.BusState.ACTIVEat runtime.BusStateitself is unchanged; the error state part of Meaning of can.BusABC.state #736 (ErrorState, error counters) is not addressed here.Related Issues / Pull Requests
Type of Change
Checklist
tox).Additional Notes
Evidence
tox -e py,lint,type,docspasses on every commit (final state: 741 passed, 66 skipped). Mocked listen-only tests per interface check that the hardware mode is set and thatsend()does not reach the driver:can.Bus(interface="socketcan", channel="vcan0", listen_only=True)silently ignoreslisten_onlyand the bus transmits.After: raises
CanInterfaceNotImplementedErrorbefore the socket is opened.**kwargssilently ignoreslisten_only=Trueand transmits.After: raises
CanInterfaceNotImplementedErrorbefore the plugin constructor runs (test_bus.py::test_bus_listen_only_rejected_if_not_declared, throughcan.Busand directly).VectorBus(..., listen_only=True).send(msg)is accepted and only looped back locally.After: raises
CanOperationError, like every other listen-only bus.The real-hardware Vector test (
test_vector.py::test_listen_only) is skipped without the XL driver and still needs a run on a machine with Vector hardware.Merge Danger
Door: two-way
Nothing is removed; deprecated options keep working until 5.0.0, and every change can be reverted before a release.
Blast Radius: plugins
can.Busnow always passeslisten_onlyto the bus class, so a third-party interface whose__init__accepts neitherlisten_onlynor**kwargsfails withTypeError; all 11 plugins listed indoc/plugin-interface.rstaccept**kwargs, so none of them breaks. For 9 of them (canine, remote, sontheim, zlgcan, cando, RP1210, damiao, hub, coe)listen_only=Truenow raisesCanInterfaceNotImplementedErrorinstead of being silently ignored while the bus transmits. candle declareslisten_onlyand keeps working, but itsbus.listen_onlyreportsFalseuntil it updates the new property.send()now raises in listen-only mode for users of the existing Vectorlisten_only, seeedstudio silent modes, cantactmonitor, kvaserdriver_modeand pcan/systecBusState.PASSIVE.CantactBus(monitor) andPcanBus(state) lose a positional parameter, which shifts later positional arguments.🤖 Generated with AI