Code covered by the BSD License  

Highlights from
Thar ABPR-20 RS232 communication via handheld emulation

Thar ABPR-20 RS232 communication via handheld emulation

by

 

20 May 2013 (Updated )

Controls and reads from a Thar ABPR-20, by emulating the handheld controller.

isserial(serialObject)
function response = isserial(serialObject)
% ISSERIAL checks if an object is a valid serial object

% checks the number of arguments
error(nargchk(1, 1, nargin))

% if its a structure, error
if isstruct(serialObject)
    % errors
    error('Not defined for structures.')
end

% different tests for different types
if iscell(serialObject)
    % recursively call this function
    response = cellfun(@isserial, serialObject, 'UniformOutput', false);
    
else
    % if it is a serial object (by definition a 1x1 serial object)
    if isa(serialObject, 'serial');
        % checks the serial object for validity
        response = isvalid(serialObject);
    
    % a serial object that is larger than 1x1 becomes an instrument object
    elseif isa(serialObject, 'instrument');
        % pre-defines the answer
        response = false(size(serialObject));
        
        % apply isvalid on each column (doesn't work on arrays)
        for m = 1:size(serialObject, 2)
            % tests each column (could equally do this by rows)
            response(:, m) = isvalid(serialObject(:, m));
        end
        
    else
        % generates a false response the same size as the serialObject
        response = false(size(serialObject));
    end
end

Contact us