コード例 #1
0
# coupling type = PS2000A_DC = 1
# range = PS2000A_2V = 7
# analogue offset = 0 V
chCRange = 7
status["setChC"] = ps.ps2000aSetChannel(chandle, 2, 1, 1, chCRange, 0)
assert_pico_ok(status["setChC"])

# Set up single trigger
# handle = chandle
# enabled = 1
# source = PS2000A_CHANNEL_A = 0
# threshold = 1024 ADC counts
# direction = PS2000A_RISING = 2
# delay = 0 s
# auto Trigger = 1000 ms
status["trigger"] = ps.ps2000aSetSimpleTrigger(chandle, 1, 0, 1024, 2, 0, 1000)
assert_pico_ok(status["trigger"])

# Set number of pre and post trigger samples to be collected
preTriggerSamples = 2500
postTriggerSamples = 2500
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 = 2
コード例 #2
0
ファイル: nabiraniA.py プロジェクト: davidmiony/miony
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