User`s guide
Creating and Executing Callback Functions
8-13
The function header for this callback function illustrates this basic syntax.
function mycallback(obj,event)
The first argument, obj, is the image acquisition object itself. Because the object is
available, you can use in your callback function any of the toolbox functions, such
as getdata, that require the object as an argument. You can also access all object
properties.
The second argument, event, is the event structure associated with the event. This
event information pertains only to the event that caused the callback function to execute.
For a complete list of supported event types and their associated event structures, see
“Event Structures” on page 8-8.
In addition to these two required input arguments, you can also specify additional,
application-specific arguments for your callback function.
Note To receive the object and event arguments, and any additional arguments, you
must use a cell array when specifying the name of the function as the value of a callback
property. For more information, see “Specifying Callback Functions” on page 8-14.
Writing a Callback Function
To illustrate, this example implements a callback function for a frames-acquired event.
This callback function enables you to monitor the frames being acquired by viewing a
sample frame periodically.
To implement this function, the callback function acquires a single frame of data and
displays the acquired frame in a MATLAB figure window. The function also accesses
the event structure passed as an argument to display the timestamp of the frame being
displayed. The drawnow command in the callback function forces MATLAB to update the
display.
function display_frame(obj,event)
sample_frame = peekdata(obj,1);
imagesc(sample_frame);
drawnow; % force an update of the figure window
abstime = event.Data.AbsTime;