Skip to content

Commit 755820b

Browse files
author
neil.hamilton
committed
update examples to stream the full number of desired samples and stop the streaming capture
1 parent 9bf5404 commit 755820b

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

ps6000aExamples/ps6000aStreamingModeExample.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@
103103

104104
streamTrigger = structs.PICO_STREAMING_DATA_TRIGGER_INFO(0, 0, 0)
105105

106-
count = 1
107-
108-
106+
count = 0
109107

110108
picoOk = PICO_STATUS["PICO_OK"]
111109

112-
while count <= maxBuffers:
110+
collectedSamples = 0
111+
112+
while collectedSamples < (maxBuffers*nSamples):
113113

114114
status["getStreamingLatestValues"] = ps.ps6000aGetStreamingLatestValues(chandle, ctypes.byref(streamData), 1,
115115
ctypes.byref(streamTrigger))
@@ -119,18 +119,28 @@
119119
time.sleep(0.01)
120120
else:
121121
count = count + 1
122-
if count <= maxBuffers:
123-
status["setDataBufferA"] = ps.ps6000aSetDataBuffer(chandle, channelA, ctypes.byref(bufferA[count - 1]),
122+
if count < maxBuffers:
123+
status["setDataBufferA"] = ps.ps6000aSetDataBuffer(chandle, channelA, ctypes.byref(bufferA[count]),
124124
nSamples, dataType, waveform, downSampleMode, actionAdd)
125125
assert_pico_ok(status["setDataBufferA"])
126-
status["setDataBufferB"] = ps.ps6000aSetDataBuffer(chandle, channelB, ctypes.byref(bufferB[count - 1]),
126+
status["setDataBufferB"] = ps.ps6000aSetDataBuffer(chandle, channelB, ctypes.byref(bufferB[count]),
127127
nSamples, dataType, waveform, downSampleMode, actionAdd)
128128
assert_pico_ok(status["setDataBufferB"])
129129
print(count)
130-
ps.ps6000aStop(chandle)
130+
131+
collectedSamples = collectedSamples + streamData[0].noOfSamples
132+
133+
# stop scope streaming
134+
status["stop"] = ps.ps6000aStop(chandle)
135+
assert_pico_ok(status["stop"])
136+
137+
# get total number of streamed data points
131138
noOfStreamedSamples=ctypes.c_uint64()
132-
ps.ps6000aNoOfStreamingValues(chandle,ctypes.byref(noOfStreamedSamples))
139+
status["noOfStreamedSamples"] = ps.ps6000aNoOfStreamingValues(chandle, ctypes.byref(noOfStreamedSamples))
140+
assert_pico_ok(status["noOfStreamedSamples"])
141+
133142
print("streaming finished")
143+
print("Number of samples collected during streaming")
134144
print(noOfStreamedSamples.value)
135145

136146

@@ -141,17 +151,11 @@
141151
status["getAdcLimits"] = ps.ps6000aGetAdcLimits(chandle, resolution, ctypes.byref(minADC), ctypes.byref(maxADC))
142152
assert_pico_ok(status["getAdcLimits"])
143153

144-
# convert ADC counts data to mV
145-
plt.plot(bufferA[5])
146-
plt.plot(bufferB[9])
154+
# plot ADC data
155+
plt.plot(bufferA[0])
156+
plt.plot(bufferB[0])
147157
plt.show()
148-
# bufferAmV = ((ctypes.c_int16 * nSamples) * 10)()
149-
# bufferBmV = ((ctypes.c_int16 * nSamples) * 10)()
150-
# for j in range(0, 9):
151-
# A = bufferA[j]
152-
# bufferAmV[j] = adc2mV(A, channelRange, maxADC)
153-
# B = bufferB[j]
154-
# bufferBmV[j] = adc2mV(B, channelRange, maxADC)
158+
155159

156160
# Close the scope
157161
status["closeunit"] = ps.ps6000aCloseUnit(chandle)

0 commit comments

Comments
 (0)