Code covered by the BSD License  

Highlights from
MATLAB Support Package for Parallax BASIC Stamp

image thumbnail

MATLAB Support Package for Parallax BASIC Stamp

by

 

25 Jul 2011 (Updated )

MATLAB library for communicating with a BASIC Stamp 2 and Board of Education (BoE) kit

stamp.findComPorts
% findComPorts
% Returns a column cell array of serial ports that BasicStamp can connect
% to. This does not necessarily mean that a BS2 is connected to any of
% these serial ports; however, it does narrow the possibilities down to two
% or three ports.

%   MATLAB Support Package for BASIC Stamp
%   Version 1.0
%   Copyright 2011 The MathWorks, Inc.

function ports = findComPorts

serialObj = serial('NOT A VALID PORT NUMBER');
ports = {};
try 
    fopen(serialObj);
catch ME    
    portString = regexpi(ME.message,'Available ports:([\w, ]*)\.', 'tokens', 'once');    
    if ~isempty(portString)
        ports = regexp(strtrim(portString{1}), '[ ,]+', 'split')';
    end
end

delete(serialObj);
ports(cellfun('isempty',ports)) = [];

Contact us