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