function instraction(obj, event)
%INSTRACTION Display event information for the event.
%
%    INSTRACTION(OBJ, EVENT) displays a message which contains the 
%    type of the event, the time of the event and the name of the
%    object which caused the event to occur.  
%
%    If an error event occurs, the error message is also displayed.  
%    If a pin event occurs, the pin that changed value and the pin 
%    value is also displayed. 
%
%    INSTRACTION is an example action function. Use this action function
%    as a template for writing your own action function.
%
%    Example:
%       s = serial('COM1');
%       set(s, 'OutputEmptyAction', 'instraction');
%       fopen(s);
%       fprintf(s, '*IDN?', 'async');
%       idn = fscanf(s);
%       fclose(s);
%       delete(s);
%

%    MP 2-24-00
%    Copyright 2000 The MathWorks, Inc. 
%    $Revision: 1.3 $  $Date: 2000/07/19 12:46:02 $


% Define error message.
error1 = 'Type ''help instrument\instraction'' for an example using INSTRACTION.';

switch nargin
case 0
   error(sprintf(['This function may not be called with 0 inputs.\n',...
         'Type ''help instrument\instraction'' for an example using INSTRACTION.']));
case 1
   error(error1);
case 2
   if ~isa(obj, 'instrument') | ~isa(event, 'struct')
      error(error1);
   end   
   if ~(isfield(event, 'Type') & isfield(event, 'Data'))
      error(error1);
   end
end  

% Determine the type of event.
EventType = event.Type;

% Determine the time of the error event.
EventData = event.Data;
EventDataTime = EventData.AbsTime;
   
% Convert the clock time to a datenum so that it can be converted to the
% display string.
EventDataTime = num2cell(EventDataTime);
EventDataTime = datenum(EventDataTime{:});

% Create a display indicating the type of event, the time of the event and
% the name of the object.
name = get(obj, 'Name');
fprintf([EventType ' event occurred at ' datestr(EventDataTime,13),...
	' for the object: ' name '.\n']);

% Display the error string.
if strcmp(lower(EventType), 'error')
	fprintf([EventData.Message '\n']);
end

% Display the pinstatus information.
if strcmp(lower(EventType), 'pinstatus')
    fprintf([EventData.Pin ' is ''' EventData.PinValue '''.\n']);
end