1
This commit is contained in:
@@ -1,43 +1,40 @@
|
|||||||
import ctypes
|
import ctypes
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
# Add DLL directory to PATH
|
|
||||||
dll_dir = os.path.join(os.path.dirname(__file__), "libs")
|
|
||||||
old_path = os.environ.get("PATH", "")
|
|
||||||
os.environ["PATH"] = dll_dir + os.pathsep + old_path
|
|
||||||
|
|
||||||
# Load DLL with stdcall convention
|
|
||||||
if hasattr(os, "add_dll_directory"):
|
|
||||||
os.add_dll_directory(dll_dir)
|
|
||||||
lib = ctypes.windll.LoadLibrary("atcore.dll")
|
|
||||||
else:
|
|
||||||
dll_path = os.path.join(dll_dir, "atcore.dll")
|
|
||||||
lib = ctypes.windll.LoadLibrary(dll_path)
|
|
||||||
|
|
||||||
# Restore PATH
|
|
||||||
os.environ["PATH"] = old_path
|
|
||||||
|
|
||||||
# Type definitions
|
# Type definitions
|
||||||
AT_H = ctypes.c_int
|
AT_H = ctypes.c_int
|
||||||
AT_64 = ctypes.c_longlong
|
AT_64 = ctypes.c_longlong
|
||||||
|
AT_BOOL = ctypes.c_int
|
||||||
|
|
||||||
# Constants
|
# Constants
|
||||||
AT_SUCCESS = 0
|
AT_SUCCESS = 0
|
||||||
AT_HANDLE_SYSTEM = 1
|
AT_HANDLE_SYSTEM = 1
|
||||||
|
|
||||||
# Define AT_InitialiseLibrary
|
# Load DLL
|
||||||
|
dll_dir = os.path.join(os.path.dirname(__file__), "libs")
|
||||||
|
old_path = os.environ.get("PATH", "")
|
||||||
|
os.environ["PATH"] = dll_dir + os.pathsep + old_path
|
||||||
|
|
||||||
|
try:
|
||||||
|
if hasattr(os, "add_dll_directory"):
|
||||||
|
with os.add_dll_directory(dll_dir):
|
||||||
|
lib = ctypes.windll.LoadLibrary("atcore.dll")
|
||||||
|
else:
|
||||||
|
lib = ctypes.windll.LoadLibrary(os.path.join(dll_dir, "atcore.dll"))
|
||||||
|
finally:
|
||||||
|
os.environ["PATH"] = old_path
|
||||||
|
|
||||||
|
# Define functions
|
||||||
lib.AT_InitialiseLibrary.argtypes = []
|
lib.AT_InitialiseLibrary.argtypes = []
|
||||||
lib.AT_InitialiseLibrary.restype = ctypes.c_int
|
lib.AT_InitialiseLibrary.restype = ctypes.c_int
|
||||||
|
|
||||||
# Define AT_GetInt
|
|
||||||
lib.AT_GetInt.argtypes = [AT_H, ctypes.c_wchar_p, ctypes.POINTER(AT_64)]
|
lib.AT_GetInt.argtypes = [AT_H, ctypes.c_wchar_p, ctypes.POINTER(AT_64)]
|
||||||
lib.AT_GetInt.restype = ctypes.c_int
|
lib.AT_GetInt.restype = ctypes.c_int
|
||||||
|
|
||||||
# Define AT_FinaliseLibrary
|
|
||||||
lib.AT_FinaliseLibrary.argtypes = []
|
lib.AT_FinaliseLibrary.argtypes = []
|
||||||
lib.AT_FinaliseLibrary.restype = ctypes.c_int
|
lib.AT_FinaliseLibrary.restype = ctypes.c_int
|
||||||
|
|
||||||
|
# Initialize library
|
||||||
print("Initializing library...")
|
print("Initializing library...")
|
||||||
ret = lib.AT_InitialiseLibrary()
|
ret = lib.AT_InitialiseLibrary()
|
||||||
if ret != AT_SUCCESS:
|
if ret != AT_SUCCESS:
|
||||||
@@ -53,7 +50,7 @@ if ret != AT_SUCCESS:
|
|||||||
else:
|
else:
|
||||||
print(f"Device count: {device_count.value}")
|
print(f"Device count: {device_count.value}")
|
||||||
|
|
||||||
# Finalize
|
# Finalize library
|
||||||
ret = lib.AT_FinaliseLibrary()
|
ret = lib.AT_FinaliseLibrary()
|
||||||
if ret != AT_SUCCESS:
|
if ret != AT_SUCCESS:
|
||||||
print(f"ERROR: Finalize failed, code: {ret}")
|
print(f"ERROR: Finalize failed, code: {ret}")
|
||||||
|
|||||||
Reference in New Issue
Block a user