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.

isvalidcomport(input)
function response = isvalidcomport(input)
% ISCOMPORT checks if a number is a valid COM port number

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

% input must be a string or a cell array of strings
if ~isstring(input) && ~iscellstr(input)
    % error
    error('Only defined for strings and cell arrays of strings.')
end

% if the instrument tool box is there...
if ~isempty(ver('instrument'))
    % gets the serial info
    info = instrhwinfo('serial');

    % gets the available ports
    comPorts = info.AvailableSerialPorts;
    
    % if its cell array of strings...
    if iscellstr(input)
        % recursively call this function
        response = cellfun(@isvalidcomport, input);
    else
        
        % tries to match it
        response = any(strcmp(comPorts, input));
    end
    
else
    % errors
    error('Instrument toolbox is not present so cannot (quickly) determine the available COM ports')
end

Contact us