User`s guide

7 Using Events and Callbacks
Example: Using the Default Callback Function
To illustrate how to use callbacks, this section presents a s imple example that
creates an image acquisition object and associates a callback function with
the s tart ev ent, trigg er event, and stop event. For information about all the
event callbacks s upported by the toolbox, see “Event Type s” on page 7-4.
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 7-12.
This example i ll ustrates how to use the default callba ck fu nction.
1 Create an im age acquisition object Th i s example creates a video
input o bj ect for a M atrox ima ge acquisition device. To run th is 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('mat rox',1);
2 Configure properties Set the values of three callback properties. The
example uses the default callback function
imaqcallback.
set(vid,'StartFcn',@imaqcallback)
set(vid,'TriggerFcn',@imaqcallback )
set(vid,'StopFcn',@imaqcallback)
For this example, specify the a mount of data to log.
set(vid, 'FramesPe rTri gger',100);
3 Start the image acquisition object Start the im age 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.
7-2