Ejemplo n.º 1
0
    def retrieveCh(self):
        # Create buffers ready for data
        bufferA = (ctypes.c_int16 * NUM_SAMPLES)()
        bufferB = (ctypes.c_int16 * NUM_SAMPLES)()
        overflow = c_long()
        cmaxSamples = ctypes.c_int32(NUM_SAMPLES)
        status = self.picoObj.ps2000_get_values(self.device, ctypes.byref(bufferA), ctypes.byref(bufferB), None, None,
                                                   ctypes.byref(overflow), cmaxSamples)
        if overflow.value != 0:
            print("Some buffers overflowed: code " + str(overflow.value) + ".\n")

        if status == 0:
            print("Failed to get values.\n")
        #else:
        #    print (".")
            #print("Got " + str(status) + " values.\n")

        # find maximum ADC count value
        maxADC = ctypes.c_int16(MAX_ADC)

        # convert ADC counts data to mV
        adc2mVChA = adc2mV(bufferA, voltrange, maxADC)
        adc2mVChB = adc2mV(bufferB, voltrange, maxADC)

        # Create time data
        time = np.linspace(0, (cmaxSamples.value) * self.timeInterval.value, cmaxSamples.value)/NANO2MILI
        return adc2mVChA, adc2mVChB, time
Ejemplo n.º 2
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
Ejemplo n.º 3
0
    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 retrieveCaptureData(self, channels):
        segment_index = 0
        ratio_move = 0  #PS5000A_RATIO_MODE_NONE
        if self.channela in channels:
            self.status["setDataBuffersA"] = ps.ps5000aSetDataBuffers(
                self.chandle, self.channela, ctypes.byref(self.bufferAMax),
                ctypes.byref(self.bufferAMin), self.totalSamples,
                segment_index, ratio_move)
            assert_pico_ok(self.status["setDataBuffersA"])
        if self.channelb in channels:
            self.status["setDataBuffersB"] = ps.ps5000aSetDataBuffers(
                self.chandle, self.channelb, ctypes.byref(self.bufferBMax),
                ctypes.byref(self.bufferBMin), self.totalSamples,
                segment_index, ratio_move)
            assert_pico_ok(self.status["setDataBuffersB"])
        if len(channels) < 1 or (self.channela not in channels
                                 and self.channelb not in channels):
            raise ValueError("Missing or unrecognised channel(s) requested")

        # create overflow loaction
        overflow = ctypes.c_int16()
        # create converted type maxSamples
        cmaxSamples = ctypes.c_int32(self.totalSamples)

        # Retried data from scope to buffers assigned above
        start_index = 0
        downsample_ratio = 0
        downsample_mode = 0  #PS5000A_RATIO_MODE_NONE
        segment_index = 0
        self.status["getValues"] = ps.ps5000aGetValues(
            self.chandle, start_index, ctypes.byref(cmaxSamples),
            downsample_ratio, downsample_mode, segment_index,
            ctypes.byref(overflow))
        assert_pico_ok(self.status["getValues"])

        # convert ADC counts data to mV
        adc2mVMaxChA, adc2mVMaxChB = None, None
        if self.channela in channels:
            adc2mVMaxChA = adc2mV(self.bufferAMax, self.channela_range,
                                  self.maxADC)
        if self.channelb in channels:
            adc2mVMaxChB = adc2mV(self.bufferBMax, self.channelb_range,
                                  self.maxADC)

        return [adc2mVMaxChA, adc2mVMaxChB]
Ejemplo n.º 5
0
    def read(self, **kwargs):
        '''
        reads the scope results:
        arguments: none
        keyword arguments: none
        the results (in V) are returned in a dictionary:
            time:                   the time (in s)
            A (V):   channel A voltage (in V)
            B (V):   channel B voltage (in V)
        '''
        #handles default values
        settings = {}
        for key, current_value in self.settings.items():
            settings[key] = kwargs[key] if key in kwargs else current_value
        check_kwargs_scope(**kwargs)
        # Create buffers ready for data
        _bufferA = (ctypes.c_int16 * self.settings['noSamples'])()
        _bufferB = (ctypes.c_int16 * self.settings['noSamples'])()
        #_bufferC = None
        #_bufferD = None
        # create overflow loaction
        _overflow = ctypes.c_int16()
        # create converted type maxSamples
        cmaxSamples = ctypes.c_int32(self.settings['noSamples'])
        self.status["getValues"] = ps.ps2000_get_values(
            self.chandle, ctypes.byref(_bufferA), ctypes.byref(_bufferB), None,
            None, ctypes.byref(_overflow), cmaxSamples)
        assert_pico2000_ok(self.status["getValues"])

        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
        adc2mVChA = adc2mV(_bufferA, self.channels['A']._chRange.value,
                           self._maxADC)
        adc2mVChB = adc2mV(_bufferB, self.channels['B']._chRange.value,
                           self._maxADC)
        results['A (V)'] = 1e-3 * np.array(adc2mVChA).reshape(-1, 1)
        results['B (V)'] = 1e-3 * np.array(adc2mVChB).reshape(-1, 1)
        return results
Ejemplo n.º 6
0
def block_mV(metadatafile,
             channel,
             measurementnumber=False,
             blocknumber=False):
    channels = ['A', 'B', 'C', 'D']
    Settings = load_settings(metadatafile)[0]
    Active_channels = [
        i for i in channels if Settings['Channels'][i]['Active'] == 2
    ]
    block = (ctypes.c_int16 * Settings['Time']['Samples'])()
    print("join", os.path.join(metadatafile.replace('metadata.yml', 'scope')))
    print("split",
          os.path.split(metadatafile)[1].replace('_metadata.yml', '.bin'))
    print(
        "join and split",
        os.path.join(
            metadatafile.replace('metadata.yml', 'scope'),
            os.path.split(metadatafile)[1].replace('_metadata.yml', '.bin')))
    print("goed",
          os.path.join(metadatafile).replace('_metadata.yml', '.bin')
          )  #) #(metadatafile.replace('metadata.yml', 'scope'), os.path.split
    datafile = os.path.join(
        metadatafile.replace('metadata.yml', 'scope'),
        os.path.split(metadatafile)[1].replace('_metadata.yml', '.bin')
    )  #os.path.join(metadatafile.replace('metadata.yml', 'scope'), os.path.split(metadatafile)[1].replace('_metadata.yml', '.bin'))
    if measurementnumber:
        datafile = datafile.replace('.bin',
                                    '_{}.bin'.format(measurementnumber))
    if blocknumber:
        datafile = datafile.replace('.bin', '_{}.bin'.format(blocknumber))
    if channel in Active_channels:
        f = open(datafile, 'br')
        #f.seek(2 * Settings['Time']['Samples'] * channels.index(channel), 0)
        #block = f.read(Settings['Time']['Samples'])
        channel_skip = int(2 * Settings['Time']['Samples'] *
                           channels.index(channel))
        for i in range(Settings['Time']['Samples']):
            f.seek(channel_skip + 2 * i, 0)
            block[i] = int.from_bytes(
                f.read(2), byteorder='little', signed=True
            )  #f.read(2)#int(2*Settings['Time']['Samples']))#int.from_bytes(f.read(2), byteorder='little', signed=True)
        f.close
        return adc2mV(
            block, ps.PS5000A_RANGE["PS5000A_{}".format(
                Settings['Channels'][channel]['Range'].replace(' ',
                                                               '').replace(
                                                                   'm', 'M'))],
            ctypes.c_int16(Settings['Time']['maxADC']))
    else:
        raise KeyError('Channel {} not in {}, only {}'.format(
            channel, datafile, Active_channels))
Ejemplo n.º 7
0
 def generate_body(self):
     """Retrieve data."""
     max_ADC = ctypes.c_int16()
     self.status["maximumValue"] = ps.ps2000aMaximumValue(
         self.chandle, ctypes.byref(max_ADC))
     assert_pico_ok(self.status["maximumValue"])
     total_samples = self.buffer_settings["size"] * self.buffer_settings[
         "num"]
     self.raw_data["time"] = np.linspace(
         0, total_samples * self.sample_interval.value, total_samples)
     for alias, channel in self.channels.items():
         self.raw_data[alias] = adc2mV(channel.buffer_complete,
                                       channel.range, max_ADC)
     self.process_data()
Ejemplo n.º 8
0
 def interpret_data(self, setSamples, timestep, channel, Range, maxSamples):
     # Create time data
     #if Samples <= maxSamples:
     Samples = len(self.buffer[channel]['Average'])
     #if Samples != setSamples:
     #    print('Number of samples changed during measurement')
     if not 'Time' in self.block:
         self.block['Time'] = np.linspace(0, Samples * timestep, Samples)
     # convert ADC counts data to mV
     self.block[channel] = adc2mV(
         self.buffer[channel]['Average'],
         ps.PS5000A_RANGE["PS5000A_{}".format(
             Range.replace(' ', '').replace('m', 'M'))], self.dev.maxADC)
     #print(self.block)
     '''
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
    def get_samples(self):
        # Checks data collection to finish the capture
        ready = ctypes.c_int16(0)
        check = ctypes.c_int16(0)
        while ready.value == check.value:  # Note: we assume that the AUTOTRIGGER function is used here
            self.status["isReady"] = ps.ps3000aIsReady(self.chandle,
                                                       ctypes.byref(ready))

        # Handle = chandle
        # start index = 0
        # noOfSamples = ctypes.byref(cmaxSamples)
        # DownSampleRatio = 0
        # DownSampleRatioMode = 0
        # SegmentIndex = 0
        # Overflow = ctypes.byref(overflow)

        self.status["GetValues"] = ps.ps3000aGetValues(
            self.chandle, 0, ctypes.byref(self.cmaxSamples), 0, 0, 0,
            ctypes.byref(self.overflow))
        assert_pico_ok(self.status["GetValues"])

        # Finds the max ADC count
        # Handle = chandle
        # Value = ctype.byref(maxADC)
        maxADC = ctypes.c_int16()
        self.status["maximumValue"] = ps.ps3000aMaximumValue(
            self.chandle, ctypes.byref(maxADC))
        assert_pico_ok(self.status["maximumValue"])

        # Converts ADC from channel A to mV
        adc2mVChAMax = adc2mV(self.bufferAMax, self.chARange, maxADC)

        # Creates the time data
        #time = np.linspace(0, (self.cmaxSamples.value) * timeIntervalns.value, self.cmaxSamples.value)
        #print self.bufferAMax
        #return np.array(self.bufferAMax,dtype='int16')
        return np.array(adc2mVChAMax)
Ejemplo n.º 11
0
    def runTestBlock(self):
        self.status["runBlock"] = ps.ps5000aRunBlock(self.chandle,
                                                     self.preTriggerSamples,
                                                     self.postTriggerSamples,
                                                     self.timebase, None, 0,
                                                     None, None)
        assert_pico_ok(self.status["runBlock"])

        # Check for data collection to finish using ps5000aIsReady
        self.ready = ctypes.c_int16(0)
        self.check = ctypes.c_int16(0)
        while self.ready.value == self.check.value:
            self.status["isReady"] = ps.ps5000aIsReady(
                self.chandle, ctypes.byref(self.ready))
        # create overflow loaction

        # 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))
        self.status["getValues"] = ps.ps5000aGetValues(
            self.chandle, 0, ctypes.byref(self.cmaxSamples), 0, 0, 0,
            ctypes.byref(self.overflow))
        assert_pico_ok(self.status["getValues"])
        for index in range(0, self.numberOfChannels):
            self.returnData[index, :] = adc2mV(self.bufferMax[index],
                                               self.chRange[index],
                                               self.maxADC)

        self.time = np.linspace(0, (self.cmaxSamples.value) *
                                self.timeIntervalns.value,
                                self.cmaxSamples.value)
        return self.returnData, self.time
Ejemplo n.º 12
0
# Retried data from scope to buffers assigned above
# handle = chandle
# start index = 0
# pointer to number of samples = ctypes.byref(cmaxSamples)
# downsample ratio = 1
# downsample ratio mode = PS6000_RATIO_MODE_NONE
# pointer to overflow = ctypes.byref(overflow))
status["getValues"] = ps.ps6000GetValues(chandle, 0, ctypes.byref(cmaxSamples), 1, 0, 0, ctypes.byref(overflow))
assert_pico_ok(status["getValues"])

# find maximum ADC count value
maxADC = ctypes.c_int16(32512)

# convert ADC counts data to mV
adc2mVChAMax =  adc2mV(bufferAMax, chARange, maxADC)
adc2mVChBMax =  adc2mV(bufferBMax, chBRange, maxADC)

# Create time data
time = np.linspace(0, (cmaxSamples.value) * timeIntervalns.value, cmaxSamples.value)

# plot data from channel A and B
plt.plot(time, adc2mVChAMax[:])
plt.plot(time, adc2mVChBMax[:])
plt.xlabel('Time (ns)')
plt.ylabel('Voltage (mV)')
plt.show()

status["stop"] = ps.ps6000aStop(chandle)
assert_pico_ok(status["stop"])
Ejemplo n.º 13
0
def naberDataA():
    # Create chandle and status ready for use
    chandle = ctypes.c_int16()
    status = {}

    # Open 2000 series PicoScope
    # Returns handle to chandle for use in future API functions
    status["openunit"] = ps.ps2000aOpenUnit(ctypes.byref(chandle), None)
    assert_pico_ok(status["openunit"])

    # Set up channel A
    # handle = chandle
    # channel = PS2000A_CHANNEL_A = 0
    # enabled = 1
    # coupling type = PS2000A_DC = 1
    # range = PS2000A_2V = 7
    # analogue offset = 0 V
    chARange = 5
    status["setChA"] = ps.ps2000aSetChannel(chandle, 0, 1, 0, chARange, 0)
    assert_pico_ok(status["setChA"])

    # Set up channel B
    # handle = chandle
    # channel = PS2000A_CHANNEL_B = 1
    # enabled = 1
    # coupling type = PS2000A_DC = 1
    # range = PS2000A_2V = 7
    # analogue offset = 0 V
    chBRange = 7
    status["setChB"] = ps.ps2000aSetChannel(chandle, 1, 1, 1, chBRange, 0)
    assert_pico_ok(status["setChB"])

    # Set up single trigger
    # handle = chandle
    # enabled = 1
    # source = PS2000A_CHANNEL_A = 0
    # threshold = 1024 ADC counts
    # direction = PS2000A_RISING = 2 (falling = 3)
    # delay = 0 s
    # auto Trigger = 1000 ms
    maxADC = ctypes.c_int16()
    status["maximumValue"] = ps.ps2000aMaximumValue(chandle,
                                                    ctypes.byref(maxADC))
    vRange = 500
    mvTrigger = -100
    adcTrigger = int(mvTrigger / vRange * maxADC.value)
    #    print(maxADC.value,adcTrigger)
    status["trigger"] = ps.ps2000aSetSimpleTrigger(chandle, 1, 0, adcTrigger,
                                                   3, 0, 0)
    assert_pico_ok(status["trigger"])

    # Set number of pre and post trigger samples to be collected
    #preTriggerSamples = 2500
    #postTriggerSamples = 2500
    preTriggerSamples = 300
    postTriggerSamples = 2150
    totalSamples = preTriggerSamples + postTriggerSamples

    # Get timebase information
    # handle = chandle
    # timebase = 8 = timebase
    # noSamples = totalSamples
    # pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalNs)
    # pointer to totalSamples = ctypes.byref(returnedMaxSamples)
    # segment index = 0
    timebase = 8
    timeIntervalns = ctypes.c_float()
    returnedMaxSamples = ctypes.c_int32()
    oversample = ctypes.c_int16(0)
    status["getTimebase2"] = ps.ps2000aGetTimebase2(
        chandle, timebase, totalSamples, ctypes.byref(timeIntervalns),
        oversample, ctypes.byref(returnedMaxSamples), 0)
    assert_pico_ok(status["getTimebase2"])

    # Run block capture
    # handle = chandle
    # number of pre-trigger samples = preTriggerSamples
    # number of post-trigger samples = PostTriggerSamples
    # timebase = 8 = 80 ns = timebase (see Programmer's guide for mre information on timebases)
    # oversample = 0 = oversample
    # time indisposed ms = None (not needed in the example)
    # segment index = 0
    # lpReady = None (using ps2000aIsReady rather than ps2000aBlockReady)
    # pParameter = None
    status["runBlock"] = ps.ps2000aRunBlock(chandle, preTriggerSamples,
                                            postTriggerSamples, timebase,
                                            oversample, None, 0, None, None)
    assert_pico_ok(status["runBlock"])

    # Check for data collection to finish using ps2000aIsReady
    ready = ctypes.c_int16(0)
    check = ctypes.c_int16(0)
    while ready.value == check.value:
        status["isReady"] = ps.ps2000aIsReady(chandle, ctypes.byref(ready))

    # Create buffers ready for assigning pointers for data collection
    bufferAMax = (ctypes.c_int16 * totalSamples)()
    bufferAMin = (ctypes.c_int16 * totalSamples)(
    )  # used for downsampling which isn't in the scope of this example
    bufferBMax = (ctypes.c_int16 * totalSamples)()
    bufferBMin = (ctypes.c_int16 * totalSamples)(
    )  # used for downsampling which isn't in the scope of this example

    # Set data buffer location for data collection from channel A
    # handle = chandle
    # source = PS2000A_CHANNEL_A = 0
    # pointer to buffer max = ctypes.byref(bufferDPort0Max)
    # pointer to buffer min = ctypes.byref(bufferDPort0Min)
    # buffer length = totalSamples
    # segment index = 0
    # ratio mode = PS2000A_RATIO_MODE_NONE = 0
    status["setDataBuffersA"] = ps.ps2000aSetDataBuffers(
        chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin),
        totalSamples, 0, 0)
    assert_pico_ok(status["setDataBuffersA"])

    # Set data buffer location for data collection from channel B
    # handle = chandle
    # source = PS2000A_CHANNEL_B = 1
    # pointer to buffer max = ctypes.byref(bufferBMax)
    # pointer to buffer min = ctypes.byref(bufferBMin)
    # buffer length = totalSamples
    # segment index = 0
    # ratio mode = PS2000A_RATIO_MODE_NONE = 0
    status["setDataBuffersB"] = ps.ps2000aSetDataBuffers(
        chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin),
        totalSamples, 0, 0)
    assert_pico_ok(status["setDataBuffersB"])

    # Create overflow location
    overflow = ctypes.c_int16()
    # create converted type totalSamples
    cTotalSamples = ctypes.c_int32(totalSamples)

    # Retried data from scope to buffers assigned above
    # handle = chandle
    # start index = 0
    # pointer to number of samples = ctypes.byref(cTotalSamples)
    # downsample ratio = 0
    # downsample ratio mode = PS2000A_RATIO_MODE_NONE
    # pointer to overflow = ctypes.byref(overflow))
    status["getValues"] = ps.ps2000aGetValues(chandle, 0,
                                              ctypes.byref(cTotalSamples), 0,
                                              0, 0, ctypes.byref(overflow))
    assert_pico_ok(status["getValues"])

    # find maximum ADC count value
    # handle = chandle
    # pointer to value = ctypes.byref(maxADC)
    maxADC = ctypes.c_int16()
    #    print(maxADC.value)
    status["maximumValue"] = ps.ps2000aMaximumValue(chandle,
                                                    ctypes.byref(maxADC))
    assert_pico_ok(status["maximumValue"])
    #    print(maxADC)
    # convert ADC counts data to mV
    adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC)
    adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC)

    # Create time data
    time = np.linspace(0, (cTotalSamples.value) * timeIntervalns.value,
                       cTotalSamples.value)

    # Stop the scope
    # handle = chandle
    status["stop"] = ps.ps2000aStop(chandle)
    assert_pico_ok(status["stop"])

    # Close unitDisconnect the scope
    # handle = chandle
    status["close"] = ps.ps2000aCloseUnit(chandle)
    assert_pico_ok(status["close"])

    # display status returns
    #    print(status)

    casA = np.array(time)
    napetiA = np.array(adc2mVChAMax)

    return casA, napetiA
Ejemplo n.º 14
0
# Get data from scope
# handle = chandle
# pointer to buffer_a = ctypes.byref(bufferA)
# pointer to buffer_b = ctypes.byref(bufferB)
# poiner to overflow = ctypes.byref(oversample)
# no_of_values = cmaxSamples
cmaxSamples = ctypes.c_int32(maxSamples)
status["getValues"] = ps.ps2000_get_values(chandle, ctypes.byref(bufferA), ctypes.byref(bufferB), None, None, ctypes.byref(oversample), cmaxSamples)
assert_pico2000_ok(status["getValues"])

# find maximum ADC count value
maxADC = ctypes.c_int16(32767)

# convert ADC counts data to mV
adc2mVChA =  adc2mV(bufferA, chARange, maxADC)
adc2mVChB =  adc2mV(bufferB, chBRange, maxADC)

# Create time data
time = np.linspace(0, (cmaxSamples.value) * timeInterval.value, cmaxSamples.value)

# plot data from channel A and B
plt.plot(time, adc2mVChA[:])
plt.plot(time, adc2mVChB[:])
plt.xlabel('Time (ns)')
plt.ylabel('Voltage (mV)')
plt.show()

# Stop the scope
# handle = chandle
status["stop"] = ps.ps2000_stop(chandle)
Ejemplo n.º 15
0
# Handle = chandle
# start index = 0
# noOfSamples = ctypes.byref(cmaxSamples)
# DownSampleRatio = 0
# DownSampleRatioMode = 0
# SegmentIndex = 0
# Overflow = ctypes.byref(overflow)

status["GetValues"] = ps.ps3000aGetValues(chandle, 0,
                                          ctypes.byref(cmaxSamples), 0, 0, 0,
                                          ctypes.byref(overflow))
assert_pico_ok(status["GetValues"])

# Converts ADC from channel A to mV
adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC)

# Creates the time data
time = np.linspace(0, (cmaxSamples.value) * timeIntervalns.value,
                   cmaxSamples.value)

# Plots the data from channel A onto a graph
plt.plot(time, adc2mVChAMax[:])
plt.xlabel('Time (ns)')
plt.ylabel('Voltage (mV)')
plt.show()

# Stops the scope
# Handle = chandle
status["stop"] = ps.ps3000aStop(chandle)
assert_pico_ok(status["stop"])
Ejemplo n.º 16
0
    status["GetValues"] = ps.ps2000aGetValues(
        handle, startIndex, ctypes.byref(ctypes.c_int32(samples)), 0, 0,
        segmentIndex, ctypes.byref(overflow))
    assert_pico_ok(status["GetValues"])

    print("Triggered event")

    # You can check for Overflow
    if overflow[0] != 0: print("Overrange error in Channel A for " + filename)
    elif overflow[1] != 0:
        print("Overrange error in Channel B for " + filename)

    # Generate the data
    time = np.linspace(0, samples * timeIntervalns.value, samples)
    mVA = adc2mV(bufferA, rangeA, maxADC)
    mVB = adc2mV(bufferB, rangeB, maxADC)

    # And then put them into a file
    with open(os.path.join(mydir, filename), 'w') as file:

        for i in range(samples):
            file.write(
                str(time[i]) + '\t' + str(mVA[i]) + '\t' + str(mVB[i]) + '\n')

# Stops the scope
# Handle = handle
status["stop"] = ps.ps2000aStop(handle)
assert_pico_ok(status["stop"])

# Closes the unit
Ejemplo n.º 17
0
 def data_min(self):
     _chRange = ps.PS5000A_RANGE[range_index[self.settings['chRange']]]
     out =[]
     for _bufferMin in self._bufferMin:
         out.append(1e-3*np.array(adc2mV(_bufferMin, _chRange, self.scope._maxADC)))
     return np.vstack(out).T
Ejemplo n.º 18
0
    if not wasCalledBack:
        # If we weren't called back by the driver, this means no data is ready. Sleep for a short while before trying
        # again.
        time.sleep(0.01)

print("Done grabbing values.")

# Find maximum ADC count value
# handle = chandle
# pointer to value = ctypes.byref(maxADC)
maxADC = ctypes.c_int16()
status["maximumValue"] = ps.ps4000aMaximumValue(chandle, ctypes.byref(maxADC))
assert_pico_ok(status["maximumValue"])

# Convert ADC counts data to mV
adc2mVChAMax = adc2mV(bufferCompleteA, channel_range, maxADC)
adc2mVChBMax = adc2mV(bufferCompleteB, channel_range, maxADC)

# Create time data
time = np.linspace(0, (totalSamples) * actualSampleIntervalNs, totalSamples)

# Plot data from channel A and B
plt.plot(time, adc2mVChAMax[:])
plt.plot(time, adc2mVChBMax[:])
plt.xlabel('Time (ns)')
plt.ylabel('Voltage (mV)')
plt.show()

# Stop the scope
# handle = chandle
status["stop"] = ps.ps4000aStop(chandle)
Ejemplo n.º 19
0
# pointer to number of samples = ctypes.byref(cmaxSamples)
# downsample ratio = 0
# downsample ratio mode = PS4000a_RATIO_MODE_NONE
# pointer to overflow = ctypes.byref(overflow))
status["getValues"] = ps.ps4000aGetValues(chandle, 0,
                                          ctypes.byref(cmaxSamples), 0, 0, 0,
                                          ctypes.byref(overflow))
assert_pico_ok(status["getValues"])

# find maximum ADC count value
# handle = chandle
# pointer to value = ctypes.byref(maxADC)
maxADC = ctypes.c_int16(32767)

# convert ADC counts data to mV
adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC)
adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC)
adc2mVChCMax = adc2mV(bufferCMax, chCRange, maxADC)
adc2mVChDMax = adc2mV(bufferDMax, chDRange, maxADC)

## detect the last point
last_point = postTriggerSamples
for i, item in enumerate(adc2mVChCMax[10:]):
    if item < 1000:
        last_point = i + 10
        break
print("Last point is ", last_point, "\nTime duration is = ",
      (last_point * timeIntervalns.value) / (1000 * 1000), ' msec')

# Compute Average
CH_A_Avg = np.average(adc2mVChAMax[:last_point])
noOfSamples = ctypes.c_uint64(nSamples)
# downSampleRatio = 1
# segmentIndex = 0
overflow = ctypes.c_int16(0)
status["getValues"] = ps.ps6000aGetValues(chandle, 0, ctypes.byref(noOfSamples), 1, downSampleMode, 0, ctypes.byref(overflow))
assert_pico_ok(status["getValues"])

# get max ADC value
# handle = chandle
minADC = ctypes.c_int16()
maxADC = ctypes.c_int16()
status["getAdcLimits"] = ps.ps6000aGetAdcLimits(chandle, resolution, ctypes.byref(minADC), ctypes.byref(maxADC))
assert_pico_ok(status["getAdcLimits"])

# convert ADC counts data to mV
adc2mVChAMax =  adc2mV(bufferAMax, channelRange, maxADC)

# Create time data
time = np.linspace(0, (nSamples) * timeInterval.value * 1000000000, nSamples)

# plot data from channel A and B
plt.plot(time, adc2mVChAMax[:])
plt.xlabel('Time (ns)')
plt.ylabel('Voltage (mV)')
plt.show()

# Close the scope
status["closeunit"] = ps.ps6000aCloseUnit(chandle)
assert_pico_ok(status["closeunit"])

print(status)
Ejemplo n.º 21
0
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]
Ejemplo n.º 22
0
# 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.ps6000GetValuesTriggerTimeOffsetBulk64(chandle, ctypes.byref(Times), ctypes.byref(TimeUnits), 0, 9)
assert_pico_ok(status["GetValuesTriggerTimeOffsetBulk"])

# Finds the max ADC count
maxADC = ctypes.c_int16(32512)

# Converts ADC from channel A to mV
adc2mVChAMax =  adc2mV(bufferAMax, chARange, maxADC)
adc2mVChAMax1 =  adc2mV(bufferAMax1, chARange, maxADC)
adc2mVChAMax2 =  adc2mV(bufferAMax2, chARange, maxADC)
adc2mVChAMax3 =  adc2mV(bufferAMax3, chARange, maxADC)
adc2mVChAMax4 =  adc2mV(bufferAMax4, chARange, maxADC)
adc2mVChAMax5 =  adc2mV(bufferAMax5, chARange, maxADC)
adc2mVChAMax6 =  adc2mV(bufferAMax6, chARange, maxADC)
adc2mVChAMax7 =  adc2mV(bufferAMax7, chARange, maxADC)
adc2mVChAMax8 =  adc2mV(bufferAMax8, chARange, maxADC)
adc2mVChAMax9 =  adc2mV(bufferAMax9, chARange, maxADC)

# Creates the time data
time = np.linspace(0, (cmaxSamples.value) * timeIntervalns.value, cmaxSamples.value)

# Plots the data from channel A onto a graph
plt.plot(time, adc2mVChAMax[:])
Ejemplo n.º 23
0
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