Code covered by the BSD License  

Highlights from
Realterm communications suite

Realterm communications suite

by

 

06 Jan 2010 (Updated )

Use Realterm in a similar way to using the MATLAB "serial" commands and instrument control toolbox.

realtermfopen(handle)
function [captureFileID, captureFile] = realtermfopen(handle)
% REALTERMFOPEN connects like fopen does with serial objects (more like
% when ordinary files are opened really).  The file ID and the capture file
% are returned, but these are not required to use the serial device (they
% are automatically retrieved from realterm).

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

% error handling
if ~isrealtermhandle(handle)
    
    % the real term handle must be a valid handle
    error('The realTermHandle is not valid.')
end

% connects
handle.PortOpen = 1;

% check that it opened OK
if ~handle.PortOpen
    
    % errors
    error('Did not connect.')
end

% if the caption is empty, generate a name, otherwise use the caption as
% the basis for the filename
if ~isempty(handle.Caption)
    
    % use the caption, removing any spaces
    filename = handle.Caption(~isspace(handle.Caption));
    
else
    
    % use a generic temporary filename
    filename = 'temp';
end

% generates a meaningful unique filename in the same directory as this
% function
captureFile = createuniquefile([fileparts(mfilename('fullpath')), filesep, filename, '.dat']);

% passes the filename to realterm
handle.CaptureFile = captureFile;

% start capture
handle.StartCapture

% try-catched for tidiness
try
    
    % open the file in MATLAB (read-only)
    captureFileID = fopen(captureFile);
    
catch
    
    % if it didn't work, stop the capture
    handle.StopCapture

    % empty the capture file field
    handle.CaptureFile = '';
    
    % close it
    fclose(captureFileID);

    % delete the file if it exists
    if exist(captureFile, 'file')
        
        % delete it
        delete(captureFile)
    end

    % rethrow the error
    rethrow(lasterror)
end

Contact us