59 lines
1.5 KiB
Python
59 lines
1.5 KiB
Python
import ctypes
|
|
import os
|
|
|
|
# Type definitions
|
|
AT_H = ctypes.c_int
|
|
AT_64 = ctypes.c_longlong
|
|
AT_BOOL = ctypes.c_int
|
|
|
|
# Constants
|
|
AT_SUCCESS = 0
|
|
AT_HANDLE_SYSTEM = 1
|
|
|
|
# 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.restype = ctypes.c_int
|
|
|
|
lib.AT_GetInt.argtypes = [AT_H, ctypes.c_wchar_p, ctypes.POINTER(AT_64)]
|
|
lib.AT_GetInt.restype = ctypes.c_int
|
|
|
|
lib.AT_FinaliseLibrary.argtypes = []
|
|
lib.AT_FinaliseLibrary.restype = ctypes.c_int
|
|
|
|
# Initialize library
|
|
print("Initializing library...")
|
|
ret = lib.AT_InitialiseLibrary()
|
|
if ret != AT_SUCCESS:
|
|
print(f"ERROR: Initialize failed, code: {ret}")
|
|
exit(1)
|
|
print("Initialize OK")
|
|
|
|
# Get device count
|
|
device_count = AT_64(0)
|
|
ret = lib.AT_GetInt(AT_HANDLE_SYSTEM, "DeviceCount", ctypes.byref(device_count))
|
|
if ret != AT_SUCCESS:
|
|
print(f"ERROR: Get device count failed, code: {ret}")
|
|
else:
|
|
print(f"Device count: {device_count.value}")
|
|
|
|
# Finalize library
|
|
ret = lib.AT_FinaliseLibrary()
|
|
if ret != AT_SUCCESS:
|
|
print(f"ERROR: Finalize failed, code: {ret}")
|
|
else:
|
|
print("Finalize OK")
|