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.

serialclose(serialObject)
function serialclose(serialObject)
% SERIALCLOSE ends communication with a serial object.

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

% checks that a serial object has been passed
if ~isserial(serialObject)
    % errors
    error('Must supply a serial object.')
end

% finds if it should be realterm or not
if isfield(serialObject.UserData, 'realTermHandle')
    % checks the port is still open
    if ~isrunning(serialObject.UserData.realTermHandle)
        % errors
        error('Realterm is already disconnected.')
    end
    
    % checks the file ID is there
    if ~isfield(serialObject.UserData, 'captureFileID')
        % displays a warning that the file wasn't closed
        warning('serialClose:fileNotClosed', 'Realterm capture file was not correctly closed.')
    end
    
    % disconnects
    realtermfclose(serialObject.UserData.realTermHandlehandle, serialObject.UserData.captureFileID)
    
else
    % checks its connected
    if ~isrunning(serialObject)
        % errors
        error('Serial port is already closed.')
    end
    
    % disconnects normally
    fclose(serialObject)
end

Contact us