|
| 1 | +# |
| 2 | +# Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms. |
| 3 | +# |
| 4 | +# ps6000 RAPID BLOCK MODE EXAMPLE |
| 5 | +# This example opens a 6000 driver device, sets up one channel and a trigger then collects 10 block of data in rapid succession. |
| 6 | +# This data is then plotted as mV against time in ns. |
| 7 | + |
| 8 | +import ctypes |
| 9 | +from picosdk.ps6000 import ps6000 as ps |
| 10 | +import numpy as np |
| 11 | +import matplotlib.pyplot as plt |
| 12 | +from picosdk.functions import adc2mV, assert_pico_ok |
| 13 | + |
| 14 | +# Create chandle and status ready for use |
| 15 | +status = {} |
| 16 | +chandle = ctypes.c_int16() |
| 17 | + |
| 18 | +# Opens the device/s |
| 19 | +status["openunit"] = ps.ps6000OpenUnit(ctypes.byref(chandle), None) |
| 20 | +assert_pico_ok(status["openunit"]) |
| 21 | + |
| 22 | +# Displays the serial number and handle |
| 23 | +print(chandle.value) |
| 24 | + |
| 25 | +# Set up channel A |
| 26 | +# handle = chandle |
| 27 | +# channel = ps6000_CHANNEL_A = 0 |
| 28 | +# enabled = 1 |
| 29 | +# coupling type = ps6000_DC = 1 |
| 30 | +# range = ps6000_10V = 8 |
| 31 | +# analogue offset = 0 V |
| 32 | +chARange = 8 |
| 33 | +status["setChA"] = ps.ps6000SetChannel(chandle, 0, 1, 1, chARange, 0, 0) |
| 34 | +assert_pico_ok(status["setChA"]) |
| 35 | + |
| 36 | +# Sets up single trigger |
| 37 | +# Handle = Chandle |
| 38 | +# Enable = 1 |
| 39 | +# Source = ps6000_channel_A = 0 |
| 40 | +# Threshold = 1024 ADC counts |
| 41 | +# Direction = ps6000_Falling = 3 |
| 42 | +# Delay = 0 |
| 43 | +# autoTrigger_ms = 1000 |
| 44 | +status["trigger"] = ps.ps6000SetSimpleTrigger(chandle, 1, 0, 1024, 3, 0, 1000) |
| 45 | +assert_pico_ok(status["setChA"]) |
| 46 | + |
| 47 | +# Setting the number of sample to be collected |
| 48 | +preTriggerSamples = 400 |
| 49 | +postTriggerSamples = 400 |
| 50 | +maxsamples = preTriggerSamples + postTriggerSamples |
| 51 | + |
| 52 | +# Gets timebase innfomation |
| 53 | +# Handle = chandle |
| 54 | +# Timebase = 2 = timebase |
| 55 | +# Nosample = maxsamples |
| 56 | +# TimeIntervalNanoseconds = ctypes.byref(timeIntervalns) |
| 57 | +# MaxSamples = ctypes.byref(returnedMaxSamples) |
| 58 | +# Segement index = 0 |
| 59 | +timebase = 2 |
| 60 | +timeIntervalns = ctypes.c_float() |
| 61 | +returnedMaxSamples = ctypes.c_int16() |
| 62 | +status["GetTimebase"] = ps.ps6000GetTimebase2(chandle, timebase, maxsamples, ctypes.byref(timeIntervalns), 1, ctypes.byref(returnedMaxSamples), 0) |
| 63 | +assert_pico_ok(status["GetTimebase"]) |
| 64 | + |
| 65 | +# Creates a overlow location for data |
| 66 | +overflow = ctypes.c_int16() |
| 67 | +# Creates converted types maxsamples |
| 68 | +cmaxSamples = ctypes.c_int32(maxsamples) |
| 69 | + |
| 70 | +# Handle = Chandle |
| 71 | +# nSegments = 10 |
| 72 | +# nMaxSamples = ctypes.byref(cmaxSamples) |
| 73 | + |
| 74 | +status["MemorySegments"] = ps.ps6000MemorySegments(chandle, 10, ctypes.byref(cmaxSamples)) |
| 75 | +assert_pico_ok(status["MemorySegments"]) |
| 76 | + |
| 77 | +# sets number of captures |
| 78 | +status["SetNoOfCaptures"] = ps.ps6000SetNoOfCaptures(chandle, 10) |
| 79 | +assert_pico_ok(status["SetNoOfCaptures"]) |
| 80 | + |
| 81 | +# Starts the block capture |
| 82 | +# Handle = chandle |
| 83 | +# Number of prTriggerSamples |
| 84 | +# Number of postTriggerSamples |
| 85 | +# Timebase = 2 = 4ns (see Programmer's guide for more information on timebases) |
| 86 | +# time indisposed ms = None (This is not needed within the example) |
| 87 | +# Segment index = 0 |
| 88 | +# LpRead = None |
| 89 | +# pParameter = None |
| 90 | +status["runblock"] = ps.ps6000RunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, 1, None, 0, None, None) |
| 91 | +assert_pico_ok(status["runblock"]) |
| 92 | + |
| 93 | +# Create buffers ready for assigning pointers for data collection |
| 94 | +bufferAMax = (ctypes.c_int16 * maxsamples)() |
| 95 | +bufferAMin = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example |
| 96 | + |
| 97 | +# Setting the data buffer location for data collection from channel A |
| 98 | +# Handle = Chandle |
| 99 | +# source = ps6000_channel_A = 0 |
| 100 | +# Buffer max = ctypes.byref(bufferAMax) |
| 101 | +# Buffer min = ctypes.byref(bufferAMin) |
| 102 | +# Buffer length = maxsamples |
| 103 | +# Segment index = 0 |
| 104 | +# Ratio mode = ps6000_Ratio_Mode_None = 0 |
| 105 | +status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxsamples, 0, 0) |
| 106 | +assert_pico_ok(status["SetDataBuffersBulk"]) |
| 107 | + |
| 108 | +# Create buffers ready for assigning pointers for data collection |
| 109 | +bufferAMax1 = (ctypes.c_int16 * maxsamples)() |
| 110 | +bufferAMin1 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example |
| 111 | + |
| 112 | +# Setting the data buffer location for data collection from channel A |
| 113 | +# Handle = Chandle |
| 114 | +# source = ps6000_channel_A = 0 |
| 115 | +# Buffer max = ctypes.byref(bufferAMax) |
| 116 | +# Buffer min = ctypes.byref(bufferAMin) |
| 117 | +# Buffer length = maxsamples |
| 118 | +# Segment index = 1 |
| 119 | +# Ratio mode = ps6000_Ratio_Mode_None = 0 |
| 120 | +status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax1), ctypes.byref(bufferAMin1), maxsamples, 1, 0) |
| 121 | +assert_pico_ok(status["SetDataBuffersBulk"]) |
| 122 | + |
| 123 | +# Create buffers ready for assigning pointers for data collection |
| 124 | +bufferAMax2 = (ctypes.c_int16 * maxsamples)() |
| 125 | +bufferAMin2 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example |
| 126 | + |
| 127 | +# Setting the data buffer location for data collection from channel A |
| 128 | +# Handle = Chandle |
| 129 | +# source = ps6000_channel_A = 0 |
| 130 | +# Buffer max = ctypes.byref(bufferAMax) |
| 131 | +# Buffer min = ctypes.byref(bufferAMin) |
| 132 | +# Buffer length = maxsamples |
| 133 | +# Segment index = 2 |
| 134 | +# Ratio mode = ps6000_Ratio_Mode_None = 0 |
| 135 | +status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax2), ctypes.byref(bufferAMin2), maxsamples, 2, 0) |
| 136 | +assert_pico_ok(status["SetDataBuffersBulk"]) |
| 137 | + |
| 138 | + |
| 139 | +# Create buffers ready for assigning pointers for data collection |
| 140 | +bufferAMax3 = (ctypes.c_int16 * maxsamples)() |
| 141 | +bufferAMin3 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example |
| 142 | + |
| 143 | +# Setting the data buffer location for data collection from channel A |
| 144 | +# Handle = Chandle |
| 145 | +# source = ps6000_channel_A = 0 |
| 146 | +# Buffer max = ctypes.byref(bufferAMax) |
| 147 | +# Buffer min = ctypes.byref(bufferAMin) |
| 148 | +# Buffer length = maxsamples |
| 149 | +# Segment index = 3 |
| 150 | +# Ratio mode = ps6000_Ratio_Mode_None = 0 |
| 151 | +status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax3), ctypes.byref(bufferAMin3), maxsamples, 3, 0) |
| 152 | +assert_pico_ok(status["SetDataBuffersBulk"]) |
| 153 | + |
| 154 | +# Create buffers ready for assigning pointers for data collection |
| 155 | +bufferAMax4 = (ctypes.c_int16 * maxsamples)() |
| 156 | +bufferAMin4 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example |
| 157 | + |
| 158 | +# Setting the data buffer location for data collection from channel A |
| 159 | +# Handle = Chandle |
| 160 | +# source = ps6000_channel_A = 0 |
| 161 | +# Buffer max = ctypes.byref(bufferAMax) |
| 162 | +# Buffer min = ctypes.byref(bufferAMin) |
| 163 | +# Buffer length = maxsamples |
| 164 | +# Segment index = 4 |
| 165 | +# Ratio mode = ps6000_Ratio_Mode_None = 0 |
| 166 | +status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax4), ctypes.byref(bufferAMin4), maxsamples, 4, 0) |
| 167 | +assert_pico_ok(status["SetDataBuffersBulk"]) |
| 168 | + |
| 169 | +# Create buffers ready for assigning pointers for data collection |
| 170 | +bufferAMax5 = (ctypes.c_int16 * maxsamples)() |
| 171 | +bufferAMin5 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example |
| 172 | + |
| 173 | +# Setting the data buffer location for data collection from channel A |
| 174 | +# Handle = Chandle |
| 175 | +# source = ps6000_channel_A = 0 |
| 176 | +# Buffer max = ctypes.byref(bufferAMax) |
| 177 | +# Buffer min = ctypes.byref(bufferAMin) |
| 178 | +# Buffer length = maxsamples |
| 179 | +# Segment index = 5 |
| 180 | +# Ratio mode = ps6000_Ratio_Mode_None = 0 |
| 181 | +status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax5), ctypes.byref(bufferAMin5), maxsamples, 5, 0) |
| 182 | +assert_pico_ok(status["SetDataBuffersBulk"]) |
| 183 | + |
| 184 | +# Create buffers ready for assigning pointers for data collection |
| 185 | +bufferAMax6 = (ctypes.c_int16 * maxsamples)() |
| 186 | +bufferAMin6 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example |
| 187 | + |
| 188 | +# Setting the data buffer location for data collection from channel A |
| 189 | +# Handle = Chandle |
| 190 | +# source = ps6000_channel_A = 0 |
| 191 | +# Buffer max = ctypes.byref(bufferAMax) |
| 192 | +# Buffer min = ctypes.byref(bufferAMin) |
| 193 | +# Buffer length = maxsamples |
| 194 | +# Segment index = 6 |
| 195 | +# Ratio mode = ps6000_Ratio_Mode_None = 0 |
| 196 | +status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax6), ctypes.byref(bufferAMin6), maxsamples, 6, 0) |
| 197 | +assert_pico_ok(status["SetDataBuffersBulk"]) |
| 198 | + |
| 199 | +# Create buffers ready for assigning pointers for data collection |
| 200 | +bufferAMax7 = (ctypes.c_int16 * maxsamples)() |
| 201 | +bufferAMin7 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example |
| 202 | + |
| 203 | +# Setting the data buffer location for data collection from channel A |
| 204 | +# Handle = Chandle |
| 205 | +# source = ps6000_channel_A = 0 |
| 206 | +# Buffer max = ctypes.byref(bufferAMax) |
| 207 | +# Buffer min = ctypes.byref(bufferAMin) |
| 208 | +# Buffer length = maxsamples |
| 209 | +# Segment index = 7 |
| 210 | +# Ratio mode = ps6000_Ratio_Mode_None = 0 |
| 211 | +status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax7), ctypes.byref(bufferAMin7), maxsamples, 7, 0) |
| 212 | +assert_pico_ok(status["SetDataBuffersBulk"]) |
| 213 | + |
| 214 | +# Create buffers ready for assigning pointers for data collection |
| 215 | +bufferAMax8 = (ctypes.c_int16 * maxsamples)() |
| 216 | +bufferAMin8 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example |
| 217 | + |
| 218 | +# Setting the data buffer location for data collection from channel A |
| 219 | +# Handle = Chandle |
| 220 | +# source = ps6000_channel_A = 0 |
| 221 | +# Buffer max = ctypes.byref(bufferAMax) |
| 222 | +# Buffer min = ctypes.byref(bufferAMin) |
| 223 | +# Buffer length = maxsamples |
| 224 | +# Segment index = 8 |
| 225 | +# Ratio mode = ps6000_Ratio_Mode_None = 0 |
| 226 | +status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax8), ctypes.byref(bufferAMin8), maxsamples, 8, 0) |
| 227 | +assert_pico_ok(status["SetDataBuffersBulk"]) |
| 228 | + |
| 229 | +# Create buffers ready for assigning pointers for data collection |
| 230 | +bufferAMax9 = (ctypes.c_int16 * maxsamples)() |
| 231 | +bufferAMin9 = (ctypes.c_int16 * maxsamples)() # used for downsampling which isn't in the scope of this example |
| 232 | + |
| 233 | +# Setting the data buffer location for data collection from channel A |
| 234 | +# Handle = Chandle |
| 235 | +# source = ps6000_channel_A = 0 |
| 236 | +# Buffer max = ctypes.byref(bufferAMax) |
| 237 | +# Buffer min = ctypes.byref(bufferAMin) |
| 238 | +# Buffer length = maxsamples |
| 239 | +# Segment index = 9 |
| 240 | +# Ratio mode = ps6000_Ratio_Mode_None = 0 |
| 241 | +status["SetDataBuffersBulk"] = ps.ps6000SetDataBuffersBulk(chandle, 0, ctypes.byref(bufferAMax9), ctypes.byref(bufferAMin9), maxsamples, 9, 0) |
| 242 | +assert_pico_ok(status["SetDataBuffersBulk"]) |
| 243 | + |
| 244 | +# Creates a overlow location for data |
| 245 | +overflow = (ctypes.c_int16 * 10)() |
| 246 | +# Creates converted types maxsamples |
| 247 | +cmaxSamples = ctypes.c_int32(maxsamples) |
| 248 | + |
| 249 | +# Checks data collection to finish the capture |
| 250 | +ready = ctypes.c_int16(0) |
| 251 | +check = ctypes.c_int16(0) |
| 252 | +while ready.value == check.value: |
| 253 | + status["isReady"] = ps.ps6000IsReady(chandle, ctypes.byref(ready)) |
| 254 | + |
| 255 | +# Handle = chandle |
| 256 | +# noOfSamples = ctypes.byref(cmaxSamples) |
| 257 | +# fromSegmentIndex = 0 |
| 258 | +# ToSegmentIndex = 9 |
| 259 | +# DownSampleRatio = 0 |
| 260 | +# DownSampleRatioMode = 0 |
| 261 | +# Overflow = ctypes.byref(overflow) |
| 262 | + |
| 263 | +status["GetValuesBulk"] = ps.ps6000GetValuesBulk(chandle, ctypes.byref(cmaxSamples), 0, 9, 0, 0, ctypes.byref(overflow)) |
| 264 | +assert_pico_ok(status["GetValuesBulk"]) |
| 265 | + |
| 266 | +# Handle = chandle |
| 267 | +# Times = Times = (ctypes.c_int16*10)() = ctypes.byref(Times) |
| 268 | +# Timeunits = TimeUnits = ctypes.c_char() = ctypes.byref(TimeUnits) |
| 269 | +# Fromsegmentindex = 0 |
| 270 | +# Tosegementindex = 9 |
| 271 | +Times = (ctypes.c_int16*10)() |
| 272 | +TimeUnits = ctypes.c_char() |
| 273 | +status["GetValuesTriggerTimeOffsetBulk"] = ps.ps6000GetValuesTriggerTimeOffsetBulk64(chandle, ctypes.byref(Times), ctypes.byref(TimeUnits), 0, 9) |
| 274 | +assert_pico_ok(status["GetValuesTriggerTimeOffsetBulk"]) |
| 275 | + |
| 276 | +# Finds the max ADC count |
| 277 | +maxADC = ctypes.c_int16(32512) |
| 278 | + |
| 279 | +# Converts ADC from channel A to mV |
| 280 | +adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC) |
| 281 | +adc2mVChAMax1 = adc2mV(bufferAMax1, chARange, maxADC) |
| 282 | +adc2mVChAMax2 = adc2mV(bufferAMax2, chARange, maxADC) |
| 283 | +adc2mVChAMax3 = adc2mV(bufferAMax3, chARange, maxADC) |
| 284 | +adc2mVChAMax4 = adc2mV(bufferAMax4, chARange, maxADC) |
| 285 | +adc2mVChAMax5 = adc2mV(bufferAMax5, chARange, maxADC) |
| 286 | +adc2mVChAMax6 = adc2mV(bufferAMax6, chARange, maxADC) |
| 287 | +adc2mVChAMax7 = adc2mV(bufferAMax7, chARange, maxADC) |
| 288 | +adc2mVChAMax8 = adc2mV(bufferAMax8, chARange, maxADC) |
| 289 | +adc2mVChAMax9 = adc2mV(bufferAMax9, chARange, maxADC) |
| 290 | + |
| 291 | +# Creates the time data |
| 292 | +time = np.linspace(0, (cmaxSamples.value) * timeIntervalns.value, cmaxSamples.value) |
| 293 | + |
| 294 | +"""# Plots the data from channel A onto a graph |
| 295 | +plt.plot(time, adc2mVChAMax[:]) |
| 296 | +plt.plot(time, adc2mVChAMax1[:]) |
| 297 | +plt.plot(time, adc2mVChAMax2[:]) |
| 298 | +plt.plot(time, adc2mVChAMax3[:]) |
| 299 | +plt.plot(time, adc2mVChAMax4[:]) |
| 300 | +plt.plot(time, adc2mVChAMax5[:]) |
| 301 | +plt.plot(time, adc2mVChAMax6[:]) |
| 302 | +plt.plot(time, adc2mVChAMax7[:]) |
| 303 | +plt.plot(time, adc2mVChAMax8[:]) |
| 304 | +plt.plot(time, adc2mVChAMax9[:]) |
| 305 | +plt.xlabel('Time (ns)') |
| 306 | +plt.ylabel('Voltage (mV)') |
| 307 | +plt.show()""" |
| 308 | + |
| 309 | +# Create the trigger timestamping structure |
| 310 | + |
| 311 | +triggerInfo = (ps.PS6000_TRIGGER_INFO * 10)() |
| 312 | + |
| 313 | +# Collect time stamp information |
| 314 | +status["triggerTimes"] = ps.ps6000GetTriggerInfoBulk(chandle, ctypes.byref(triggerInfo), 0, 9) |
| 315 | +assert_pico_ok(status["triggerTimes"]) |
| 316 | + |
| 317 | +# retrieve information from the structure |
| 318 | + |
| 319 | +print("segmentIndex") |
| 320 | +for i in range(0,9): |
| 321 | + print(triggerInfo[i].segmentIndex) |
| 322 | + |
| 323 | +print("status") |
| 324 | +for i in range(0,9): |
| 325 | + print(triggerInfo[i].status) |
| 326 | + |
| 327 | +print("timeStampCounter") |
| 328 | +for i in range(0,9): |
| 329 | + print(triggerInfo[i].timeStampCounter) |
| 330 | + |
| 331 | +# Stops the scope |
| 332 | +# Handle = chandle |
| 333 | +status["stop"] = ps.ps6000Stop(chandle) |
| 334 | +assert_pico_ok(status["stop"]) |
| 335 | + |
| 336 | +# Closes the unit |
| 337 | +# Handle = chandle |
| 338 | +status["close"] = ps.ps6000CloseUnit(chandle) |
| 339 | +assert_pico_ok(status["close"]) |
| 340 | + |
| 341 | +# Displays the staus returns |
| 342 | +print(status) |
| 343 | + |
0 commit comments