Beispiel #1
0
    def configurePSD(self, binWidth, spectrumRange, nTimes=None):
        spectrumRange = spectrumRange * 2
        requiredSamplingInterval = 1 / spectrumRange
        requiredMeasureTime = 1 / binWidth
        self.maxSamples = ceil(requiredMeasureTime / requiredSamplingInterval)
        self.timebase = floor(requiredSamplingInterval * 125000000 + 2)  #14bit
        #self.timebase = floor(requiredSamplingInterval * 62500000 + 3) #16bit

        self.status["getTimebase2"] = ps.ps5000aGetTimebase2(self.chandle, \
            self.timebase, self.maxSamples, byref(self.timeInternalns),\
            None, 0)
        assert_pico_ok(self.status["getTimebase2"])

        self.maxSamples = ceil(requiredMeasureTime * 1e9 /
                               self.timeInternalns.value)

        assert self.timeInternalns.value <= requiredSamplingInterval * 1e9

        if bool(nTimes):
            nMaxSamples = c_long()
            ps.ps5000aMemorySegments(self.chandle, 1, byref(nMaxSamples))
            print(nMaxSamples)
            nMaxSamples.value = math.floor(nMaxSamples.value /
                                           self.nEnabledChannels())
            if nTimes == 'Max':
                nTimes = math.floor(nMaxSamples.value / (self.maxSamples)) - 25
            print(nTimes, self.maxSamples)
            assert self.maxSamples * nTimes < nMaxSamples.value
            self.maxSamples = nTimes * self.maxSamples
            return nTimes, int(self.maxSamples / nTimes)
 def runBlock(self,**kwargs): 
     '''
     arms the trigger, block mode is close to repeat (with re-arm) or single mode (without re-arm)
     rapid block accumulates several events (similar to fast frame modes on other scopes)
     arguments: none
     keyword arguments (defaults in self.trigger.settings):
         preTrigger: fraction of samples before the trigger occurs (0 to 1)
         segmentIndex: scope memory segment to store the run result
     after successfully arming the trigger, self.trigger.settings is updated
     after triggering, the channel records the noSamples and then stops (until re-arming) 
     '''
     settings = {}
     for key,current_value in self.settings.items():
         settings[key] = kwargs[key] if key in kwargs else current_value
     check_kwargs_scope(**kwargs) 
     
     
     cmaxSamples = ctypes.c_int32(self.scope.settings['noSamples'])
     self.status["MemorySegments"] = ps.ps5000aMemorySegments(self.chandle, settings['nSegments'], ctypes.byref(cmaxSamples))
     assert_pico_ok(self.status["MemorySegments"])
     
     # sets number of captures
     self.status["SetNoOfCaptures"] = ps.ps5000aSetNoOfCaptures(self.chandle, settings['nSegments'])
     assert_pico_ok(self.status["SetNoOfCaptures"])
      
     _preTriggerSamples = int(self.scope.settings['noSamples']*settings['preTrigger'])
     _postTriggerSamples = self.scope.settings['noSamples'] - _preTriggerSamples
     _timebase = self.scope.settings['timebase']
     _timeIndisposeMs = ctypes.c_int32()
     _segmentIndex = settings['segmentIndex']
     #additional callback options here, use isready instead
     self.status["runBlock"] = ps.ps5000aRunBlock(self.chandle, _preTriggerSamples, _postTriggerSamples, 
                                             _timebase, ctypes.byref(_timeIndisposeMs), _segmentIndex, None, None)
     assert_pico_ok(self.status["runBlock"])
     self.settings = settings
Beispiel #3
0
    def configMemory(self):
        # Creates a overflow location for data
        self.overflow = ctypes.c_int16()
        # Creates converted types maxsamples
        self.cmaxSamples = ctypes.c_int32(self.maxsamples)

        # Handle = Chandle
        # nMaxSamples = ctypes.byref(cmaxSamples)
        self.status["MemorySegments"] = ps.ps5000aMemorySegments(
            self.chandle, self.blocks, ctypes.byref(self.cmaxSamples))
        assert_pico_ok(self.status["MemorySegments"])

        # sets number of captures
        self.status["SetNoOfCaptures"] = ps.ps5000aSetNoOfCaptures(
            self.chandle, self.blocks)
        assert_pico_ok(self.status["SetNoOfCaptures"])
 def runRapidBlock(self,**kwargs):
     '''
     arms the trigger, block mode is close to repeat (with re-arm) or single mode (without re-arm)
     rapid block accumulates several events (similar to fast frame modes on other scopes)
     arguments: none
     keyword arguments (defaults in self.trigger.settings):
         preTrigger: fraction of samples before the trigger occurs (0 to 1)
         segmentIndex: scope memory segment to store the run result
         nSegments: number of samples to capture
     after successfully arming the trigger, self.trigger.settings is updated
     after triggering, the channel records the noSamples and then stops (until re-arming) 
     '''
     settings = {}
     for key,current_value in self.settings.items():
         settings[key] = kwargs[key] if key in kwargs else current_value
     check_kwargs_scope(**kwargs)  
     # Handle = Chandle
     # nSegments = 10
     # nMaxSamples = ctypes.byref(cmaxSamples)
     cmaxSamples = ctypes.c_int32(self.scope.settings['noSamples'])
     self.status["MemorySegments"] = ps.ps5000aMemorySegments(self.chandle, settings['nSegments'], ctypes.byref(cmaxSamples))
     assert_pico_ok(self.status["MemorySegments"])
     
     # sets number of captures
     self.status["SetNoOfCaptures"] = ps.ps5000aSetNoOfCaptures(self.chandle, settings['nSegments'])
     assert_pico_ok(self.status["SetNoOfCaptures"])
     
     # Starts the block capture
     # Handle = chandle
     # Number of prTriggerSamples
     # Number of postTriggerSamples
     # Timebase = 2 = 4ns (see Programmer's guide for more information on timebases)
     # time indisposed ms = None (This is not needed within the example)
     # Segment index = 0
     # LpRead = None
     # pParameter = None
     _preTriggerSamples = int(self.scope.settings['noSamples']*settings['preTrigger'])
     _postTriggerSamples = self.scope.settings['noSamples'] - _preTriggerSamples
     _timebase = self.scope.settings['timebase']
     _timeIndisposeMs = ctypes.c_int32()
     _segmentIndex = settings['segmentIndex']
     self.status["runblock"] = ps.ps5000aRunBlock(self.chandle, _preTriggerSamples, _postTriggerSamples, 
                                             _timebase, ctypes.byref(_timeIndisposeMs), _segmentIndex, None, None)
     assert_pico_ok(self.status["runblock"])
     self.settings = settings
    def _set_memory_segments(self, num_segments, num_samples):
        """Set up memory segments in the device.

        For multiple captures, the device's memory must be divided into
        segments, one for each capture. If the memory cannot contain the
        required number of samples per segment, an InvalidParameterError is
        raised.

        :param num_segments: the number of memory segments.
        :param num_samples: the number of required samples per capture.
        """
        max_samples = ctypes.c_int32()
        assert_pico_ok(
            ps.ps5000aMemorySegments(self._handle, num_segments,
                                     ctypes.byref(max_samples)))
        max_samples = max_samples.value
        if max_samples < num_samples:
            raise InvalidParameterError(
                f"A memory segment can only fit {max_samples}, but "
                f"{num_samples} are required.")
# MaxSamples = ctypes.byref(returnedMaxSamples)
# Segement index = 0
timeIntervalns = ctypes.c_float()
returnedMaxSamples = ctypes.c_int16()
status["GetTimebase"] = ps.ps5000aGetTimebase2(chandle, timebase, maxsamples, ctypes.byref(timeIntervalns), ctypes.byref(returnedMaxSamples), 0)
assert_pico_ok(status["GetTimebase"])

# Creates a overlow location for data
overflow = ctypes.c_int16()
# Creates converted types maxsamples
cmaxSamples = ctypes.c_int32(maxsamples)

# Handle = Chandle
# nSegments = 10
# nMaxSamples = ctypes.byref(cmaxSamples)
status["MemorySegments"] = ps.ps5000aMemorySegments(chandle, 10, ctypes.byref(cmaxSamples))
assert_pico_ok(status["MemorySegments"])

# sets number of captures
status["SetNoOfCaptures"] = ps.ps5000aSetNoOfCaptures(chandle, 10)
assert_pico_ok(status["SetNoOfCaptures"])

# Starts the block capture
# Handle = chandle
# Number of prTriggerSamples
# Number of postTriggerSamples
# Timebase = 2 = 4ns (see Programmer's guide for more information on timebases)
# time indisposed ms = None (This is not needed within the example)
# Segment index = 0
# LpRead = None
# pParameter = None
Beispiel #7
0
    def getTimeSignal(self,
                      channel=None,
                      check=True,
                      trigger=None,
                      triggerThreshold=0,
                      reportOverflow=True):
        # get all channel data but only return required
        if check:
            nMaxSamples = c_long()
            ps.ps5000aMemorySegments(self.chandle, 1, byref(nMaxSamples))
            nMaxSamples.value = math.floor(nMaxSamples.value /
                                           self.nEnabledChannels())
            if self.maxSamples > nMaxSamples.value:
                raise Exception("samples will be larger than memory")

            self.status["getTimebase2"] = ps.ps5000aGetTimebase2(self.chandle, \
                self.timebase, self.maxSamples, byref(self.timeInternalns),\
                None, 0)
            assert_pico_ok(self.status["getTimebase2"])

        if trigger is not None:
            source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_{trigCh}".format(
                trigCh=trigger)]
            self.status["trigger"] = ps.ps5000aSetSimpleTrigger(
                self.chandle, 1, source, triggerThreshold, 2, 0, 0)
            assert_pico_ok(self.status["trigger"])
        else:
            source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_{trigCh}".format(
                trigCh='D')]
            self.status["trigger"] = ps.ps5000aSetSimpleTrigger(
                self.chandle, 0, source, triggerThreshold, 2, 0, 0)
            assert_pico_ok(self.status["trigger"])

        preTriggerSamples = 0
        self.status["runBlock"] = ps.ps5000aRunBlock(self.chandle, \
            preTriggerSamples, self.maxSamples, self.timebase, None, 0, None, None)
        assert_pico_ok(self.status["runBlock"])

        ready = c_int16(0)
        check = c_int16(0)
        while ready.value == check.value:
            self.status["isReady"] = ps.ps5000aIsReady(self.chandle,
                                                       byref(ready))
            time.sleep(1e-3)

        for key in self.chs:
            if self.chs[key].enabled:
                self.chs[key].buffer = (c_int16 * self.maxSamples)()
                self.status["setDataBuffer"+key] = ps.ps5000aSetDataBuffer(self.chandle, \
                    self.chs[key].channel, byref(self.chs[key].buffer), self.maxSamples, 0, 0)
                assert_pico_ok(self.status["setDataBuffer" + key])

        overflow = c_int16()
        cmaxSamples = c_uint32(self.maxSamples)
        self.status["getValues"] = ps.ps5000aGetValues(self.chandle, 0 , \
        byref(cmaxSamples), 0, 0, 0, byref(overflow))
        assert_pico_ok(self.status["getValues"])

        overflow = '{0:04b}'.format(overflow.value)
        chOF = [bool(int(i)) for i in overflow]
        self.chs['A'].overflow = chOF[-1]
        self.chs['B'].overflow = chOF[-2]
        self.chs['C'].overflow = chOF[-3]
        self.chs['D'].overflow = chOF[-4]
        channels = ['A', 'B', 'C', 'D']
        if reportOverflow:
            for i in range(4):
                if chOF[-(i + 1)]:
                    print('channel {0} overflow'.format(channels[i]))

        maxADC = c_int16()
        self.status["maximumValue"] = ps.ps5000aMaximumValue(
            self.chandle, byref(maxADC))
        assert_pico_ok(self.status["maximumValue"])

        for key in self.chs:
            if self.chs[key].enabled:
                self.chs[key].timeSignal = (np.array(self.chs[key].buffer) / maxADC.value) * \
                    self.psVoltageRange[self.chs[key].range] * 1e-3

        if channel is not None:
            return self.chs[channel].timeSignal