10000 Supress exception occuring in NIXNET _detect_available_configs() (#1085) · projectgus/python-can@c64f162 · GitHub
[go: up one dir, main page]

Skip to content

Commit c64f162

Browse files
Supress exception occuring in NIXNET _detect_available_configs() (hardbyte#1085)
* Supress exception occuring in NIXNET _detect_available_configs() * Format code with black * fix error import * Format code with black Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 0262b8d commit c64f162

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

can/interfaces/nixnet.py

Lines changed: 28 additions & 13 deletions
85E9
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@
1919

2020
if sys.platform == "win32":
2121
try:
22-
from nixnet import session, types, constants, errors, system, database
22+
from nixnet import (
23+
session,
24+
types,
25+
constants,
26+
errors,
27+
system,
28+
database,
29+
XnetError,
30+
)
2331
except ImportError:
2432
logger.error("Error, NIXNET python module cannot be loaded.")
2533
raise ImportError()
@@ -225,18 +233,25 @@ def shutdown(self):
225233
@staticmethod
226234
def _detect_available_configs():
227235
configs = []
228-
nixnet_system = system.System()
229-
for can_intf in nixnet_system.intf_refs_can:
230-
logger.info("Channel index %d: %s", can_intf.port_num, str(can_intf))
231-
configs.append(
232-
{
233-
"interface": "nixnet",
234-
"channel": str(can_intf),
235-
"can_term_available": can_intf.can_term_cap
236-
== constants.CanTermCap.YES,
237-
}
238-
)
239-
nixnet_system.close()
236+
237+
try:
238+
with system.System() as nixnet_system:
239+
for interface in nixnet_system.intf_refs_can:
240+
cahnnel = str(interface)
241+
logger.debug(
242+
"Found channel index %d: %s", interface.port_num, cahnnel
243+
)
244+
configs.append(
245+
{
246+
"interface": "nixnet",
247+
"channel": cahnnel,
248+
"can_term_available": interface.can_term_cap
249+
== constants.CanTermCap.YES,
250+
}
251+
)
252+
except XnetError as error:
253+
logger.debug("An error occured while searching for configs: %s", str(error))
254+
240255
return configs
241256

242257

0 commit comments

Comments
 (0)
0