function disp(obj)
%DISP Display method for serial port objects.
%
%    DISP(OBJ) dynamically displays information pertaining to 
%    serial port object, OBJ. OBJ can be an array of serial port
%    objects.
%

%    MP 7-13-99
%    Copyright 1999-2000 The MathWorks, Inc. 
%    $Revision: 1.4 $  $Date: 2000/08/29 23:47:30 $

% The object display is based on the number of objects
% in the array.
try
	jobject = igetfield(obj, 'jobject');
catch
	builtin('display', obj);
	return;
end

switch (length(jobject))
case 1
   % Single object display.
   fprintf(char(display(jobject)));
otherwise
   % Multiple object display.
   localArrayDisplay(obj);
end

% **********************************************************************
% Create the display for an array of objects.
function localArrayDisplay(obj)

% Write out the header.
fprintf('\n');
fprintf([blanks(3) 'Instrument Object Array\n\n']);
fprintf([blanks(3) 'Index:   Type:          Status:     Name:  \n']);

% Create the index.
dispLength = length(obj);
index = num2cell([1:dispLength]);

% Initialize variables.
typeValues   = cell(dispLength,1);
statusValues = cell(dispLength,1);
nameValues   = cell(dispLength,1);

% Get all the values for the display.
jobj = igetfield(obj, 'jobject');
for i = 1:dispLength
    if isvalid(jobj(i))
		typeValues{i}   = get(jobj(i), 'Type');
		statusValues{i} = get(jobj(i), 'Status');
		nameValues{i}   = get(jobj(i), 'Name');
    else
        typeValues{i}   = localFixClass(class(jobj(i)));
        statusValues{i} = 'Invalid';
        nameValues{i}   = 'Invalid';
    end
end

% Write out the property values.
for i = 1:dispLength
   fprintf([blanks(3) num2str(index{i})...
         blanks(9 - length(num2str(index{i}))) typeValues{i}...
         blanks(15 - length(typeValues{i})) statusValues{i}...   
         blanks(12 - length(statusValues{i})) num2str(nameValues{i})...
         '\n']);
end	

fprintf('\n');

% *******************************************************************
% Fix the display.
function out = localFixClass(str)

if (findstr('javahandle.com.mathworks.toolbox.instrument.', str))
    out = strrep(str, 'javahandle.com.mathworks.toolbox.instrument.', '');
end

if strmatch('SerialComm', out)
   out = 'serial';
elseif strmatch('SerialVisa', out)
   out = 'visa-serial';
elseif strmatch('GpibDll', out)
   out = 'gpib';
elseif strmatch('VxiVisa', out)
   out = 'visa-vxi';
elseif strmatch('VxiGpibVisa', out)
    out = 'visa-gpib-vxi';
elseif strmatch('GpibVisa', out)
   out = 'visa-gpib';
elseif strmatch('Gpib', out)
   out = 'gpib';
end

