Skip to content

Commit a2ddb51

Browse files
authored
Use ctypes.util.find_library to find vxlapi.dll (#1731)
1 parent 4e39768 commit a2ddb51

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

can/interfaces/vector/canlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
xldriver: Optional[ModuleType] = None
5252
try:
5353
from . import xldriver
54-
except Exception as exc:
54+
except FileNotFoundError as exc:
5555
LOG.warning("Could not import vxlapi: %s", exc)
5656

5757
WaitForSingleObject: Optional[Callable[[int, int], int]]

can/interfaces/vector/xldriver.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import ctypes
99
import logging
1010
import platform
11+
from ctypes.util import find_library
1112

1213
from . import xlclass
1314
from .exceptions import VectorInitializationError, VectorOperationError
@@ -16,8 +17,10 @@
1617

1718
# Load Windows DLL
1819
DLL_NAME = "vxlapi64" if platform.architecture()[0] == "64bit" else "vxlapi"
19-
_xlapi_dll = ctypes.windll.LoadLibrary(DLL_NAME)
20-
20+
if dll_path := find_library(DLL_NAME):
21+
_xlapi_dll = ctypes.windll.LoadLibrary(dll_path)
22+
else:
23+
raise FileNotFoundError(f"Vector XL library not found: {DLL_NAME}")
2124

2225
# ctypes wrapping for API functions
2326
xlGetErrorString = _xlapi_dll.xlGetErrorString

0 commit comments

Comments
 (0)