Skip to content

Commit 8e98b74

Browse files
authored
Merge branch 'develop' into bit-timing-class
2 parents fa3ab30 + 833c4f5 commit 8e98b74

5 files changed

Lines changed: 58 additions & 9 deletions

File tree

CONTRIBUTORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ Alexander Mueller<XelaRellum@web.de>
2727
Jan Goeteyn
2828
"ykzheng" <wishdo@gmail.com>
2929
Lear Corporation
30+
Nick Black <dank@qemfd.net>

can/interfaces/canalystii.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,25 @@ class VCI_CAN_OBJ(Structure):
7373

7474
class CANalystIIBus(BusABC):
7575
def __init__(
76-
self, channel, device=0, baud=None, Timing0=None, Timing1=None, can_filters=None
76+
self,
77+
channel,
78+
device=0,
79+
bitrate=None,
80+
Timing0=None,
81+
Timing1=None,
82+
can_filters=None,
83+
**kwargs,
7784
):
7885
"""
7986
8087
:param channel: channel number
8188
:param device: device number
82-
:param baud: baud rate
83-
:param Timing0: customize the timing register if baudrate is not specified
89+
:param bitrate: CAN network bandwidth (bits/s)
90+
:param Timing0: customize the timing register if bitrate is not specified
8491
:param Timing1:
8592
:param can_filters: filters for packet
8693
"""
87-
super().__init__(channel, can_filters)
94+
super().__init__(channel=channel, can_filters=can_filters, **kwargs)
8895

8996
if isinstance(channel, (list, tuple)):
9097
self.channels = channel
@@ -100,11 +107,11 @@ def __init__(
100107
self.device, self.channels
101108
)
102109

103-
if baud is not None:
110+
if bitrate is not None:
104111
try:
105-
Timing0, Timing1 = TIMING_DICT[baud]
112+
Timing0, Timing1 = TIMING_DICT[bitrate]
106113
except KeyError:
107-
raise ValueError("Baudrate is not supported")
114+
raise ValueError("Bitrate is not supported")
108115

109116
if Timing0 is None or Timing1 is None:
110117
raise ValueError("Timing registers are not set")

can/interfaces/ics_neovi/neovi_bus.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"""
1212

1313
import logging
14+
import os
15+
import tempfile
1416
from collections import deque
1517

1618
from can import Message, CanError, BusABC
@@ -28,6 +30,35 @@
2830
ics = None
2931

3032

33+
try:
34+
from filelock import FileLock
35+
except ImportError as ie:
36+
37+
logger.warning(
38+
"Using ICS NeoVi can backend without the "
39+
"filelock module installed may cause some issues!: %s",
40+
ie,
41+
)
42+
43+
class FileLock:
44+
"""Dummy file lock that does not actually do anything"""
45+
46+
def __init__(self, lock_file, timeout=-1):
47+
self._lock_file = lock_file
48+
self.timeout = timeout
49+
50+
def __enter__(self):
51+
return self
52+
53+
def __exit__(self, exc_type, exc_val, exc_tb):
54+
return None
55+
56+
57+
# Use inter-process mutex to prevent concurrent device open.
58+
# When neoVI server is enabled, there is an issue with concurrent device open.
59+
open_lock = FileLock(os.path.join(tempfile.gettempdir(), "neovi.lock"))
60+
61+
3162
class ICSApiError(CanError):
3263
"""
3364
Indicates an error with the ICS API.
@@ -122,7 +153,9 @@ def __init__(self, channel, can_filters=None, **kwargs):
122153
type_filter = kwargs.get("type_filter")
123154
serial = kwargs.get("serial")
124155
self.dev = self._find_device(type_filter, serial)
125-
ics.open_device(self.dev)
156+
157+
with open_lock:
158+
ics.open_device(self.dev)
126159

127160
if "bitrate" in kwargs:
128161
for channel in self.channels:

doc/configuration.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,7 @@ Lookup table of interface names:
126126
+---------------------+-------------------------------------+
127127
| ``"virtual"`` | :doc:`interfaces/virtual` |
128128
+---------------------+-------------------------------------+
129+
| ``"canalystii"`` | :doc:`interfaces/canalystii` |
130+
+---------------------+-------------------------------------+
131+
| ``"systec"`` | :doc:`interfaces/systec` |
132+
+---------------------+-------------------------------------+

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
long_description = f.read()
2525

2626
# Dependencies
27-
extras_require = {"serial": ["pyserial~=3.0"], "neovi": ["python-ics>=2.12"]}
27+
extras_require = {
28+
"serial": ["pyserial~=3.0"],
29+
"neovi": ["python-ics>=2.12", "filelock"],
30+
}
2831

2932
tests_require = [
3033
"pytest~=4.3",
@@ -90,6 +93,7 @@
9093
"wrapt~=1.10",
9194
"aenum",
9295
'windows-curses;platform_system=="Windows"',
96+
"filelock",
9397
],
9498
setup_requires=["pytest-runner"],
9599
extras_require=extras_require,

0 commit comments

Comments
 (0)