User`s guide
Creating and Executing Callback Functions
vid = videoinput('mat rox', 1);
2 Configure property values — This example sets the Frame sPerTrigger
value to 30 and the T riggerRepeat property to 4. The example also
specifiesasthevalueofthe
FramesAcquiredFcn callback the event
callback function
display_frame, created in “Example: Writing a Callback
Function” on page 7-13. The object will execute the
FramesAcquiredFcn
every fi ve frames, as specif ied by th e value of the Fram esA cquiredFcnCount
property.
set(vid,'FramesPerTrigger', 30);
set(vid,'TriggerRepeat', 4);
set(vid,'FramesAcquiredFcnCount', 5);
set(vid,'FramesAcquiredFcn', {'display_frame'});
3 Acquir
edata— Start the video input object. E very time five frames are
acqui
red, the object executes the
display_frame callback function. This
callb
ack function displays the most recently acquired frame logged to the
memor
ybuffer.
start(vid)
4 Clean up — Always rem ove image acquisition objects from mem ory, and
the variables that re ference them, when you n o longer need them.
delete(vid)
clear vid
Example: Monitoring Memory Usage
This example creates a callback function for a tim er event that displays the
toolbox’s current mem ory usage and stops the acquisition when the available
memory for frame storage falls below a specified amount.
Creating the Memory M onitor Callback Function
This callback function implements a simple memory usage monitoring
function. The callback function uses the
imaqmem function to retrieve two
memory usage statistics,
FrameMemoryLimit and FrameMemo ryUs ed,andthen
calculates the amount of memory that is currently left for allocating fram es.
When the amount of memory available falls below a specified value, the
function outputs a message and stops the object.
7-17