Skip to content

Commit

Permalink
Added TWINCATSDK environment variable to resolve Windows TcAdsll.dll …
Browse files Browse the repository at this point in the history
…(4026) (#389)
  • Loading branch information
vincent-hve authored Jul 30, 2024
1 parent 8086c9f commit f014aee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pyads/pyads_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@
# load dynamic ADS library
if platform_is_windows(): # pragma: no cover, skip Windows test
dlldir_handle = None
if sys.version_info >= (3, 8) and "TWINCAT3DIR" in os.environ:
if sys.version_info >= (3, 8):
# 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"
if platform.architecture()[0] == "64bit":
dll_path += "\\x64"
dlldir_handle = os.add_dll_directory(dll_path)
if "TWINCATSDK" in os.environ:
dll_path = os.environ["TWINCATSDK"] + "\\..\\.."
if platform.architecture()[0] == "64bit":
dll_path += "\\Common64"
else:
dll_path += "\\Common32"
dlldir_handle = os.add_dll_directory(dll_path)
elif "TWINCAT3DIR" in os.environ:
dll_path = os.environ["TWINCAT3DIR"] + "\\..\\AdsApi\\TcAdsDll"
if platform.architecture()[0] == "64bit":
dll_path += "\\x64"
dlldir_handle = os.add_dll_directory(dll_path)
try:
_adsDLL = ctypes.WinDLL("TcAdsDll.dll") # type: ignore
finally:
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ commands = discover
deps = discover
changedir = tests
whitelist_externals=*
passenv = TWINCATSDK TWINCAT3DIR

[pytest]
testpaths = tests

0 comments on commit f014aee

Please sign in to comment.