%% Viewing Events
% This example explains what events are and shows how to view the event log. Events occur during 
% an acquisition at a particular time when a condition is met. These events include:
%
% * Error
% * FramesAcquired
% * Start
% * Stop
% * Timer
% * Trigger
%
% All acquisitions consist of at least 3 events:
%
% * Starting the device
% * Triggering the device
% * Stopping the device.
%
% Copyright 2001-2012 The MathWorks, Inc.

%% Executing an Acquisition
% Initiate a basic acquisition using a video input object.

% Access an image acquisition device.
vidobj = videoinput('winvideo', 1);

% Use a manual trigger to initiate data logging.
triggerconfig(vidobj, 'manual');

% Start the acquisition.
start(vidobj)

% Trigger the object to start logging and allow the acquisition to run for
% couple of seconds.
trigger(vidobj)
pause(2);

% Stop the acquisition
stop(vidobj)

%% Viewing Event Information
% To view event information for the acquisition, access the |EventLog| 
% property of the video input object. Events are recorded in chronological order.

% View the event log.
events = vidobj.EventLog

%%
% Each event provides information on the state of the object at the
% time the event occurred.

% Display first event.
event1 = events(1)

%%

data1 = events(1).Data

%%

% Display second event.
event2 = events(2)

%%

data2 = events(2).Data

%%

% Display third event.
event3 = events(3)

%%

data3 = events(3).Data

%%

% Once the video input object is no longer needed, delete
% it and clear it from the workspace.
delete(vidobj)
clear vidobj
