Skip to content

Commit f3fa071

Browse files
luojiaaooluoja
andauthored
Kvaser: add parameter exclusive and override_exclusive (#1660)
* * 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]>
1 parent 40c7791 commit f3fa071

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

can/interfaces/kvaser/canlib.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ def __init__(self, channel, can_filters=None, **kwargs):
404404
computer, set this to True or set single_handle to True.
405405
:param bool fd:
406406
If CAN-FD frames should be supported.
407+
:param bool exclusive:
408+
Don't allow sharing of this CANlib channel.
409+
:param bool override_exclusive:
410+
Open the channel even if it is opened for exclusive access already.
407411
:param int data_bitrate:
408412
Which bitrate to use for data phase in CAN FD.
409413
Defaults to arbitration bitrate.
@@ -420,6 +424,8 @@ def __init__(self, channel, can_filters=None, **kwargs):
420424
driver_mode = kwargs.get("driver_mode", DRIVER_MODE_NORMAL)
421425
single_handle = kwargs.get("single_handle", False)
422426
receive_own_messages = kwargs.get("receive_own_messages", False)
427+
exclusive = kwargs.get("exclusive", False)
428+
override_exclusive = kwargs.get("override_exclusive", False)
423429
accept_virtual = kwargs.get("accept_virtual", True)
424430
fd = kwargs.get("fd", False)
425431
data_bitrate = kwargs.get("data_bitrate", None)
@@ -445,6 +451,10 @@ def __init__(self, channel, can_filters=None, **kwargs):
445451
self.channel_info = channel_info
446452

447453
flags = 0
454+
if exclusive:
455+
flags |= canstat.canOPEN_EXCLUSIVE
456+
if override_exclusive:
457+
flags |= canstat.canOPEN_OVERRIDE_EXCLUSIVE
448458
if accept_virtual:
449459
flags |= canstat.canOPEN_ACCEPT_VIRTUAL
450460
if fd:
@@ -491,7 +501,12 @@ def __init__(self, channel, can_filters=None, **kwargs):
491501
self._write_handle = self._read_handle
492502
else:
493503
log.debug("Creating separate handle for TX on channel: %s", channel)
494-
self._write_handle = canOpenChannel(channel, flags)
504+
if exclusive:
505+
flags_ = flags & ~canstat.canOPEN_EXCLUSIVE
506+
flags_ |= canstat.canOPEN_OVERRIDE_EXCLUSIVE
507+
else:
508+
flags_ = flags
509+
self._write_handle = canOpenChannel(channel, flags_)
495510
canBusOn(self._read_handle)
496511

497512
can_driver_mode = (

can/interfaces/kvaser/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ def CANSTATUS_SUCCESS(status):
161161
canDRIVER_SELFRECEPTION = 8
162162
canDRIVER_OFF = 0
163163

164+
canOPEN_EXCLUSIVE = 0x0008
165+
canOPEN_REQUIRE_EXTENDED = 0x0010
164166
canOPEN_ACCEPT_VIRTUAL = 0x0020
165167
canOPEN_OVERRIDE_EXCLUSIVE = 0x0040
166168
canOPEN_REQUIRE_INIT_ACCESS = 0x0080

0 commit comments

Comments
 (0)