Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation

by

 

06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

realtermfclose(handle, captureFileID)
function realtermfclose(handle, captureFileID)
% REALTERMFCLOSE closes communication with the Realterm serial object

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

% error handling
if ~isrealtermhandle(handle)
    % the real term handle must be a valid handle
    error('The realTermHandle is not valid.')
    
elseif ~isfid(captureFileID)
    % the file ID must be vaild
    error('Invalid capture file ID.')
end

% tries to stop the capture
try
    % gets the capture file (from realterm = could do this from the fid
    % too)
    captureFile = handle.CaptureFile;
     
    % tries to stop the capture
    handle.StopCapture

    % closes the port
    handle.PortOpen = 0;

    % closes the server
    try
        % closes the server (can do this using dot notation, but this is only
        % defined for single variables e.g. handle.Close - it doesn't work with
        % nested serial objects mixed with structures
        handle.Close

        % deletes the server
        delete(handle)

    catch
        % errors
        error('Could not correctly close the ActiveX Real Term server.')
    end
    
    % closes the capture file in MATLAB
    fclose(captureFileID);
    
    % if the file exists, tidy up
    if exist(captureFile, 'file')
        % deletes the capture file
        delete(captureFile)
    end

catch
    % displays a warning
    warning('tharBPRObjDisconnect:ActiveXCloseFailure', 'Could correctly stop the data capture.')
end

Contact us