def block(self): self.data_mVRay.clear() self.time = {} self.status["runblock"] = ps.ps5000aRunBlock(self.chandle, self.preTriggerSamples, self.postTriggerSamples, self.timebase, None, 0, None, None) assert_pico_ok(self.status["runblock"]) ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: self.status["isReady"] = ps.ps5000aIsReady(self.chandle, ctypes.byref(ready)) self.status["GetValuesBulk"] = ps.ps5000aGetValuesBulk( self.chandle, ctypes.byref(self.cmaxSamples), 0, self.blocks - 1, 0, 0, ctypes.byref(self.overflow)) assert_pico_ok(self.status["GetValuesBulk"]) for i in range(self.blocks): self.data_mVRay.append( adc2mV(self.bufferMaxRay[i], self.chARange, self.maxADC)) #self.data_mVRay.append(np.asarray(self.bufferMaxRay[i], dtype=int) * self.chARange / self.maxADC.value) self.createTimeAxis()
def _get_values(self, num_samples, num_captures): """Get data from device and return buffer or None.""" num_samples = ctypes.c_uint32(num_samples) overflow = (ctypes.c_int16 * num_captures)() status = ps.ps5000aGetValuesBulk(self._handle, ctypes.byref(num_samples), 0, num_captures - 1, 0, 0, ctypes.byref(overflow)) status_msg = PICO_STATUS_LOOKUP[status] if status_msg == "PICO_OK": return [ self._buffers[channel] if is_enabled is True else None for channel, is_enabled in self._channels_enabled.items() ] elif status_msg == "PICO_NO_SAMPLES_AVAILABLE": return None else: raise PicoSDKError(f"PicoSDK returned {status_msg}")
# Checks data collection to finish the capture ready = ctypes.c_int16(0) check = ctypes.c_int16(0) while ready.value == check.value: status["isReady"] = ps.ps5000aIsReady(chandle, ctypes.byref(ready)) # Handle = chandle # noOfSamples = ctypes.byref(cmaxSamples) # fromSegmentIndex = 0 # ToSegmentIndex = 9 # DownSampleRatio = 0 # DownSampleRatioMode = 0 # Overflow = ctypes.byref(overflow) status["GetValuesBulk"] = ps.ps5000aGetValuesBulk(chandle, ctypes.byref(cmaxSamples), 0, 9, 0, 0, ctypes.byref(overflow)) assert_pico_ok(status["GetValuesBulk"]) # Handle = chandle # Times = Times = (ctypes.c_int16*10)() = ctypes.byref(Times) # Timeunits = TimeUnits = ctypes.c_char() = ctypes.byref(TimeUnits) # Fromsegmentindex = 0 # Tosegementindex = 9 Times = (ctypes.c_int16*10)() TimeUnits = ctypes.c_char() status["GetValuesTriggerTimeOffsetBulk"] = ps.ps5000aGetValuesTriggerTimeOffsetBulk64(chandle, ctypes.byref(Times), ctypes.byref(TimeUnits), 0, 9) assert_pico_ok(status["GetValuesTriggerTimeOffsetBulk"]) # Get and print TriggerInfo for memory segments # Create array of ps.PS5000A_TRIGGER_INFO for each memory segment Ten_TriggerInfo = (ps.PS5000A_TRIGGER_INFO*10) ()
def read(self,**kwargs): ''' reads the scope results: arguments: none keyword arguments (defaults in scope.settings): source: the channel(s) to read. If no channels are given, all the channels are read, startIndex: the sample to start reading, down_sample_blocksize: the number of samples to group for the data reduction (see Channel()._setDataBuffers), reduction_mode: the reduction_mode for the data reduction (see Channel()._setDataBuffers), the results (in V) are stored in scope.channels['channe_name'].data_max and scope.channels['channe_name'].data_min a results structure is returned: time: the time (in s) channel+' (V)': channel voltage (in V) ***in reduction_mode == aggregate, two keys are returned instead:*** channel+'_{max} (V)': channel max voltage (in V) channel+'_{min} (V)': channel min voltage (in V) channel voltage (including max/min) are returned as noSamples*nSegments arrays ''' #handles default values settings = {} for key,current_value in self.settings.items(): settings[key] = kwargs[key] if key in kwargs else current_value if not 'source' in kwargs: settings['source'] = self.enabledChannels for channel in settings['source']: self.channels[channel]._setDataBuffers(reduction_mode = settings['reduction_mode']) check_kwargs_scope(**kwargs) # create overflow loaction overflow = (ctypes.c_int16 *self.trigger.settings['nSegments'])() # create converted type maxSamples cmaxSamples = ctypes.c_int32(self.settings['noSamples']) _ratio_mode = ratio_mode_index[settings['reduction_mode']] _segmentIndex = ctypes.c_uint32(self.settings['segmentIndex']) # Retried data from scope to buffers assigned above # handle = chandle # start index = 0 # pointer to number of samples = ctypes.byref(cmaxSamples) # downsample ratio = 0 # downsample ratio mode = PS5000A_RATIO_MODE_NONE # pointer to overflow = ctypes.byref(overflow)) if self.trigger.settings['nSegments']==1: self.status["getValues"] = ps.ps5000aGetValues(self.chandle, settings['startIndex'], ctypes.byref(cmaxSamples), settings['down_sample_blocksize'], _ratio_mode, _segmentIndex, ctypes.byref(overflow)) assert_pico_ok(self.status["getValues"]) else: _fromSegmentIndex = self.trigger.settings['segmentIndex'] _toSegmentIndex = _fromSegmentIndex+self.trigger.settings['nSegments']-1 self.status["getValuesBulk"] = ps.ps5000aGetValuesBulk(self.chandle, ctypes.byref(cmaxSamples), _fromSegmentIndex,_toSegmentIndex, settings['down_sample_blocksize'], _ratio_mode, ctypes.byref(overflow)) assert_pico_ok(self.status["getValuesBulk"]) self.settings = settings # Create time data time = np.linspace(0, (cmaxSamples.value) * self.settings['timeIntervalSeconds'], cmaxSamples.value) results = {'time (s)':time} # convert ADC counts data to mV for channel in settings['source']: if self.channels[channel].settings['reduction_mode']=='aggregate': results[channel+'_{max} (V)']=self.channels[channel].data_max results[channel+'_{min} (V)']=self.channels[channel].data_min else: results[channel+' (V)']=self.channels[channel].data_max return results