Code covered by the BSD License  

Highlights from
Knauer pump RS232 communication

Knauer pump RS232 communication



Functions for communicating with Knauer pumps via RS232.

function knauerpumpobjconnect(serialObject)
% KNAUERPUMPOBJCONNECT initialises communication with Knauer pumps
% knauerpumpobjconnect(serialObject) initialises communication with Knauer
% pumps, given serialObject as a valid pump serial object (generated by
% knauerpumpobj).

% e.g. knauerpumpobjconnect(serialObject) - initialises communication with
% the pump.

% Range:

% serialObject = valid serial port object

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

% error handling
if ~isa(serialObject, 'serial') || ~isvalid(serialObject) || ~strcmp(serialObject.Status, 'closed')
    % errors
    error('serialObject must be a valid closed serial object.')

% opens communication

% Vista needs a brief pause to behave itself correctly - I've left his is
% for XP too, but in case you wanted to shave off that whole 400 ms, you
% could try...BUT old MATLAB versions detect Vista as "Microsoft Windows
% 2000" - whether this is required or not for realterm has not been tested
%if isempty(strfind(system_dependent('getos'), 'XP'))

% fetches some information
    % gets the pump head size
    pumpHeadSize = knauerpumpobjreadpumpheadsize(serialObject);

	% stores it in the user data (maxFlow is currently not used in the
	% CO2gui, but is there for future use)
    serialObject.UserData = catstructs(serialObject.UserData, struct(   'pumpHeadSize', pumpHeadSize,...
                                                                        'maxFlow', pumpHeadSize));

    % displays a warning
    warning('knauerpump:connectionInfo', 'Did not retrieve some pump information.')

function output = catstructs(varargin)
% Concatenate structures.  This also overwrites duplicate fields, so that
% the later arguments take priority over earlier arguments.

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

% removes the empty arguments (they get ignored)
varargin = varargin(~cellfun('isempty', varargin));

% counts the new arguments
numArgs = numel(varargin);

% initialises allStruct
allStruct = 0;

% for each argument checks that they're a structure
for m = 1:numel(varargin)
    % is it a structure?
    allStruct = allStruct + isstruct(varargin{m});

% are they all structures?
if allStruct ~= numArgs
    % errors
    error('All arguments must be structures.')

% defines the output as the first argument
output = varargin{1};

% for each structure...
for n = 2:numArgs
    % get the fieldnames
    fields = fieldnames(varargin{n});

    % for each field
    for nn = 1:numel(fields)
        % add it on to the first stucture
        output.(fields{nn}) = varargin{n}.(fields{nn});

Contact us