Skip to content

Commit f4a131b

Browse files
author
neil.hamilton
committed
Complete PS6000A_ID_Streaming_Example.m first version
1 parent 7422cff commit f4a131b

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

examples/PS6000A_ID_Streaming_Example.m

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@
133133

134134
%% Create Buffers
135135

136-
bufferA = zeros(totalSamples, 1, 'int16');
137-
138136
maxBuffers = 10;
139137

138+
bufferA = zeros(totalSamples, 1,'int16');
139+
140140
for i =(1:maxBuffers)
141141
pBufferA(i,1) =libpointer('int16Ptr', bufferA);
142142
end
@@ -150,14 +150,14 @@
150150

151151

152152
[status.setBufferA] = invoke(ps6000aDeviceObj, 'ps6000aSetDataBuffer', channelA, pBufferA(1,1), ...
153-
totalSamples, dataType, waveform, downSampleRatioMode, actionA);
153+
totalSamples, dataType, waveform, downSampleRatioMode, actionB);
154154

155155

156156
%% Run Block Capture
157157

158158
sampleInterval = 1;
159159
sampleIntervalTimeUnits = ps6000aEnumInfo.enPicoTimeUnits.PICO_US;
160-
autoStop = 1;
160+
autoStop = 0;
161161
downSampleRatio = 1;
162162

163163
disp('Streaming starting...')
@@ -169,12 +169,12 @@
169169
streamData = ps6000aStructs.tPicoStreamingDataInfo.members;
170170

171171
streamData.bufferIndex_ = 0;
172-
streamData.channel_ = ps6000aEnumInfo.enPicoChannel.PICO_CHANNEL_A;
173-
streamData.mode_ = ps6000aEnumInfo.enPicoRatioMode.PICO_RATIO_MODE_AVERAGE;
172+
streamData.channel_ = channelA;
173+
streamData.mode_ = downSampleRatio;
174174
streamData.noOfSamples_ = 0;
175175
streamData.overflow_ = 0;
176176
streamData.startIndex_ = 0;
177-
streamData.type_ = ps6000aEnumInfo.enPicoDataType.PICO_INT16_T;
177+
streamData.type_ = dataType;
178178

179179
pStreamData = libpointer('tPicoStreamingDataInfoPtr',streamData);
180180

@@ -186,17 +186,23 @@
186186
pStreamTrigger = libpointer('tPicoStreamingDataTriggerInfoPtr',streamTrigger);
187187
%%
188188
i=1
189-
while i < maxBuffers
189+
190+
needBufferStatus = hex2dec('197');
191+
192+
while i <= maxBuffers
190193

191-
pause(0.25)
194+
pause(1)
192195

193196
[status.getStreamingLatestValues] = invoke(ps6000aDeviceObj, 'ps6000aGetStreamingLatestValues', pStreamData, 1, pStreamTrigger);
194197

195-
if status.getStreamingLatestValues ~= 0
198+
if status.getStreamingLatestValues ~= PicoStatus.PICO_OK
196199
bufferA(:,i) = pBufferA(i,1).Value;
197-
i=i+1
200+
i=i+1;
201+
if i <= maxBuffers
198202
[status.setBufferA] = invoke(ps6000aDeviceObj, 'ps6000aSetDataBuffer', channelA, pBufferA(i,1), ...
199203
totalSamples, dataType, waveform, downSampleRatioMode, actionB);
204+
i
205+
end
200206
end
201207

202208
end
@@ -215,25 +221,42 @@
215221

216222
voltageRange = 5000; %mV
217223

218-
bufferA = pBufferA.Value;
219-
220224
bufferA = adc2mv(bufferA,voltageRange,double(maxValue));
221225

222226
disp('Data converted to mV')
223227

224228
%% Plot Collected Data
225229

226230
samplesCollected=length(bufferA(:,1));
227-
maxTime = (double(samplesCollected) * sampleInterval);
228-
timeUS = linspace(0,maxTime,samplesCollected);
231+
maxBufferTime = (double(samplesCollected) * sampleInterval);
232+
bufferTimeUS = linspace(0,maxBufferTime,samplesCollected);
229233

230234
figure(1)
231-
plot(timeUS,bufferA(:,1));
235+
232236
hold on
237+
for i = 1:maxBuffers
238+
plot(bufferTimeUS, bufferA(:,i));
239+
end
240+
233241
ylabel('Voltage (mV)');
234242
xlabel('Time (us)');
235243
hold off
236244

245+
totalBuffers = [];
246+
for i = 1:maxBuffers
247+
totalBuffers = vertcat(totalBuffers,bufferA(:,i));
248+
end
249+
250+
totalSamplesCollected = length(totalBuffers(:,1));
251+
maxTime = (double(totalSamplesCollected) * sampleInterval);
252+
totalTimeUS = linspace(0,maxTime,totalSamplesCollected);
253+
254+
figure(2)
255+
256+
plot(totalTimeUS,totalBuffers);
257+
ylabel('Voltage (mV)');
258+
xlabel('Time (us)');
259+
237260
%% Disconnect scope
238261

239262
disconnect(ps6000aDeviceObj);

0 commit comments

Comments
 (0)