Skip to content
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

* For interface Kvaser, add parameter exclusive #1660

Merged
merged 2 commits into from
Sep 12, 2023
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
17 changes: 16 additions & 1 deletion can/interfaces/kvaser/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ def __init__(self, channel, can_filters=None, **kwargs):
computer, set this to True or set single_handle to True.
:param bool fd:
If CAN-FD frames should be supported.
:param bool exclusive:
Don't allow sharing of this CANlib channel.
:param bool override_exclusive:
Open the channel even if it is opened for exclusive access already.
:param int data_bitrate:
Which bitrate to use for data phase in CAN FD.
Defaults to arbitration bitrate.
Expand All @@ -420,6 +424,8 @@ def __init__(self, channel, can_filters=None, **kwargs):
driver_mode = kwargs.get("driver_mode", DRIVER_MODE_NORMAL)
single_handle = kwargs.get("single_handle", False)
receive_own_messages = kwargs.get("receive_own_messages", False)
exclusive = kwargs.get("exclusive", False)
override_exclusive = kwargs.get("override_exclusive", False)
accept_virtual = kwargs.get("accept_virtual", True)
fd = kwargs.get("fd", False)
data_bitrate = kwargs.get("data_bitrate", None)
Expand All @@ -445,6 +451,10 @@ def __init__(self, channel, can_filters=None, **kwargs):
self.channel_info = channel_info

flags = 0
if exclusive:
flags |= canstat.canOPEN_EXCLUSIVE
if override_exclusive:
flags |= canstat.canOPEN_OVERRIDE_EXCLUSIVE
if accept_virtual:
flags |= canstat.canOPEN_ACCEPT_VIRTUAL
if fd:
Expand Down Expand Up @@ -491,7 +501,12 @@ def __init__(self, channel, can_filters=None, **kwargs):
self._write_handle = self._read_handle
else:
log.debug("Creating separate handle for TX on channel: %s", channel)
self._write_handle = canOpenChannel(channel, flags)
if exclusive:
flags_ = flags & ~canstat.canOPEN_EXCLUSIVE
flags_ |= canstat.canOPEN_OVERRIDE_EXCLUSIVE
else:
flags_ = flags
self._write_handle = canOpenChannel(channel, flags_)
canBusOn(self._read_handle)

can_driver_mode = (
Expand Down
2 changes: 2 additions & 0 deletions can/interfaces/kvaser/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ def CANSTATUS_SUCCESS(status):
canDRIVER_SELFRECEPTION = 8
canDRIVER_OFF = 0

canOPEN_EXCLUSIVE = 0x0008
canOPEN_REQUIRE_EXTENDED = 0x0010
canOPEN_ACCEPT_VIRTUAL = 0x0020
canOPEN_OVERRIDE_EXCLUSIVE = 0x0040
canOPEN_REQUIRE_INIT_ACCESS = 0x0080
Expand Down