Skip to content

Commit e98fdd3

Browse files
author
neil.hamilton
committed
Add ps5000RapidBlockExample.py to repo
1 parent bba436e commit e98fdd3

File tree

1 file changed

+295
-0
lines changed

1 file changed

+295
-0
lines changed
Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
1+
#
2+
# Copyright (C) 2018-2022 Pico Technology Ltd. See LICENSE file for terms.
3+
#
4+
# ps5000 RAPID BLOCK MODE EXAMPLE
5+
# This example opens a 5000 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.ps5000 import ps5000 as ps
10+
import numpy as np
11+
import matplotlib.pyplot as plt
12+
from picosdk.functions import adc2mV, assert_pico_ok, mV2adc
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.ps5000OpenUnit(ctypes.byref(chandle))
20+
assert_pico_ok(status["openunit"])
21+
22+
23+
# Displays the serial number and handle
24+
print(chandle.value)
25+
26+
# Set up channel A
27+
# handle = chandle
28+
channel = ps.PS5000_CHANNEL["PS5000_CHANNEL_A"]
29+
# enabled = 1
30+
coupling_type = 1 # DC
31+
chARange = ps.PS5000_RANGE["PS5000_5V"]
32+
status["setChA"] = ps.ps5000SetChannel(chandle, channel, 1, coupling_type, chARange, 0)
33+
assert_pico_ok(status["setChA"])
34+
35+
36+
# Finds the max ADC count
37+
# Handle = chandle
38+
# Value = ctype.byref(maxADC)
39+
maxADC = ctypes.c_int16(32512)
40+
41+
42+
# Set up single trigger
43+
# handle = chandle
44+
# enabled = 1
45+
source = ps.PS5000_CHANNEL["PS5000_CHANNEL_A"]
46+
threshold = int(mV2adc(500,chARange, maxADC))
47+
# direction = PS5000_RISING = 2
48+
# delay = 0 s
49+
# auto Trigger = 1000 ms
50+
status["trigger"] = ps.ps5000SetSimpleTrigger(chandle, 1, source, threshold, 2, 0, 1000)
51+
assert_pico_ok(status["trigger"])
52+
53+
# Setting the number of sample to be collected
54+
preTriggerSamples = 400
55+
postTriggerSamples = 400
56+
maxsamples = preTriggerSamples + postTriggerSamples
57+
58+
# Gets timebase innfomation
59+
# Warning: When using this example it may not be possible to access all Timebases as all channels are enabled by default when opening the scope.
60+
# To access these Timebases, set any unused analogue channels to off.
61+
# Handle = chandle
62+
timebase = 2
63+
# Nosample = maxsamples
64+
# TimeIntervalNanoseconds = ctypes.byref(timeIntervalns)
65+
# MaxSamples = ctypes.byref(returnedMaxSamples)
66+
# Segement index = 0
67+
timeIntervalns = ctypes.c_float()
68+
oversample = 1
69+
returnedMaxSamples = ctypes.c_int16()
70+
status["GetTimebase"] = ps.ps5000GetTimebase(chandle, timebase, maxsamples, ctypes.byref(timeIntervalns), oversample, ctypes.byref(returnedMaxSamples), 0)
71+
assert_pico_ok(status["GetTimebase"])
72+
73+
# Creates a overlow location for data
74+
overflow = ctypes.c_int16()
75+
# Creates converted types maxsamples
76+
cmaxSamples = ctypes.c_int32(maxsamples)
77+
78+
# Handle = Chandle
79+
# nSegments = 10
80+
# nMaxSamples = ctypes.byref(cmaxSamples)
81+
status["MemorySegments"] = ps.ps5000MemorySegments(chandle, 10, ctypes.byref(cmaxSamples))
82+
assert_pico_ok(status["MemorySegments"])
83+
84+
# sets number of captures
85+
status["SetNoOfCaptures"] = ps.ps5000SetNoOfCaptures(chandle, 10)
86+
assert_pico_ok(status["SetNoOfCaptures"])
87+
88+
# Starts the block capture
89+
# Handle = chandle
90+
# Number of prTriggerSamples
91+
# Number of postTriggerSamples
92+
# Timebase = 2 = 4ns (see Programmer's guide for more information on timebases)
93+
# time indisposed ms = None (This is not needed within the example)
94+
# Segment index = 0
95+
# LpRead = None
96+
# pParameter = None
97+
status["runblock"] = ps.ps5000RunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, oversample, None, 0, None, None)
98+
assert_pico_ok(status["runblock"])
99+
100+
# Create buffers ready for assigning pointers for data collection
101+
bufferAMax = (ctypes.c_int16 * maxsamples)()
102+
103+
# Setting the data buffer location for data collection from channel A
104+
# Handle = Chandle
105+
source = ps.PS5000_CHANNEL["PS5000_CHANNEL_A"]
106+
# Buffer max = ctypes.byref(bufferAMax)
107+
# Buffer length = maxsamples
108+
# Segment index = 0
109+
status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxsamples, 0)
110+
assert_pico_ok(status["SetDataBuffers"])
111+
112+
# Create buffers ready for assigning pointers for data collection
113+
bufferAMax1 = (ctypes.c_int16 * maxsamples)()
114+
115+
# Setting the data buffer location for data collection from channel A
116+
# Handle = Chandle
117+
# source = ps.PS5000_CHANNEL["ps5000_channel_A"]
118+
# Buffer max = ctypes.byref(bufferAMax)
119+
# Buffer length = maxsamples
120+
# Segment index = 1
121+
status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax1), ctypes.byref(bufferAMin1), maxsamples, 1)
122+
assert_pico_ok(status["SetDataBuffers"])
123+
124+
# Create buffers ready for assigning pointers for data collection
125+
bufferAMax2 = (ctypes.c_int16 * maxsamples)()
126+
127+
# Setting the data buffer location for data collection from channel A
128+
# Handle = Chandle
129+
# source = ps.PS5000_CHANNEL["ps5000_channel_A"]
130+
# Buffer max = ctypes.byref(bufferAMax)
131+
# Buffer length = maxsamples
132+
# Segment index = 2
133+
status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax2), ctypes.byref(bufferAMin2), maxsamples, 2)
134+
assert_pico_ok(status["SetDataBuffers"])
135+
136+
# Create buffers ready for assigning pointers for data collection
137+
bufferAMax3 = (ctypes.c_int16 * maxsamples)()
138+
139+
# Setting the data buffer location for data collection from channel A
140+
# Handle = Chandle
141+
# source = ps.PS5000_CHANNEL["ps5000_channel_A"]
142+
# Buffer max = ctypes.byref(bufferAMax)
143+
# Buffer length = maxsamples
144+
# Segment index = 3
145+
status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax3), ctypes.byref(bufferAMin3), maxsamples, 3)
146+
assert_pico_ok(status["SetDataBuffers"])
147+
148+
# Create buffers ready for assigning pointers for data collection
149+
bufferAMax4 = (ctypes.c_int16 * maxsamples)()
150+
151+
# Setting the data buffer location for data collection from channel A
152+
# Handle = Chandle
153+
# source = ps.PS5000_CHANNEL["ps5000_channel_A"]
154+
# Buffer max = ctypes.byref(bufferAMax)
155+
# Buffer length = maxsamples
156+
# Segment index = 4
157+
status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax4), ctypes.byref(bufferAMin4), maxsamples, 4)
158+
assert_pico_ok(status["SetDataBuffers"])
159+
160+
# Create buffers ready for assigning pointers for data collection
161+
bufferAMax5 = (ctypes.c_int16 * maxsamples)()
162+
163+
# Setting the data buffer location for data collection from channel A
164+
# Handle = Chandle
165+
# source = ps.PS5000_CHANNEL["ps5000_channel_A"]
166+
# Buffer max = ctypes.byref(bufferAMax)
167+
# Buffer length = maxsamples
168+
# Segment index = 5
169+
status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax5), ctypes.byref(bufferAMin5), maxsamples, 5)
170+
assert_pico_ok(status["SetDataBuffers"])
171+
172+
# Create buffers ready for assigning pointers for data collection
173+
bufferAMax6 = (ctypes.c_int16 * maxsamples)()
174+
175+
# Setting the data buffer location for data collection from channel A
176+
# Handle = Chandle
177+
# source = ps.PS5000_CHANNEL["ps5000_channel_A"]
178+
# Buffer max = ctypes.byref(bufferAMax)
179+
# Buffer length = maxsamples
180+
# Segment index = 6
181+
status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax6), ctypes.byref(bufferAMin6), maxsamples, 6)
182+
assert_pico_ok(status["SetDataBuffers"])
183+
184+
# Create buffers ready for assigning pointers for data collection
185+
bufferAMax7 = (ctypes.c_int16 * maxsamples)()
186+
187+
# Setting the data buffer location for data collection from channel A
188+
# Handle = Chandle
189+
# source = ps.PS5000_CHANNEL["ps5000_channel_A"]
190+
# Buffer max = ctypes.byref(bufferAMax)
191+
# Buffer length = maxsamples
192+
# Segment index = 7
193+
status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax7), ctypes.byref(bufferAMin7), maxsamples, 7)
194+
assert_pico_ok(status["SetDataBuffers"])
195+
196+
# Create buffers ready for assigning pointers for data collection
197+
bufferAMax8 = (ctypes.c_int16 * maxsamples)()
198+
199+
# Setting the data buffer location for data collection from channel A
200+
# Handle = Chandle
201+
# source = ps.PS5000_CHANNEL["ps5000_channel_A"]
202+
# Buffer max = ctypes.byref(bufferAMax)
203+
# Buffer length = maxsamples
204+
# Segment index = 8
205+
status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax8), ctypes.byref(bufferAMin8), maxsamples, 8)
206+
assert_pico_ok(status["SetDataBuffers"])
207+
208+
# Create buffers ready for assigning pointers for data collection
209+
bufferAMax9 = (ctypes.c_int16 * maxsamples)()
210+
211+
# Setting the data buffer location for data collection from channel A
212+
# Handle = Chandle
213+
# source = ps.PS5000_CHANNEL["ps5000_channel_A"]
214+
# Buffer max = ctypes.byref(bufferAMax)
215+
# Buffer length = maxsamples
216+
# Segment index = 9
217+
status["SetDataBuffers"] = ps.ps5000SetDataBufferBulk(chandle, source, ctypes.byref(bufferAMax9), ctypes.byref(bufferAMin9), maxsamples, 9)
218+
assert_pico_ok(status["SetDataBuffers"])
219+
220+
# Creates a overlow location for data
221+
overflow = (ctypes.c_int16 * 10)()
222+
# Creates converted types maxsamples
223+
cmaxSamples = ctypes.c_int32(maxsamples)
224+
225+
# Checks data collection to finish the capture
226+
ready = ctypes.c_int16(0)
227+
check = ctypes.c_int16(0)
228+
while ready.value == check.value:
229+
status["isReady"] = ps.ps5000IsReady(chandle, ctypes.byref(ready))
230+
231+
# Handle = chandle
232+
# noOfSamples = ctypes.byref(cmaxSamples)
233+
# fromSegmentIndex = 0
234+
# ToSegmentIndex = 9
235+
# DownSampleRatio = 0
236+
# DownSampleRatioMode = 0
237+
# Overflow = ctypes.byref(overflow)
238+
239+
status["GetValuesBulk"] = ps.ps5000GetValuesBulk(chandle, ctypes.byref(cmaxSamples), 0, 9, ctypes.byref(overflow))
240+
assert_pico_ok(status["GetValuesBulk"])
241+
242+
# Handle = chandle
243+
# Times = Times = (ctypes.c_int16*10)() = ctypes.byref(Times)
244+
# Timeunits = TimeUnits = ctypes.c_char() = ctypes.byref(TimeUnits)
245+
# Fromsegmentindex = 0
246+
# Tosegementindex = 9
247+
Times = (ctypes.c_int16*10)()
248+
TimeUnits = ctypes.c_char()
249+
status["GetValuesTriggerTimeOffsetBulk"] = ps.ps5000GetValuesTriggerTimeOffsetBulk64(chandle, ctypes.byref(Times), ctypes.byref(TimeUnits), 0, 9)
250+
assert_pico_ok(status["GetValuesTriggerTimeOffsetBulk"])
251+
252+
# Converts ADC from channel A to mV
253+
adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC)
254+
adc2mVChAMax1 = adc2mV(bufferAMax1, chARange, maxADC)
255+
adc2mVChAMax2 = adc2mV(bufferAMax2, chARange, maxADC)
256+
adc2mVChAMax3 = adc2mV(bufferAMax3, chARange, maxADC)
257+
adc2mVChAMax4 = adc2mV(bufferAMax4, chARange, maxADC)
258+
adc2mVChAMax5 = adc2mV(bufferAMax5, chARange, maxADC)
259+
adc2mVChAMax6 = adc2mV(bufferAMax6, chARange, maxADC)
260+
adc2mVChAMax7 = adc2mV(bufferAMax7, chARange, maxADC)
261+
adc2mVChAMax8 = adc2mV(bufferAMax8, chARange, maxADC)
262+
adc2mVChAMax9 = adc2mV(bufferAMax9, chARange, maxADC)
263+
264+
# Creates the time data
265+
time = np.linspace(0, (cmaxSamples.value - 1) * timeIntervalns.value, cmaxSamples.value)
266+
267+
# Plots the data from channel A onto a graph
268+
plt.plot(time, adc2mVChAMax[:])
269+
plt.plot(time, adc2mVChAMax1[:])
270+
plt.plot(time, adc2mVChAMax2[:])
271+
plt.plot(time, adc2mVChAMax3[:])
272+
plt.plot(time, adc2mVChAMax4[:])
273+
plt.plot(time, adc2mVChAMax5[:])
274+
plt.plot(time, adc2mVChAMax6[:])
275+
plt.plot(time, adc2mVChAMax7[:])
276+
plt.plot(time, adc2mVChAMax8[:])
277+
plt.plot(time, adc2mVChAMax9[:])
278+
plt.xlabel('Time (ns)')
279+
plt.ylabel('Voltage (mV)')
280+
plt.show()
281+
282+
# Stops the scope
283+
# Handle = chandle
284+
status["stop"] = ps.ps5000Stop(chandle)
285+
assert_pico_ok(status["stop"])
286+
287+
# Closes the unit
288+
# Handle = chandle
289+
status["close"] = ps.ps5000CloseUnit(chandle)
290+
assert_pico_ok(status["close"])
291+
292+
# Displays the staus returns
293+
#print(status)
294+
295+

0 commit comments

Comments
 (0)