Skip to content

Commit 7e473dc

Browse files
author
neil.hamilton
committed
Create ps6000BlockAdvancedTriggerExample.py
1 parent 78e9032 commit 7e473dc

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#
2+
# Copyright (C) 2018 Pico Technology Ltd. See LICENSE file for terms.
3+
#
4+
# PS6000 BLOCK MODE EXAMPLE
5+
# This example opens a 6000 driver device, sets up two channels and a trigger then collects a block of data.
6+
# This data is then plotted as mV against time in ns.
7+
8+
import ctypes
9+
import numpy as np
10+
from picosdk.ps6000 import ps6000 as ps
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+
chandle = ctypes.c_int16()
16+
status = {}
17+
18+
# Open 6000 series PicoScope
19+
# Returns handle to chandle for use in future API functions
20+
status["openunit"] = ps.ps6000OpenUnit(ctypes.byref(chandle), None)
21+
assert_pico_ok(status["openunit"])
22+
23+
# Set up channel A
24+
# handle = chandle
25+
# channel = PS6000_CHANNEL_A = 0
26+
# enabled = 1
27+
# coupling type = PS6000_DC = 1
28+
# range = PS6000_2V = 7
29+
# analogue offset = 0 V
30+
# bandwidth limiter = PS6000_BW_FULL = 0
31+
chARange = 7
32+
status["setChA"] = ps.ps6000SetChannel(chandle, 0, 1, 1, chARange, 0, 0)
33+
assert_pico_ok(status["setChA"])
34+
35+
# Set up channel B
36+
# handle = chandle
37+
# channel = PS6000_CHANNEL_B = 1
38+
# enabled = 1
39+
# coupling type = PS6000_DC = 1
40+
# range = PS6000_2V = 7
41+
# analogue offset = 0 V
42+
# bandwidth limiter = PS6000_BW_FULL = 0
43+
chBRange = 7
44+
status["setChB"] = ps.ps6000SetChannel(chandle, 1, 1, 1, chBRange, 0, 0)
45+
assert_pico_ok(status["setChB"])
46+
47+
# Set up level drop out tirgger on A
48+
49+
50+
# Set number of pre and post trigger samples to be collected
51+
preTriggerSamples = 2500
52+
postTriggerSamples = 2500
53+
maxSamples = preTriggerSamples + postTriggerSamples
54+
55+
# Get timebase information
56+
# handle = chandle
57+
# timebase = 8 = timebase
58+
# noSamples = maxSamples
59+
# pointer to timeIntervalNanoseconds = ctypes.byref(timeIntervalns)
60+
# oversample = 1
61+
# pointer to maxSamples = ctypes.byref(returnedMaxSamples)
62+
# segment index = 0
63+
timebase = 8
64+
timeIntervalns = ctypes.c_float()
65+
returnedMaxSamples = ctypes.c_int32()
66+
status["getTimebase2"] = ps.ps6000GetTimebase2(chandle, timebase, maxSamples, ctypes.byref(timeIntervalns), 1, ctypes.byref(returnedMaxSamples), 0)
67+
assert_pico_ok(status["getTimebase2"])
68+
69+
# Run block capture
70+
# handle = chandle
71+
# number of pre-trigger samples = preTriggerSamples
72+
# number of post-trigger samples = PostTriggerSamples
73+
# timebase = 8 = 80 ns (see Programmer's guide for mre information on timebases)
74+
# oversample = 0
75+
# time indisposed ms = None (not needed in the example)
76+
# segment index = 0
77+
# lpReady = None (using ps6000IsReady rather than ps6000BlockReady)
78+
# pParameter = None
79+
status["runBlock"] = ps.ps6000RunBlock(chandle, preTriggerSamples, postTriggerSamples, timebase, 0, None, 0, None, None)
80+
assert_pico_ok(status["runBlock"])
81+
82+
# Check for data collection to finish using ps6000IsReady
83+
ready = ctypes.c_int16(0)
84+
check = ctypes.c_int16(0)
85+
while ready.value == check.value:
86+
status["isReady"] = ps.ps6000IsReady(chandle, ctypes.byref(ready))
87+
88+
# Create buffers ready for assigning pointers for data collection
89+
bufferAMax = (ctypes.c_int16 * maxSamples)()
90+
bufferAMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example
91+
bufferBMax = (ctypes.c_int16 * maxSamples)()
92+
bufferBMin = (ctypes.c_int16 * maxSamples)() # used for downsampling which isn't in the scope of this example
93+
94+
# Set data buffer location for data collection from channel A
95+
# handle = chandle
96+
# source = PS6000_CHANNEL_A = 0
97+
# pointer to buffer max = ctypes.byref(bufferAMax)
98+
# pointer to buffer min = ctypes.byref(bufferAMin)
99+
# buffer length = maxSamples
100+
# ratio mode = PS6000_RATIO_MODE_NONE = 0
101+
status["setDataBuffersA"] = ps.ps6000SetDataBuffers(chandle, 0, ctypes.byref(bufferAMax), ctypes.byref(bufferAMin), maxSamples, 0)
102+
assert_pico_ok(status["setDataBuffersA"])
103+
104+
# Set data buffer location for data collection from channel B
105+
# handle = chandle
106+
# source = PS6000_CHANNEL_B = 1
107+
# pointer to buffer max = ctypes.byref(bufferBMax)
108+
# pointer to buffer min = ctypes.byref(bufferBMin)
109+
# buffer length = maxSamples
110+
# ratio mode = PS6000_RATIO_MODE_NONE = 0
111+
status["setDataBuffersB"] = ps.ps6000SetDataBuffers(chandle, 1, ctypes.byref(bufferBMax), ctypes.byref(bufferBMin), maxSamples, 0)
112+
assert_pico_ok(status["setDataBuffersB"])
113+
114+
# create overflow loaction
115+
overflow = ctypes.c_int16()
116+
# create converted type maxSamples
117+
cmaxSamples = ctypes.c_int32(maxSamples)
118+
119+
# Retried data from scope to buffers assigned above
120+
# handle = chandle
121+
# start index = 0
122+
# pointer to number of samples = ctypes.byref(cmaxSamples)
123+
# downsample ratio = 1
124+
# downsample ratio mode = PS6000_RATIO_MODE_NONE
125+
# pointer to overflow = ctypes.byref(overflow))
126+
status["getValues"] = ps.ps6000GetValues(chandle, 0, ctypes.byref(cmaxSamples), 1, 0, 0, ctypes.byref(overflow))
127+
assert_pico_ok(status["getValues"])
128+
129+
# find maximum ADC count value
130+
maxADC = ctypes.c_int16(32512)
131+
132+
# convert ADC counts data to mV
133+
adc2mVChAMax = adc2mV(bufferAMax, chARange, maxADC)
134+
adc2mVChBMax = adc2mV(bufferBMax, chBRange, maxADC)
135+
136+
# Create time data
137+
time = np.linspace(0, (cmaxSamples.value) * timeIntervalns.value, cmaxSamples.value)
138+
139+
# plot data from channel A and B
140+
plt.plot(time, adc2mVChAMax[:])
141+
plt.plot(time, adc2mVChBMax[:])
142+
plt.xlabel('Time (ns)')
143+
plt.ylabel('Voltage (mV)')
144+
plt.show()
145+
146+
status["stop"] = ps.ps6000Stop(chandle)
147+
assert_pico_ok(status["stop"])
148+
149+
# Close unitDisconnect the scope
150+
# handle = chandle
151+
ps.ps6000CloseUnit(chandle)
152+
153+
# display status returns
154+
print(status)

0 commit comments

Comments
 (0)