diff --git a/can/interfaces/vector/canlib.py b/can/interfaces/vector/canlib.py index 797539c88..a6d8fb84b 100644 --- a/can/interfaces/vector/canlib.py +++ b/can/interfaces/vector/canlib.py @@ -51,7 +51,7 @@ xldriver: Optional[ModuleType] = None try: from . import xldriver -except Exception as exc: +except FileNotFoundError as exc: LOG.warning("Could not import vxlapi: %s", exc) WaitForSingleObject: Optional[Callable[[int, int], int]] diff --git a/can/interfaces/vector/xldriver.py b/can/interfaces/vector/xldriver.py index 2af90c728..faed23b36 100644 --- a/can/interfaces/vector/xldriver.py +++ b/can/interfaces/vector/xldriver.py @@ -8,6 +8,7 @@ import ctypes import logging import platform +from ctypes.util import find_library from . import xlclass from .exceptions import VectorInitializationError, VectorOperationError @@ -16,8 +17,10 @@ # Load Windows DLL DLL_NAME = "vxlapi64" if platform.architecture()[0] == "64bit" else "vxlapi" -_xlapi_dll = ctypes.windll.LoadLibrary(DLL_NAME) - +if dll_path := find_library(DLL_NAME): + _xlapi_dll = ctypes.windll.LoadLibrary(dll_path) +else: + raise FileNotFoundError(f"Vector XL library not found: {DLL_NAME}") # ctypes wrapping for API functions xlGetErrorString = _xlapi_dll.xlGetErrorString