To illustrate how to use callbacks, this section presents a simple example that creates an image acquisition object and associates a callback function with the start event, trigger event, and stop event. For information about all the event callbacks supported by the toolbox, see Event Types.
The example uses the default callback function provided with
imaqcallback. The default callback
function displays the name of the object along with information about
the type of event that occurred and when it occurred. To learn how
to create your own callback functions, see Creating and Executing Callback Functions.
This example illustrates how to use the default callback function.
Create an image
acquisition object — This example creates a video
input object for a Matrox® image
acquisition device. To run this example on your system, use the
to get the object constructor for your image acquisition device and
substitute that syntax for the following code.
vid = videoinput('matrox',1);
Configure properties —
Set the values of three callback properties. The example uses the
default callback function
vid.StartFcn = @imaqcallback vid.TriggerFcn = @imaqcallback vid.StopFcn = @imaqcallback
For this example, specify the amount of data to log.
vid.FramesPerTrigger = 100;
Start the image acquisition object — Start the image acquisition object. The object executes an immediate trigger, acquires 100 frames of data, and then stops. With the three callback functions enabled, the object outputs information about each event as it occurs.
start(vid) Start event occurred at 14:38:46 for video input object: M_RS170-matrox-1. Trigger event occurred at 14:38:46 for video input object: M_RS170-matrox-1. Stop event occurred at 14:38:49 for video input object: M_RS170-matrox-1.
Clean up — Always remove image acquisition objects from memory, and the variables that reference them, when you no longer need them.
delete(vid) clear vid