User`s guide
Using the Default Callback Function
8-3
Using the Default Callback Function
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” on page 8-5.
The example uses the default callback function provided with the toolbox,
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” on
page 8-12.
This example illustrates how to use the default callback function.
1
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
imaqhwinfo function to get the object constructor for your image acquisition device
and substitute that syntax for the following code.
vid = videoinput('matrox',1);
2
Configure properties — Set the values of three callback properties. The example
uses the default callback function imaqcallback.
vid.StartFcn = @imaqcallback
vid.TriggerFcn = @imaqcallback
vid.StopFcn = @imaqcallback
For this example, specify the amount of data to log.
vid.FramesPerTrigger = 100;
3
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.
4
Clean up — Always remove image acquisition objects from memory, and the
variables that reference them, when you no longer need them.