Download "user manual"

Transcript
Events and Callbacks
Examples: Using Callback Properties and Callback
Functions
Examples showing how to create callback functions and configure callback
properties are given below.
Displaying the Number of Samples Output
This example illustrates how to generate samples output events. You can run
this example by typing daqdoc6_4 at the MATLAB command line. The local
callback function daqdoc6_4disp (not shown below) displays the number of
events that were output from the engine whenever the samples output event
occurred.
1 Create a device object — Create the analog output object AO for a sound
card. The installed adaptors and hardware IDs are found with daqhwinfo.
AO = analogoutput('winsound');
%AO = analogoutput('nidaq',1);
%AO = analogoutput('mcc',1);
2 Add channels — Add two channels to AO.
chans = addchannel(AO,1:2);
%chans = addchannel(AO,0:1); % For NI and MCC
3 Configure property values — Configure the trigger to repeat four times,
specify daqdoc6_4disp as the M-file callback function to execute whenever
8000 samples are output, generate data to be queued, and queue the data
with one call to putdata.
set(AO,'SampleRate',8000)
ActualRate = get(AO,'SampleRate');
set(AO,'RepeatOutput',4)
set(AO,'SamplesOutputFcnCount',8000)
freq = get(AO,'SamplesOutputFcnCount');
set(AO,'SamplesOutputFcn',@daqdoc6_4disp)
data = sin(linspace(0,2*pi*500,3*freq))';
putdata(AO,[data data])
6-31