Skip to content

Use ctypes.util.find_library to find vxlapi dll #1731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion can/interfaces/vector/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down
7 changes: 5 additions & 2 deletions can/interfaces/vector/xldriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ctypes
import logging
import platform
from ctypes.util import find_library

from . import xlclass
from .exceptions import VectorInitializationError, VectorOperationError
Expand All @@ -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
Expand Down