def _python_run_block(self, handle, pre_samples, post_samples, timebase_id, oversample, segment_index): time_indisposed = c_int32(0) if len(self._run_block.argtypes) == 5: return_code = self._run_block(c_int16(handle), c_int32(pre_samples + post_samples), c_int16(timebase_id), c_int16(oversample), byref(time_indisposed)) if return_code == 0: raise InvalidCaptureParameters() elif len(self._run_block.argtypes) == 9: status = self._run_block(c_int16(handle), c_int32(pre_samples), c_int32(post_samples), c_uint32(timebase_id), c_int16(oversample), byref(time_indisposed), c_uint32(segment_index), None, None) if status != self.PICO_STATUS['PICO_OK']: raise InvalidCaptureParameters("run_block failed (%s)" % constants.pico_tag(status)) else: raise NotImplementedError("not done other driver types yet") return float(time_indisposed.value) * 0.001
def stop(self, device): if self._stop.restype == c_int16: return_code = self._stop(c_int16(device.handle)) if isinstance(return_code, c_int16): if return_code == 0: raise InvalidCaptureParameters() else: status = self._stop(c_int16(device.handle)) if status != self.PICO_STATUS['PICO_OK']: raise InvalidCaptureParameters("stop failed (%s)" % constants.pico_tag(status))
def get_values(self, device, active_channels, num_samples, segment_index=0): # Initialise buffers to hold the data: results = { channel: numpy.empty(num_samples, numpy.dtype('int16')) for channel in active_channels } overflow = c_int16(0) if len(self._get_values.argtypes ) == 7 and self._get_timebase.argtypes[1] == c_int16: inputs = {k: None for k in 'ABCD'} for k, arr in results.items(): inputs[k] = arr.ctypes.data return_code = self._get_values(c_int16(device.handle), inputs['A'], inputs['B'], inputs['C'], inputs['D'], byref(overflow), c_int32(num_samples)) if return_code == 0: raise InvalidCaptureParameters() elif len(self._get_values.argtypes ) == 7 and self._get_timebase.argtypes[1] == c_uint32: # For this function pattern, we first call a function (self._set_data_buffer) to register each buffer. Then, # we can call self._get_values to actually populate them. for channel, array in results.items(): status = self._set_data_buffer( c_int16(device.handle), c_int32(self.PICO_CHANNEL[channel]), array.ctypes.data, c_int32(num_samples), c_uint32(segment_index), c_int32(self.PICO_RATIO_MODE['NONE'])) if status != self.PICO_STATUS['PICO_OK']: raise InvalidCaptureParameters( "set_data_buffer failed (%s)" % constants.pico_tag(status)) samples_collected = c_uint32(num_samples) status = self._get_values(c_int16(device.handle), c_uint32(0), byref(samples_collected), c_uint32(1), c_int32(self.PICO_RATIO_MODE['NONE']), c_uint32(segment_index), byref(overflow)) if status != self.PICO_STATUS['PICO_OK']: raise InvalidCaptureParameters("get_values failed (%s)" % constants.pico_tag(status)) overflow_warning = {} if overflow.value: for channel in results.keys(): if overflow.value & (1 >> self.PICO_CHANNEL[channel]): overflow_warning[channel] = True return results, overflow_warning
def is_ready(self, device): """poll this function to find out when block mode is ready or has triggered. returns: True if data is ready, False otherwise.""" if hasattr(self, '_ready') and len(self._ready.argtypes) == 1: return_code = self._ready(c_int16(device.handle)) return bool(return_code) elif hasattr(self, '_is_ready') and len(self._is_ready.argtypes) == 2: is_ready = c_int16(0) status = self._is_ready(c_int16(device.handle), byref(is_ready)) if status != self.PICO_STATUS['PICO_OK']: raise InvalidCaptureParameters("is_ready failed (%s)" % constants.pico_tag(status)) return bool(is_ready.value) else: raise NotImplementedError("not done other driver types yet")