Repository navigation
Unify listen-only mode into can.Bus(listen_only=...) - #2149
Open
zariiii9003 wants to merge 6 commits into
Open
zariiii9003 wants to merge 6 commits into
zariiii9003 wants to merge 6 commits into
Conversation
zariiii9003
force-pushed
the
listen-only-split-v3
branch
2 times, most recently
from
November 23, 2026 00:14
689d3e6 to
e7dce5a
Compare
zariiii9003
force-pushed
the
listen-only-split-v3
branch
from
November 24, 2026 19:40
471a16e to
81084ba
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, or forwards**kwargsto a base class constructor that does. 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, andcan.Busdrops it instead of forwarding it, so interfaces that do not know the argument keep working unchanged. In listen-only mode nothing is put on the wire andsend()raisesCanOperationError.listen_only=Truemonitordriver_modelisten_only)bus.listen_only = ...state=argument, settingbus.stateoperation_mode="silent"/"loopback_and_silent"(the latter now behaves like"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;--activeno longer touchesbus.stateand only switches off a listen-only mode that came from the configuration (e.g.state = PASSIVEfor pcan or systec).bus.stateis deprecated in favour oflisten_only, onBusABCand on pcan/systec.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. 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.**kwargsand passes them toBusABCsilently 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).__init__(*args, **kwargs)would be rejected by a check on its own signature.After: accepted and opened in listen-only mode (
test_bus.py::test_bus_listen_only_accepted_if_forwarded).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.Busonly passeslisten_onlywhen it isTrue, so third-party interfaces that do not know the argument are unaffected unless listen-only mode is requested. For the 9 plugins indoc/plugin-interface.rstthat take**kwargswithout declaringlisten_only(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. Settingbus.stateon pcan/systec now always emits aDeprecationWarning, andcan.logger --activeno longer setsbus.state.CantactBus(monitor) andPcanBus(state) lose a positional parameter, which shifts later positional arguments.🤖 Generated with AI