9 log = logging.getLogger(__name__)
11 TYPE_CHAR20 = ctypes.c_char * 20
12 TYPE_CHAR32 = ctypes.c_char * 32
15 '''Class interface for the QHYCCD SDK
17 def __init__(self, dll_path='/usr/local/lib/libqhyccd.so'):
21 self.
_sdk_sdk = ctypes.CDLL(dll_path)
23 self.
_sdk_sdk.GetQHYCCDParam.restype = ctypes.c_double
24 self.
_sdk_sdk.OpenQHYCCD.restype = ctypes.POINTER(ctypes.c_uint32)
26 ret = self.
_sdk_sdk.InitQHYCCDResource()
32 self.
_sdk_sdk.GetQHYCCDId(ctypes.c_int(i), self.
_ids_ids[-1])
33 log.debug(
"Cameras {:d} ID {:s}".format(i, self.
_ids_ids[-1].value.decode(
'utf8')))
43 self.
_sdk_sdk.CloseQHYCCD(cam_handle)
46 self.
_sdk_sdk.ReleaseQHYCCDResource()
51 return [_id.value
for _id
in self.
_ids_ids]
79 param_min = ctypes.c_double
80 param_max = ctypes.c_double
81 param_step = ctypes.c_double
83 self.
_sdk_sdk.GetQHYCCDParamMinMaxStep(camera_handle, parameter, ctypes.byref(param_min), ctypes.byref(param_max), ctypes.byref(param_step))
85 return param_min.value, param_max.value, param_step.value
88 min_gain, max_gain, step_gain = self.
get_parameter_limitsget_parameter_limits(camera_handle, CONTROL_ID.CONTROL_GAIN)
89 min_exp, max_exp, step_exp = self.
get_parameter_limitsget_parameter_limits(camera_handle, CONTROL_ID.CONTROL_EXPOSURE)
92 'exp' : [min_exp, max_exp, step_exp],
93 'gain' : [min_gain, max_gain, step_gain]
96 return parameter_limits
100 chip_width = ctypes.c_double()
101 chip_height = ctypes.c_double()
102 width = ctypes.c_uint()
103 height = ctypes.c_uint()
104 pixel_width = ctypes.c_double()
105 pixel_height = ctypes.c_double()
106 channels = ctypes.c_uint32(1)
107 bpp = ctypes.c_uint()
109 self.
_sdk_sdk.GetQHYCCDChipInfo(camera_handle, ctypes.byref(chip_width), ctypes.byref(chip_height), ctypes.byref(width), ctypes.byref(height), ctypes.byref(pixel_width), ctypes.byref(pixel_height), ctypes.byref(bpp))
112 'physical' : [chip_width.value, chip_height.value],
113 'size' : [width.value, height.value],
114 'pixel_size' : [pixel_width.value, pixel_height.value],
115 'channels' : channels.value,
128 year = ctypes.c_uint32()
129 month = ctypes.c_uint32()
130 day = ctypes.c_uint32()
131 subday = ctypes.c_uint32()
134 ret = self.
_sdk_sdk.GetQHYCCDSDKVersion(ctypes.byref(year), ctypes.byref(month), ctypes.byref(day), ctypes.byref(subday))
135 return '{:d}-{:>02d}-{:>02d}'.format(2000 + year.value, month.value, day.value)
138 self.
_sdk_sdk.SetQHYCCDParam(camera_handle, parameter, value)
141 return self.
_sdk_sdk.GetQHYCCDParam(camera_handle, parameter)
144 ''' A class that interface with the QHYCCD series of cameras.
169 self.
_sdk_sdk.set_parameter(self.
_camera_camera, CONTROL_ID.CONTROL_USBTRAFFIC, ctypes.c_double(50))
170 self.
_sdk_sdk.set_parameter(self.
_camera_camera, CONTROL_ID.CONTROL_TRANSFERBIT, self.
_bpp_bpp)
182 return self.
_sdk_sdk.get_parameter(self.
_camera_camera, CONTROL_ID.CONTROL_COOLER)
184 @target_temperature.setter
193 @exposure_time.setter
198 self.
_sdk_sdk.set_parameter(self.
_camera_camera, CONTROL_ID.CONTROL_EXPOSURE, ctypes.c_double(self.
_exposure_time_exposure_time * 1e6))
199 log.debug(
"Set exposure time to", self.
_sdk_sdk.get_parameter(self.
_camera_camera, CONTROL_ID.CONTROL_EXPOSURE) / 1e6)
203 return self.
_gain_gain
208 self.
_sdk_sdk.set_parameter(self.
_camera_camera, CONTROL_ID.CONTROL_GAIN, ctypes.c_double(self.
_gain_gain))
213 return self.
_bpp_bpp.value
217 self.
_bpp_bpp = ctypes.c_double(new_bpp)
218 self.
_sdk_sdk.set_parameter(self.
_camera_camera, CONTROL_ID.CONTROL_TRANSFERBIT, self.
_bpp_bpp)
223 self.
_roi_h_roi_h = ctypes.c_uint(roi_h)
225 if self.
_bpp_bpp.value == 16:
226 self.
_imgdata_imgdata = (ctypes.c_uint16 * roi_w * roi_h)()
227 self.
_sdk_sdk._sdk.SetQHYCCDResolution(self.
_camera_camera, ctypes.c_uint(x0), ctypes.c_uint(y0), self.
_roi_w_roi_w, self.
_roi_h_roi_h)
229 self.
_imgdata_imgdata = (ctypes.c_uint8 * roi_w * roi_h)()
230 self.
_sdk_sdk._sdk.SetQHYCCDResolution(self.
_camera_camera, ctypes.c_uint(x0), ctypes.c_uint(y0), self.
_roi_w_roi_w, self.
_roi_h_roi_h)
233 ret = self.
_sdk_sdk._sdk.ExpQHYCCDSingleFrame(self.
_camera_camera)
236 percentage_complete = self.
_sdk_sdk._sdk.GetQHYCCDExposureRemaining(self.
_camera_camera)
247 ret = self.
_sdk_sdk._sdk.GetQHYCCDSingleFrame(self.
_camera_camera, ctypes.byref(self.
_roi_w_roi_w), ctypes.byref(self.
_roi_h_roi_h), ctypes.byref(self.
_bpp_bpp), ctypes.byref(self.
_channels_channels), self.
_imgdata_imgdata)
248 return np.asarray(self.
_imgdata_imgdata)
251 ret = self.
_sdk_sdk._sdk.ExpQHYCCDSingleFrame(self.
_camera_camera)
252 ret = self.
_sdk_sdk._sdk.GetQHYCCDSingleFrame(self.
_camera_camera, ctypes.byref(self.
_roi_w_roi_w), ctypes.byref(self.
_roi_h_roi_h), ctypes.byref(self.
_bpp_bpp), ctypes.byref(self.
_channels_channels), self.
_imgdata_imgdata)
253 return np.asarray(self.
_imgdata_imgdata)
261 if new_read_mode == 0
or new_read_mode == 1:
def exposure_time(self, new_exposure_time)
def cancel_exposure(self)
def get_singleframe(self)
def target_temperature(self, new_temperature)
def set_readout_modes(self, new_read_mode)
def set_roi(self, x0, y0, roi_w, roi_h)
def target_temperature(self)
def __init__(self, sdk, camera_id, new_bpp=16)
def is_exposure_finished(self)
def get_all_limits(self, camera_handle)
def set_parameter(self, camera_handle, parameter, value)
def open_camera(self, camera_id)
def close_camera(self, camera_id)
def number_of_cameras(self)
def get_parameter(self, camera_handle, parameter)
def get_parameter_limits(self, camera_handle, parameter)
def __init__(self, dll_path='/usr/local/lib/libqhyccd.so')
def get_chip_info(self, camera_handle)
GeneratorWrapper< T > range(T const &start, T const &end, T const &step)