Skip to content

uc480: linux support and bugfixes #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pylablib/devices/uc480/uc480_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@ class ERROR(enum.IntEnum):
IS_ERROR_CPU_IDLE_STATES_CONFIGURATION = _int32(204)
IS_DEVICE_BUSY = _int32(205)
IS_SENSOR_INITIALIZATION_FAILED = _int32(206)
IS_IMAGE_BUFFER_NOT_DWORD_ALIGNED = _int32(207)
IS_SEQ_BUFFER_IS_LOCKED = _int32(208)
IS_FILE_PATH_DOES_NOT_EXIST = _int32(209)
IS_INVALID_WINDOW_HANDLE = _int32(210)
IS_INVALID_IMAGE_PARAMETER = _int32(211)
IS_NO_SUCH_DEVICE = _int32(212)
IS_DEVICE_IN_USE = _int32(213)
dERROR={a.name:a.value for a in ERROR}
drERROR={a.value:a.name for a in ERROR}

Expand Down Expand Up @@ -1460,9 +1467,9 @@ class MULTICAST(enum.IntEnum):
ULONG_PTR=ctypes.c_uint64
LONG_PTR=ctypes.c_int64
WORD=ctypes.c_ushort
DWORD=ctypes.c_ulong
DWORD=ctypes.c_uint32
LPWORD=ctypes.POINTER(WORD)
ULONG=ctypes.c_ulong
ULONG=ctypes.c_uint32
LONGLONG=ctypes.c_int64
LPLONG=ctypes.POINTER(ctypes.c_long)
INT=ctypes.c_int
Expand Down
26 changes: 18 additions & 8 deletions pylablib/devices/uc480/uc480_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,22 @@ def __init__(self, backend="uc480"):

@staticmethod
def _load_dll(backend):
if backend=="uc480":
if backend=="uc480": # windows-only
lib_name="uc480.dll" if platform.architecture()[0][:2]=="32" else "uc480_64.dll"
dcx_path=load_lib.get_program_files_folder("Thorlabs/Scientific Imaging/DCx Camera Support/USB Driver Package")
thorcam_path=load_lib.get_program_files_folder("Thorlabs/Scientific Imaging/ThorCam")
error_message="The library is automatically supplied with Thorcam software\n"+load_lib.par_error_message.format("uc480")
return load_lib.load_lib(lib_name,locations=("parameter/uc480",thorcam_path,"global"),error_message=error_message,call_conv="cdecl")
return load_lib.load_lib(lib_name,locations=("parameter/uc480",dcx_path,thorcam_path,"global"),error_message=error_message,call_conv="cdecl")
elif backend=="ueye":
lib_name="ueye_api.dll" if platform.architecture()[0][:2]=="32" else "ueye_api_64.dll"
ueye_path=load_lib.get_program_files_folder("IDS/uEye/USB driver package")
ids_path=load_lib.get_program_files_folder("IDS/uEye/develop/bin")
lib_name,ueye_path,ids_path=None,None,None
if platform.system() == 'Windows':
lib_name="ueye_api.dll" if platform.architecture()[0][:2]=="32" else "ueye_api_64.dll"
ueye_path=load_lib.get_program_files_folder("IDS/uEye/USB driver package")
ids_path=load_lib.get_program_files_folder("IDS/uEye/develop/bin")
else: # TODO: other OSes? this assumes Linux
lib_name="libueye_api.so"
ueye_path="/opt/ids/ueye/lib"
ids_path="/opt/ids/ueye/lib/x86_64-linux-gnu"
error_message="The library is automatically supplied with IDS uEye or IDS Software Suite\n"+load_lib.par_error_message.format("ueye")
return load_lib.load_lib(lib_name,locations=("parameter/ueye",ueye_path,ids_path,"global"),error_message=error_message,call_conv="cdecl")
else:
Expand Down Expand Up @@ -441,10 +448,13 @@ def is_GetCameraList(self):
ncam=self.is_GetNumberOfCameras()
if ncam==0:
return []
assert ncam > 0 and ncam < (1<<12), ("Weird 'ncam' value: %d"%ncam)

for _ in range(10):
class UC480_CAMERA_LIST(ctypes.Structure):
_fields_=[ ("dwCount",ctypes.c_ulong),
_fields_=[ ("dwCount",ctypes.c_uint32),
("uci",UC480_CAMERA_INFO*ncam) ]

cam_lst=UC480_CAMERA_LIST()
cam_lst.dwCount=ncam
self.is_GetCameraList_lib(ctypes.pointer(cam_lst))
Expand All @@ -453,7 +463,7 @@ class UC480_CAMERA_LIST(ctypes.Structure):
else:
ncam=cam_lst.dwCount
raise uc480Error("can not obtain the camera list: the list size keeps changing")

def is_GetCaptureStatus(self, hcam):
status=uc480_defs.UC480_CAPTURE_STATUS_INFO()
self.is_CaptureStatus(hcam,uc480_defs.CAPTURE_STATUS_CMD.IS_CAPTURE_STATUS_INFO_CMD_GET,ctypes.byref(status),ctypes.sizeof(status))
Expand All @@ -469,4 +479,4 @@ def get_lib(backend):
lib=libs[backend]
lib.initlib()
return lib
raise ValueError("unrecognized backend '{}'; available backends are {}".format(backend,list(libs)))
raise ValueError("unrecognized backend '{}'; available backends are {}".format(backend,list(libs)))