User`s guide
2 Targets and Scopes in the MATLAB
®
Interface
% Save the data.
t( end + 1 : end + 500) = sc(scNum).Time;
data(end + 1 : end + 500, :) = sc( scNu m).Data;
% Restart this scope.
start(sc(scNum));
% Switch to the next scope.
%Shortcut for if(scNum==1) scNum=2;else scNum=1,end
scNum = 3 - scNum;
end
11 Wh en done, remov e the scopes.
% Remove the scopes we added.
remscope(tg,[1 2]);
The following is a complete code listing for the preceding double-buffering data
acquisition procedure. You can copy and paste this code i nto a MATLAB file
and run it after you download the model (
xpcosc.mdl) to the target PC. This
example assumes that the communication speed between the host and target
PC is fast enough to handle the number of samples and can acquire the full
data set before the next acquisition cycles starts. In a similar way, you can use
more than two scopes to implement a tri ple- or quadruple-buffering scheme.
% Ass umes model xpcosc.mdl has been built and loaded on the target PC.
% Atta ch to the target PC and set StopTime to 1 sec.
tg = xpctarget.xpc;
tg.StopTime = 1;
% Add two host scopes.
sc = tg.addscope('host', [1 2]);
% [0 1] are the signals of interest. Add to both scopes.
addsignal(sc,[0 1]);
% Each scope triggers next scope at end of a 500 sample acquisition.
set(sc, 'NumSamples', 500, 'TriggerSample', -1);
set(sc, 'TriggerMode', 'Scope');
sc(1).TriggerScope = 2;
sc(2).TriggerScope = 1;
% Init ialize time and data log.
t = [];
data = zeros(0, 2);
% Star t the scopes and the model.
start(sc);
2-22