Skip to content
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

fix dll path issue with Twincat 4026 #393

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 11 additions & 6 deletions pyads/pyads_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,26 @@

# load dynamic ADS library
if platform_is_windows(): # pragma: no cover, skip Windows test
dlldir_handle = None
dlldir_handle = []
if sys.version_info >= (3, 8) and "TWINCAT3DIR" in os.environ:
# Starting with version 3.8, CPython does not consider the PATH environment
# variable any more when resolving DLL paths. The following works with the default
# installation of the Beckhoff TwinCAT ADS DLL.
dll_path = os.environ["TWINCAT3DIR"] + "\\..\\AdsApi\\TcAdsDll"
dll_path = os.environ["TWINCAT3DIR"]
# 20240620 update with the versoin 4026
dll_path_v4023 = os.path.join(dll_path, "\\..\\AdsApi\\TcAdsDll")
dll_path_v4026 = os.path.join(dll_path, "..")
if platform.architecture()[0] == "64bit":
dll_path += "\\x64"
dlldir_handle = os.add_dll_directory(dll_path)
dll_path_v4023 += "\\x64"
dll_path_v4026 += "\\Common64"
dlldir_handle.append(os.add_dll_directory(dll_path_v4023))
dlldir_handle.append(os.add_dll_directory(dll_path_v4026))
try:
_adsDLL = ctypes.WinDLL("TcAdsDll.dll") # type: ignore
finally:
if dlldir_handle:
for handle in dlldir_handle:
# Do not clobber the load path for other modules
dlldir_handle.close()
handle.close()
NOTEFUNC = ctypes.WINFUNCTYPE( # type: ignore
ctypes.c_void_p,
ctypes.POINTER(SAmsAddr),
Expand Down