コード例 #1
0
    def getChannelValues(self, channel):
        _channel = ps.PS5000A_CHANNEL['PS5000A_CHANNEL_' + channel.upper()]
        buf = (ctypes.c_int16 * self.noSamples)()
        self.status['setBuffer_' + channel.upper()] = ps.ps5000aSetDataBuffer(
            self.chandle, _channel, ctypes.byref(buf), self.noSamples, 0, 0)
        assert_pico_ok(self.status['setBuffer_' + channel.upper()])

        overflow = ctypes.c_int16()
        cnoSamples = ctypes.c_int32(self.noSamples)

        self.status['getChannelValues' +
                    channel.upper()] = ps.ps5000aGetValues(
                        self.chandle, 0, ctypes.byref(cnoSamples), 0, 0, 0,
                        ctypes.byref(overflow))
        assert_pico_ok(self.status['getChannelValues' + channel.upper()])

        maxADC = ctypes.c_int16()
        self.status['maximumValue'] = ps.ps5000aMaximumValue(
            self.chandle, ctypes.byref(maxADC))
        assert_pico_ok(self.status['maximumValue'])
        _voltage_range = ps.PS5000A_RANGE[
            'PS5000A_' + self.channel_info[channel.upper()]['voltage_range']]
        buf_mV = adc2mV(buf, _voltage_range, maxADC)

        return buf_mV
コード例 #2
0
    def _set_data_buffer(self, channel_name, num_samples, num_captures=1):
        """Set up data buffer.

        :param channel_name: channel name ('A', 'B', etc.)
        :param num_samples: number of samples required
        :param num_captures: number of captures
        """
        channel = _get_channel_from_name(channel_name)
        self._buffers[channel_name] = [(ctypes.c_int16 * num_samples)()
                                       for i in range(num_captures)]
        for segment in range(num_captures):
            assert_pico_ok(
                ps.ps5000aSetDataBuffer(
                    self._handle, channel,
                    ctypes.byref(self._buffers[channel_name][segment]),
                    num_samples, segment, 0))
コード例 #3
0
ファイル: scandevice.py プロジェクト: msu103su2/OpticalLever
def readVoltage():

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

    ready = c_int16(0)
    check = c_int16(0)
    while ready.value == check.value:
        status["isReady"] = ps.ps5000aIsReady(chandle, byref(ready))

    bufferA = (c_int16 * 2)()
    source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"]
    downSampleTatioMode = ps.PS5000A_RATIO_MODE["PS5000A_RATIO_MODE_AVERAGE"]
    status["setDataBufferA"] = ps.ps5000aSetDataBuffer(chandle, source,
                                                       byref(bufferA), 2, 0,
                                                       downSampleTatioMode)
    assert_pico_ok(status["setDataBufferA"])

    maxDownSampleRatio = c_uint32()
    status["dwonSample"] = ps.ps5000aGetMaxDownSampleRatio(
        chandle, maxSamples, byref(maxDownSampleRatio), downSampleTatioMode, 0)
    assert_pico_ok(status["dwonSample"])

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

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

    adc2mVChA = adc2mV(bufferA, chARange, maxADC)
    avg = adc2mVChA[0]
    return avg
コード例 #4
0
    def flush(self):
        buf = (ctypes.c_int16 * self.noSamples)()
        overflow = ctypes.c_int16()
        cnoSamples = ctypes.c_int32(self.noSamples)
        for channel in self.channel_info.keys():
            if self.channel_info[channel]['enabled']:
                _channel = ps.PS5000A_CHANNEL['PS5000A_CHANNEL_' +
                                              channel.upper()]
                self.status['setBuffer_' +
                            channel.upper()] = ps.ps5000aSetDataBuffer(
                                self.chandle, _channel, ctypes.byref(buf),
                                self.noSamples, 0, 0)
                assert_pico_ok(self.status['setBuffer_' + channel.upper()])

                flush_done = False
                while (not flush_done):
                    status = ps.ps5000aGetValues(self.chandle, 0,
                                                 ctypes.byref(cnoSamples), 0,
                                                 0, 0, ctypes.byref(overflow))
                    flush_done = status == PICO_STATUS[
                        'PICO_NO_SAMPLES_AVAILABLE']
コード例 #5
0
ファイル: scandevice.py プロジェクト: msu103su2/OpticalLever
def autoRange():
    global chARange
    maxSamples = 100
    while chARange < max(psVoltageRange.keys()):
        overrange = False
        preTriggerSamples = 100
        status["runBlock"] = ps.ps5000aRunBlock(chandle, preTriggerSamples,
                                                maxSamples, timebase, None, 0,
                                                None, None)
        assert_pico_ok(status["runBlock"])

        ready = c_int16(0)
        check = c_int16(0)
        while ready.value == check.value:
            status["isReady"] = ps.ps5000aIsReady(chandle, byref(ready))

        bufferA = (c_int16 * maxSamples)()
        source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"]
        status["setDataBufferA"] = ps.ps5000aSetDataBuffer(
            chandle, source, byref(bufferA), maxSamples, 0, 0)
        assert_pico_ok(status["setDataBufferA"])

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

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

        if max(map(abs, adc2mV(bufferA, chARange,
                               maxADC))) == psVoltageRange[chARange]:
            overrange = True

        if overrange:
            chARange += 1
            status["setChA"] = ps.ps5000aSetChannel(
                chandle, channel, 1, coupling_type, chARange,
                0)  #enabled = 1, analogue offset = 0 V
            assert_pico_ok(status["setChA"])
        else:
            break

    while chARange > min(psVoltageRange.keys()):
        toosmall = False
        status["setChA"] = ps.ps5000aSetChannel(
            chandle, channel, 1, coupling_type, chARange - 1,
            0)  #enabled = 1, analogue offset = 0 V
        assert_pico_ok(status["setChA"])
        preTriggerSamples = 100
        status["runBlock"] = ps.ps5000aRunBlock(chandle, preTriggerSamples,
                                                maxSamples, timebase, None, 0,
                                                None, None)
        assert_pico_ok(status["runBlock"])

        ready = c_int16(0)
        check = c_int16(0)
        while ready.value == check.value:
            status["isReady"] = ps.ps5000aIsReady(chandle, byref(ready))

        bufferA = (c_int16 * maxSamples)()
        source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"]
        status["setDataBufferA"] = ps.ps5000aSetDataBuffer(
            chandle, source, byref(bufferA), maxSamples, 0, 0)
        assert_pico_ok(status["setDataBufferA"])

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

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

        if max(map(abs, adc2mV(bufferA, chARange,
                               maxADC))) < psVoltageRange[chARange]:
            toosmall = True
        if toosmall:
            chARange = chARange - 1
        else:
            status["setChA"] = ps.ps5000aSetChannel(
                chandle, channel, 1, coupling_type, chARange,
                0)  #enabled = 1, analogue offset = 0 V
            assert_pico_ok(status["setChA"])
            break
コード例 #6
0
ファイル: scandevice.py プロジェクト: msu103su2/OpticalLever
def readAmplitude(binWidth, spectrumRange, checkRange, nmbOfAvg):

    spectrumRange = spectrumRange * 2
    requiredMeasureTime = 2 / binWidth
    requiredSamplingInterval = 1 / spectrumRange
    timebase = floor(requiredSamplingInterval * 62500000 + 3)
    timeInternalns = c_float()
    returnedMaxSamples = c_int32()
    maxSamples = ceil(spectrumRange / binWidth)
    status["getTimebase2"] = ps.ps5000aGetTimebase2(chandle, timebase,
                                                    maxSamples,
                                                    byref(timeInternalns),
                                                    byref(returnedMaxSamples),
                                                    0)
    assert_pico_ok(status["getTimebase2"])
    assert timeInternalns.value < requiredSamplingInterval * 1e9

    for i in range(nmbOfAvg):
        preTriggerSamples = 100
        status["runBlock"] = ps.ps5000aRunBlock(chandle, preTriggerSamples,
                                                maxSamples, timebase, None, 0,
                                                None, None)
        assert_pico_ok(status["runBlock"])

        ready = c_int16(0)
        check = c_int16(0)
        while ready.value == check.value:
            status["isReady"] = ps.ps5000aIsReady(chandle, byref(ready))

        bufferA = (c_int16 * maxSamples)()
        source = ps.PS5000A_CHANNEL["PS5000A_CHANNEL_A"]
        status["setDataBufferA"] = ps.ps5000aSetDataBuffer(
            chandle, source, byref(bufferA), maxSamples, 0, 0)
        assert_pico_ok(status["setDataBufferA"])

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

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

        timeSignal = adc2mV(bufferA, chARange, maxADC)
        f, newPSD = signal.periodogram(timeSignal,
                                       1 / (timeInternalns.value / 1e9),
                                       window=signal.get_window(
                                           'blackman', len(timeSignal)))
        startIndex = f.searchsorted(checkRange[0]) - 1
        endIndex = f.searchsorted(checkRange[1]) + 1
        f = f[startIndex:endIndex]
        newPSD = newPSD[startIndex:endIndex]
        if i == 0:
            PSD = np.array(newPSD)
        else:
            PSD = PSD + newPSD

    PSD = PSD / nmbOfAvg

    PSD = 10 * np.log10(10 * PSD)
    PSD = PSD - PSD.mean()
    Index, _ = find_peaks(PSD, distance=PSD.size)
    return PSD[Index]
コード例 #7
0
ファイル: ps5000A.py プロジェクト: msu103su2/OpticalLever
    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