Skip to content

Commit 436e78f

Browse files
committed
Raising more precise API error when set bitrate fails
Also calling shutdown before raising exception from the init if the device is opened
1 parent 343a0d7 commit 436e78f

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

can/interfaces/ics_neovi/neovi_bus.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,25 @@ def __init__(self, channel, can_filters=None, **kwargs):
158158
with open_lock:
159159
ics.open_device(self.dev)
160160

161-
if "bitrate" in kwargs:
162-
for channel in self.channels:
163-
ics.set_bit_rate(self.dev, kwargs.get("bitrate"), channel)
164-
165-
fd = kwargs.get("fd", False)
166-
if fd:
167-
if "data_bitrate" in kwargs:
161+
try:
162+
if "bitrate" in kwargs:
168163
for channel in self.channels:
169-
ics.set_fd_bit_rate(self.dev, kwargs.get("data_bitrate"), channel)
164+
ics.set_bit_rate(self.dev, kwargs.get("bitrate"), channel)
165+
166+
fd = kwargs.get("fd", False)
167+
if fd:
168+
if "data_bitrate" in kwargs:
169+
for channel in self.channels:
170+
ics.set_fd_bit_rate(
171+
self.dev, kwargs.get("data_bitrate"), channel
172+
)
173+
except ics.RuntimeError as re:
174+
logger.error(re)
175+
err = ICSApiError(*ics.get_last_api_error(self.dev))
176+
try:
177+
self.shutdown()
178+
finally:
179+
raise err
170180

171181
self._use_system_timestamp = bool(kwargs.get("use_system_timestamp", False))
172182
self._receive_own_messages = kwargs.get("receive_own_messages", True)

0 commit comments

Comments
 (0)