Skip to content

Commit f05188e

Browse files
author
neil.hamilton
committed
Continue work on ps6000aExamples/ps6000aStreamingModeExample.py
1 parent fb44ff4 commit f05188e

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

ps6000aExamples/ps6000aStreamingModeExample.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import matplotlib.pyplot as plt
1414
from picosdk.functions import adc2mV, assert_pico_ok
1515
from picosdk.constants import PICO_STATUS
16+
import time
1617

1718
# Create chandle and status ready for use
1819
chandle = ctypes.c_int16()
@@ -35,10 +36,10 @@
3536
assert_pico_ok(status["setChannelA"])
3637

3738
# set channel B-H off
38-
for x in range (1, 7, 1):
39+
for x in range(1, 7, 1):
3940
channel = x
40-
status["setChannel",x] = ps.ps6000aSetChannelOff(chandle,channel)
41-
assert_pico_ok(status["setChannel",x])
41+
status["setChannel", x] = ps.ps6000aSetChannelOff(chandle, channel)
42+
assert_pico_ok(status["setChannel", x])
4243

4344

4445
# Set number of samples to be collected
@@ -60,8 +61,8 @@
6061
# create buffers
6162
maxBuffers = 10
6263

63-
for i in range (0,9):
64-
bufferA(i) = (ctypes.c_int16 * nSamples)()
64+
65+
bufferA = ((ctypes.c_int16 * nSamples)*10)()
6566

6667
print(bufferA)
6768
# Set data buffers
@@ -75,22 +76,25 @@
7576
downSampleMode = enums.PICO_RATIO_MODE["PICO_RATIO_MODE_RAW"]
7677
clear = enums.PICO_ACTION["PICO_CLEAR_ALL"]
7778
add = enums.PICO_ACTION["PICO_ADD"]
78-
action = clear|add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"]
79-
status["setDataBuffers"] = ps.ps6000aSetDataBuffer(chandle, channelA, ctypes.byref(bufferA(0)), nSamples, dataType, waveform, downSampleMode, action)
79+
action = clear | add # PICO_ACTION["PICO_CLEAR_WAVEFORM_CLEAR_ALL"] | PICO_ACTION["PICO_ADD"]
80+
status["setDataBuffers"] = ps.ps6000aSetDataBuffer(chandle, channelA, ctypes.byref(bufferA[0]), nSamples, dataType,
81+
waveform, downSampleMode, action)
8082
assert_pico_ok(status["setDataBuffers"])
8183

8284
# Run streaming
83-
sampleInterval = 1
85+
sampleInterval = ctypes.c_double(1)
8486
sampleIntervalTimeUnits = enums.PICO_TIME_UNITS["PICO_US"]
8587
autoStop = 0
8688
downSampleRatio = 1
8789

88-
status["runStreaming"] = ps.ps6000aRunStreaming(chandle, ctypes.byref(sampleInterval), sampleIntervalTimeUnits, noOfPreTriggerSamples, noOfPostTriggerSamples, autoStop, downSampleRatio, downSampleMode)
90+
status["runStreaming"] = ps.ps6000aRunStreaming(chandle, ctypes.byref(sampleInterval), sampleIntervalTimeUnits,
91+
noOfPreTriggerSamples, noOfPostTriggerSamples, autoStop,
92+
downSampleRatio, downSampleMode)
8993
assert_pico_ok(status["runStreaming"])
9094

91-
streamData = structs.PICO_STREAMING_DATA_INFO[channelA, downSampleRatio, dataType, 0, 0, 0, 0]
95+
streamData = structs.PICO_STREAMING_DATA_INFO(channelA, downSampleRatio, dataType, 0, 0, 0, 0)
9296

93-
streamTrigger = structs.PICO_STREAMING_DATA_TRIGGER_INFO[0,0,0]
97+
streamTrigger = structs.PICO_STREAMING_DATA_TRIGGER_INFO(0, 0, 0)
9498

9599
count = 1
96100

@@ -100,14 +104,18 @@
100104

101105
while count <= maxBuffers:
102106

103-
status["getStreamingLatestValues"] = ps.ps6000aGetStreaminglatestValues(chandle, ctypes.byref(streamData), 1, ctypes.byref(streamTrigger)
107+
status["getStreamingLatestValues"] = ps.ps6000aGetStreamingLatestValues(chandle, ctypes.byref(streamData), 1,
108+
ctypes.byref(streamTrigger))
104109

105-
if status["getStreamingLatestValues"] == picoOk
106-
else
110+
if status["getStreamingLatestValues"] == picoOk:
111+
# do nothing
112+
time.sleep(0.01)
113+
else:
107114
count = count+1
108-
if count <= maxBuffers
109-
status["setDataBuffers"] = ps.ps6000aSetDataBuffer(chandle, channelA, ctypes.byref(bufferA(count-1)), nSamples, dataType, waveform, downSampleMode, actionB)
110-
assert_pico_ok(status["setDataBuffers"])
115+
if count <= maxBuffers:
116+
status["setDataBuffer"] = ps.ps6000aSetDataBuffer(chandle, channelA, ctypes.byref(bufferA[count-1]),
117+
nSamples, dataType, waveform, downSampleMode, actionB)
118+
assert_pico_ok(status["setDataBuffer"])
111119
print(count)
112120

113121
print("streaming finished")
@@ -120,10 +128,12 @@
120128
assert_pico_ok(status["getAdcLimits"])
121129

122130
# convert ADC counts data to mV
123-
bufferAmV = adc2mV(bufferA, channelRange, maxADC)
131+
bufferAmV=((ctypes.c_int16 * nSamples)*10)()
132+
for j in range(0, 9):
133+
bufferAmV[j] = adc2mV(bufferA[j], channelRange, maxADC)
124134

125135
# Close the scope
126136
status["closeunit"] = ps.ps6000aCloseUnit(chandle)
127137
assert_pico_ok(status["closeunit"])
128138

129-
print(status)
139+
print(status)

0 commit comments

Comments
 (0)