Data Acquisition Toolbox | ![]() ![]() |
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.
AO
for a sound card. The installed adaptors and hardware IDs are found with daqhwinfo
.
AO
.
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])
AO
. The waittilstop
function blocks the MATLAB command line, and waits for AO
to stop running.
AO
, you should remove it from memory and from the MATLAB workspace.
Displaying EventLog Information
This example illustrates how callback functions allow you to easily display information stored in the EventLog
property. You can run this example by typing daqdoc6_5
at the MATLAB command line. The local callback function daqdoc6_5disp
(not shown below) displays the absolute time and relative sample associated with the start, trigger, and stop events.
AO
for a sound card. The installed adaptors and hardware IDs are found with daqhwinfo
.
AO
.
daqdoc6_5disp
as the M-file callback function to execute when the start, trigger, and stop events occur, generate data to be queued, and queue the data with one call to putdata
.
set(AO,'SampleRate',8000) ActualRate = get(AO,'SampleRate'); set(AO,'StartFcn',@daqdoc6_5disp) set(AO,'TriggerFcn',@daqdoc6_5disp) set(AO,'StopFcn',@daqdoc6_5disp) data = sin(linspace(0,2*pi*500,ActualRate)); data = [data data data]; time = (length(data)/AO.SampleRate); putdata(AO,data')
AO
. The waittilstop
function blocks the MATLAB command line, and waits for AO
to stop running.
AO
, you should remove it from memory and from the MATLAB workspace.
![]() | Recording and Retrieving Event Information | Linearly Scaling the Data: Engineering Units | ![]() |