Skip to content

Commit

Permalink
Universal DLL path for 4024 / 4026 (#402)
Browse files Browse the repository at this point in the history
Co-authored-by: Christopher Beard <christopherb@huxleybertram.com>
  • Loading branch information
chrisbeardy and Christopher Beard authored Jul 31, 2024
1 parent fe07fd1 commit bb94901
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## 3.4.2

### Changed

* [#402](https://github.com/stlehmann/pyads/pull/402) Universal DLL path for TwinCat 4026 and 4024

## 3.4.1

### Changed
Expand Down Expand Up @@ -111,7 +117,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed
* fixed error with source distribution not containing adslib directory

### Removed

## 3.3.1
Expand Down
2 changes: 1 addition & 1 deletion pyads/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@

from .symbol import AdsSymbol

__version__ = '3.4.1'
__version__ = '3.4.2'
20 changes: 7 additions & 13 deletions pyads/pyads_ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,16 @@
# load dynamic ADS library
if platform_is_windows(): # pragma: no cover, skip Windows test
dlldir_handle = None
if sys.version_info >= (3, 8):
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.
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)
dll_path = os.environ["TWINCAT3DIR"] + "\\.."
if platform.architecture()[0] == "64bit":
dll_path += "\\Common64"
else:
dll_path += "\\Common32"
dlldir_handle = os.add_dll_directory(dll_path)
try:
_adsDLL = ctypes.WinDLL("TcAdsDll.dll") # type: ignore
finally:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ commands = discover
deps = discover
changedir = tests
whitelist_externals=*
passenv = TWINCATSDK TWINCAT3DIR
passenv = TWINCAT3DIR

[pytest]
testpaths = tests

0 comments on commit bb94901

Please sign in to comment.