|
20 | 20 | status["openunit"] = drDaq.UsbDrDaqOpenUnit(ctypes.byref(chandle)) |
21 | 21 | assert_pico_ok(status["openunit"]) |
22 | 22 |
|
| 23 | +# Set sample interval |
| 24 | +us_for_block = ctypes.c_int32(1000) |
| 25 | +ideal_no_of_samples = 1000 |
| 26 | +channels = ctypes.c_int32(drDaq.USB_DRDAQ_INPUTS["USB_DRDAQ_CHANNEL_SCOPE"]) |
| 27 | +no_of_channels = 1 |
| 28 | +status["setInterval"] = drDaq.UsbDrDaqSetInterval(chandle, ctypes.byref(us_for_block), ideal_no_of_samples, ctypes.byref(channels), no_of_channels) |
| 29 | +assert_pico_ok(status["setInterval"]) |
| 30 | + |
| 31 | +# Find scaling information |
| 32 | +channel = drDaq.USB_DRDAQ_INPUTS["USB_DRDAQ_CHANNEL_SCOPE"] |
| 33 | +nScales = ctypes.c_int16(0) |
| 34 | +currentScale = ctypes.c_int16(0) |
| 35 | +names = (ctypes.c_char*256)() |
| 36 | +namesSize = 256 |
| 37 | +status["getscalings"] = drDaq.UsbDrDaqGetScalings(chandle, channel, ctypes.byref(nScales), ctypes.byref(currentScale), ctypes.byref(names), namesSize) |
| 38 | +assert_pico_ok(status["getscalings"]) |
| 39 | + |
| 40 | +print(nScales.value) |
| 41 | +print(currentScale.value) |
| 42 | +print(names.value) |
| 43 | + |
| 44 | +# Set channel scaling |
| 45 | +scalingNumber = drDaq.USB_DRDAQ_SCOPE_RANGE["USB_DRDAQ_2V5"] |
| 46 | +status["setscaling"] = drDaq.UsbDrDaqSetScalings(chandle, channel, scalingNumber) |
| 47 | +assert_pico_ok(status["setscaling"]) |
| 48 | + |
| 49 | +# Set trigger |
| 50 | +enabled = 1 |
| 51 | +auto_trigger = 1 |
| 52 | +auto_ms = 1000 # in ms |
| 53 | +dir = 0 # rising edge |
| 54 | +threshold = 1000 # in mV |
| 55 | +hysteresis = 50 # in ADC counts |
| 56 | +delay = -50 # trigger in centre of block |
| 57 | +status["settrigger"] = drDaq.UsbDrDaqSetTrigger(chandle, enabled, auto_trigger, auto_ms, channel, dir, threshold, hysteresis, delay) |
| 58 | +assert_pico_ok(status["settrigger"]) |
| 59 | + |
| 60 | +# Run block capture |
| 61 | +method = drDaq.USB_DRDAQ_BLOCK_METHOD["BM_SINGLE"] |
| 62 | +status["run"] = drDaq.UsbDrDaqRun(chandle, ideal_no_of_samples, method) |
| 63 | +assert_pico_ok(status["run"]) |
| 64 | + |
| 65 | +ready = ctypes.c_int16(0) |
| 66 | + |
| 67 | +while ready.value == 0: |
| 68 | + status["ready"] = drDaq.UsbDrDaqReady(chandle, ctypes.byref(ready)) |
| 69 | + print(ready.value) |
| 70 | + time.sleep(0.1) |
| 71 | + |
| 72 | +# Retrieve data from device |
| 73 | +values = (ctypes.c_float * ideal_no_of_samples)() |
| 74 | +noOfValues = ctypes.c_uint32(ideal_no_of_samples) |
| 75 | +overflow = ctypes.c_uint16(0) |
| 76 | +triggerIndex = ctypes.c_uint32(0) |
| 77 | +status["getvaluesF"] = drDaq.UsbDrDaqGetValuesF(chandle, ctypes.byref(values), ctypes.byref(noOfValues), ctypes.byref(overflow), ctypes.byref(triggerIndex)) |
| 78 | +assert_pico_ok(status["getvaluesF"]) |
| 79 | + |
| 80 | +# generate time data |
| 81 | +time = np.linspace(0, us_for_block, ideal_no_of_samples) |
| 82 | + |
| 83 | +# plot the data |
| 84 | +plt.plot(time, values[:]) |
| 85 | +plt.xlabel('Time (ns)') |
| 86 | +plt.ylabel('Voltage (mV)') |
| 87 | +plt.show() |
| 88 | + |
| 89 | + |
23 | 90 | # Disconnect the scope |
24 | 91 | # handle = chandle |
25 | 92 | status["close"] = drDaq.UsbDrDaqCloseUnit(chandle) |
|
0 commit comments