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.

pumpobj(com, userData)
function serialObject = pumpobj(com, userData)
% PUMPOBJ Returns the serial object for Jasco pumps
% serialObject = pumpobj(com) returns the serial object for Jasco pumps given a
% suitable COM port number (unsigned integer: 1-255).  If an object already
% exists on that COM port (open or otherwise), returns an error.
% Information can be passed into the serial object through the optional
% userData argument.

% Normal usage:

% e.g. serialObject = pumpobj(9) - returns a serial object for the Jasco pump
% on COM9


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

% Error handling
if ~iscomport(com)
    % errors
    error('com must be an unsigned integer from 1 to 255')
end

% if object on specified COM port exists, errors, otherwise creates
% serial object

% initialises variables
serialPort = sprintf('COM%d', com);

% if serial object does not exist, defines serial object and opens it
if isempty(instrfindall('Port', serialPort))
    % creates the serial object (note that the first terminator is for
    % reading, and the second terminator is for writing)
    serialObject = serial(  serialPort,...
        'BaudRate', 4800,...
        'DataBits', 8,...
        'Parity', 'none',...
        'StopBits', 2,...
        'Flowcontrol', 'hardware',...
        'Terminator', {'CR/LF', 'CR'},...
        'TimeOut', 1);

    % if userData was provided, modify the object
    if nargin >= 2
        % changes it
        serialObject.UserData = userData;
    end
    
else
    % errors
    error('Object(s) already exist on this serial port')
end

Contact us