Skip to content

Commit a9d03da

Browse files
authored
Merge pull request hardbyte#865 from hardbyte/neovi-set-bitrate-error
Raising more precise API error when set bitrate fails
2 parents c77739b + cc4be08 commit a9d03da

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

can/interfaces/ics_neovi/neovi_bus.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,24 @@ 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+
if kwargs.get("fd", False):
167+
if "data_bitrate" in kwargs:
168+
for channel in self.channels:
169+
ics.set_fd_bit_rate(
170+
self.dev, kwargs.get("data_bitrate"), channel
171+
)
172+
except ics.RuntimeError as re:
173+
logger.error(re)
174+
err = ICSApiError(*ics.get_last_api_error(self.dev))
175+
try:
176+
self.shutdown()
177+
finally:
178+
raise err
170179

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

0 commit comments

Comments
 (0)