1
This commit is contained in:
@@ -13,7 +13,7 @@ try:
|
||||
sdk_paths = [
|
||||
r"C:\Program Files\Andor SOLIS\atcore.dll",
|
||||
r"C:\Program Files\Andor SDK3\atcore.dll",
|
||||
"atcore.dll" # Try system PATH
|
||||
"atcore.dll", # Try system PATH
|
||||
]
|
||||
|
||||
lib = None
|
||||
@@ -21,13 +21,15 @@ try:
|
||||
if os.path.exists(path) or path == "atcore.dll":
|
||||
try:
|
||||
lib = ctypes.WinDLL(path)
|
||||
print(f" Loaded SDK from: {path}")
|
||||
print(f"Loaded SDK from: {path}")
|
||||
break
|
||||
except OSError:
|
||||
continue
|
||||
|
||||
if lib is None:
|
||||
raise OSError("Could not find atcore.dll. Please install Andor SDK3 or Andor SOLIS.")
|
||||
raise OSError(
|
||||
"Could not find atcore.dll. Please install Andor SDK3 or Andor SOLIS."
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
print(f" Failed to load Andor SDK3 library: {e}")
|
||||
@@ -47,13 +49,27 @@ lib.AT_Close.restype = ctypes.c_int
|
||||
lib.AT_Close.argtypes = [ctypes.c_int]
|
||||
|
||||
lib.AT_GetInt.restype = ctypes.c_int
|
||||
lib.AT_GetInt.argtypes = [ctypes.c_int, ctypes.c_wchar_p, ctypes.POINTER(ctypes.c_longlong)]
|
||||
lib.AT_GetInt.argtypes = [
|
||||
ctypes.c_int,
|
||||
ctypes.c_wchar_p,
|
||||
ctypes.POINTER(ctypes.c_longlong),
|
||||
]
|
||||
|
||||
lib.AT_GetString.restype = ctypes.c_int
|
||||
lib.AT_GetString.argtypes = [ctypes.c_int, ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_int]
|
||||
lib.AT_GetString.argtypes = [
|
||||
ctypes.c_int,
|
||||
ctypes.c_wchar_p,
|
||||
ctypes.c_wchar_p,
|
||||
ctypes.c_int,
|
||||
]
|
||||
|
||||
lib.AT_GetStringMaxLength.restype = ctypes.c_int
|
||||
lib.AT_GetStringMaxLength.argtypes = [ctypes.c_int, ctypes.c_wchar_p, ctypes.POINTER(ctypes.c_int)]
|
||||
lib.AT_GetStringMaxLength.argtypes = [
|
||||
ctypes.c_int,
|
||||
ctypes.c_wchar_p,
|
||||
ctypes.POINTER(ctypes.c_int),
|
||||
]
|
||||
|
||||
|
||||
# Error checking
|
||||
def check_error(code, func_name):
|
||||
@@ -62,12 +78,13 @@ def check_error(code, func_name):
|
||||
1: "NOT_INITIALISED",
|
||||
2: "NOT_IMPLEMENTED",
|
||||
12: "INVALID_HANDLE",
|
||||
39: "DEVICE_NOT_FOUND"
|
||||
39: "DEVICE_NOT_FOUND",
|
||||
}
|
||||
if code != 0:
|
||||
error = error_names.get(code, f"UNKNOWN({code})")
|
||||
raise RuntimeError(f"{func_name} failed with error: {error}")
|
||||
|
||||
|
||||
# Helper functions
|
||||
def get_int_feature(handle, feature):
|
||||
value = ctypes.c_longlong()
|
||||
@@ -75,6 +92,7 @@ def get_int_feature(handle, feature):
|
||||
check_error(code, f"AT_GetInt({feature})")
|
||||
return value.value
|
||||
|
||||
|
||||
def get_string_feature(handle, feature):
|
||||
max_len = ctypes.c_int()
|
||||
code = lib.AT_GetStringMaxLength(handle, feature, ctypes.byref(max_len))
|
||||
@@ -85,6 +103,7 @@ def get_string_feature(handle, feature):
|
||||
check_error(code, f"AT_GetString({feature})")
|
||||
return buffer.value
|
||||
|
||||
|
||||
# Main test code
|
||||
print("=" * 60)
|
||||
print("Andor SDK3 Camera Discovery Test")
|
||||
@@ -94,13 +113,13 @@ print("=" * 60)
|
||||
print("\n[1] Initializing Andor SDK3 library...")
|
||||
code = lib.AT_InitialiseLibrary()
|
||||
check_error(code, "AT_InitialiseLibrary")
|
||||
print(" Library initialized successfully")
|
||||
print("Library initialized successfully")
|
||||
|
||||
try:
|
||||
# Get number of cameras (using system handle = 1)
|
||||
print("\n[2] Detecting cameras...")
|
||||
num_cameras = get_int_feature(1, "DeviceCount")
|
||||
print(f" Found {num_cameras} camera(s)")
|
||||
print(f"Found {num_cameras} camera(s)")
|
||||
|
||||
if num_cameras == 0:
|
||||
print("\n<EFBFBD> No cameras detected. Please check:")
|
||||
@@ -113,7 +132,7 @@ try:
|
||||
handle = ctypes.c_int()
|
||||
code = lib.AT_Open(0, ctypes.byref(handle))
|
||||
check_error(code, "AT_Open")
|
||||
print(f" Camera opened (handle: {handle.value})")
|
||||
print(f"Camera opened (handle: {handle.value})")
|
||||
|
||||
try:
|
||||
# Get camera information
|
||||
@@ -147,21 +166,21 @@ try:
|
||||
pass
|
||||
|
||||
print("-" * 60)
|
||||
print(" Camera information retrieved successfully")
|
||||
print("Camera information retrieved successfully")
|
||||
|
||||
finally:
|
||||
# Close camera
|
||||
print("\n[5] Closing camera...")
|
||||
code = lib.AT_Close(handle.value)
|
||||
check_error(code, "AT_Close")
|
||||
print(" Camera closed")
|
||||
print("Camera closed")
|
||||
|
||||
finally:
|
||||
# Finalize library
|
||||
print("\n[6] Shutting down SDK library...")
|
||||
code = lib.AT_FinaliseLibrary()
|
||||
check_error(code, "AT_FinaliseLibrary")
|
||||
print(" Library shutdown complete")
|
||||
print("Library shutdown complete")
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("Test completed successfully!")
|
||||
|
||||
Reference in New Issue
Block a user