Code covered by the BSD License  

Highlights from
Knauer pump RS232 communication

Knauer pump RS232 communication

by

 

Functions for communicating with Knauer pumps via RS232.

knauerpumpobjwriteflow(serialObject, setFlow)
function knauerpumpobjwriteflow(serialObject, setFlow)
% KNAUERPUMPOBJWRITEFLOW sets flow rate of Knauer pumps
% knauerpumpobjwriteflow(serialObject, setFlow) changes the set flow rate
% of Knauer pumps given a valid serial object and a flow rate from 0.000 to
% 50.000. The pump ignores any more than 3 decimal places.

% e.g. knauerpumpobjwriteflow(serialObject, 0.2) - sets flow rate of the
% pump to 0.2 mL min-1

% Range:

% serialObject = valid serial port object

% setFlow = unsigned number: 0-50


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

% need to know the pump head size to figure out which command to use -
% deliberately using the "fast" method since this doesn't change very often
pumpHeadSize = knauerpumpobjreadpumpheadsizefast(serialObject);

% depend on what it is, different pressures are possible
switch pumpHeadSize
    
    case 10
        
        % its 10 mL min-1
        maxPossibleFlow = 10;
        
    case 50
        
        % its 50 mL min-1
        maxPossibleFlow = 50;
        
    otherwise
        
        % issue a warning
        warning('Unknown pump head size for Knauer pump - unable to check flow rate against maximum possible.')
        
        % define it as infinite so its not really checked
        maxPossibleFlow = inf;
end

% error handling
if ~isscalar(setFlow) || ~isreal(setFlow) || isnan(setFlow) || setFlow < 0 || setFlow > maxPossibleFlow
    
    % errors
    error('Flow rate must be a number from 0 to %d mL min^-1', maxPossibleFlow)
end

% pump actually handles flow rates in uL min-1 - so multiply it on command,
% rounding as we go
knauerpumpobjcomm(serialObject, 'write', sprintf('FLOW:%.0f', setFlow * 1000))

Contact us