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.

serialscan(serialObject, varargin)
function output = serialscan(serialObject, varargin)
% SERIALSCAN reads from a serial object depending on if it contains the
% Realterm handle or not.

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

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

% note that 'mode' is currently ignored, but is in for future
% compatibility purposes - this method is effectively 'async' anyway

% finds if it should be realterm or not
if isfield(serialObject.UserData, 'realTermHandle')
    % checks the rest of the fields are there
    if ~isfield(serialObject.UserData, 'captureFileID')
        % errors
        error('Cannot retrieve the capture file ID.')
    end
    
    % gets the terminator
    terminator = serialterminator(serialObject);
    
    % if its a 2-element cell array, only use the first one (this is for
    % the read)
    if iscell(terminator)
        % use the first one
        terminator = terminator{1};
    end
    
    % read it in using real term (assumes the timeout on the serial object
    % has been set up correctly)
    output = realtermfscanf(serialObject.UserData.realTermHandle,...
                            serialObject.UserData.captureFileID,...
                            terminator,...
                            serialObject.TimeOut,...
                            varargin{:});
    
else
    % checks its connected
    if ~isrunning(serialObject)
        % errors
        error('Serial port is not open.')
    end
    
    % read it in conventionally
    output = fscanf(serialObject, varargin{:});
end

Contact us