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
# operation = 0 # shots = 0 # sweeps = 0 # triggerType = ctypes.c_int16(1) = PS2000a_SIGGEN_NONE # triggerSource = ctypes.c_int16(1) = P2000a_SIGGEN_NONE # extInThreshold = 1 wavetype = ctypes.c_int16(1) sweepType = ctypes.c_int32(2) triggertype = ctypes.c_int32(0) triggerSource = ctypes.c_int32(0) status["SetSigGenBuiltIn"] = ps.ps2000aSetSigGenBuiltIn( chandle, 0, 2000000, wavetype, 10000, 100000, 5, 1, sweepType, 0, 0, 0, triggertype, triggerSource, 1) assert_pico_ok(status["SetSigGenBuiltIn"]) # pauses the script to show signal time.sleep(36) # Stops the scope # Handle = chandle status["stop"] = ps.ps2000aStop(chandle) assert_pico_ok(status["stop"]) # Closes the unit # Handle = chandle status["close"] = ps.ps2000aCloseUnit(chandle) assert_pico_ok(status["close"]) # Displays the staus returns print(status)
def stop(self): """Stop picoscope.""" self.status["stop"] = ps.ps2000aStop(self.chandle) assert_pico_ok(self.status["stop"]) self.status["close"] = ps.ps2000aCloseUnit(self.chandle) assert_pico_ok(self.status["close"])