Skip to content

Commit

Permalink
Kvaser: add parameter exclusive and override_exclusive (#1660)
Browse files Browse the repository at this point in the history
* * For interface Kvaser, add parameter exclusive
Don't allow sharing of this CANlib channel.

*  For interface Kvaser, add parameter override_exclusive
Open the channel even if it is opened for exclusive access already.

* fix

---------

Co-authored-by: luoja <[email protected]>
  • Loading branch information
luojiaaoo and luoja authored Sep 12, 2023
1 parent 40c7791 commit f3fa071
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit f3fa071

Please sign in to comment.