Skip to content

Support "no init access" feature of Kvaser interfaces #1955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion can/interfaces/kvaser/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ def __init__(
:param int data_bitrate:
Which bitrate to use for data phase in CAN FD.
Defaults to arbitration bitrate.

:param bool no_init_access:
Don't open the handle with init access.
"""

log.info(f"CAN Filters: {can_filters}")
Expand All @@ -455,6 +456,7 @@ def __init__(
exclusive = kwargs.get("exclusive", False)
override_exclusive = kwargs.get("override_exclusive", False)
accept_virtual = kwargs.get("accept_virtual", True)
no_init_access = kwargs.get("no_init_access", False)
fd = isinstance(timing, BitTimingFd) if timing else kwargs.get("fd", False)
data_bitrate = kwargs.get("data_bitrate", None)
fd_non_iso = kwargs.get("fd_non_iso", False)
Expand Down Expand Up @@ -491,6 +493,8 @@ def __init__(
flags |= canstat.canOPEN_OVERRIDE_EXCLUSIVE
if accept_virtual:
flags |= canstat.canOPEN_ACCEPT_VIRTUAL
if no_init_access:
flags |= canstat.canOPEN_NO_INIT_ACCESS
if fd:
if fd_non_iso:
flags |= canstat.canOPEN_CAN_FD_NONISO
Expand Down
13 changes: 13 additions & 0 deletions test/test_kvaser.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,19 @@ def test_bus_get_stats(self):
self.assertTrue(canlib.canGetBusStatistics.called)
self.assertIsInstance(stats, canlib.structures.BusStatistics)

def test_bus_no_init_access(self):
canlib.canOpenChannel.reset_mock()
bus = can.Bus(interface="kvaser", channel=0, no_init_access=True)

self.assertGreater(canlib.canOpenChannel.call_count, 0)
for call in canlib.canOpenChannel.call_args_list:
self.assertEqual(
call[0][1] & constants.canOPEN_NO_INIT_ACCESS,
constants.canOPEN_NO_INIT_ACCESS,
)

bus.shutdown()

@staticmethod
def canGetNumberOfChannels(count):
count._obj.value = 2
Expand Down
Loading