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.

serialterminator(serialObject)
function response = serialterminator(serialObject)
% SERIALTERMINATOR extracts and processes the terminator in the serial
% object so it can be used by the realterm software

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

% it must be a serial object
if ~isserial(serialObject)
    % errors
    error('Must supply a serial object.')
end

% decides what to do
terminator = serialObject.Terminator;

% if its a cell array...
if iscell(terminator) && numel(terminator) == 2
    % same deal as above
    for m = 1:2
        % decides what to do
        switch terminator{m}
            case 'CR'
                % simple
                response{m} = char(13);

            case 'LF'
                % simple again
                response{m} = char(10);

            case 'CR/LF'
                % straight forward
                response{m} = char([13, 10]);

            case 'LF/CR'
                % simple
                response{m} = char([10, 13]);

            otherwise
                % if its a number
                if isnumeric(terminator{m})
                    % modify it
                    response{m} = char(terminator{m}(:));
                    
                elseif ischar(terminator{m})
                    % leave it as it is
                    response{m} = terminator{m}(:);

                else
                    % errors
                    error('Unknown terminator.')
                end
        end
    end

elseif isstring(terminator) || isnumeric(terminator)
    % decides what to do
    switch terminator
        case 'CR'
            % simple
            response = char(13);

        case 'LF'
            % simple again
            response = char(10);

        case 'CR/LF'
            % straight forward
            response = char([13, 10]);

        case 'LF/CR'
            % simple
            response = char([10, 13]);

        otherwise
            % if its a number
            if isnumeric(terminator)
                % modify it
                response = char(terminator(:));
            end
    end

else
    % error
    error('Unknown terminator type')
end

Contact us