Code covered by the BSD License  

Highlights from
Knauer pump RS232 communication

Knauer pump RS232 communication



Functions for communicating with Knauer pumps via RS232.

knauerpumpobjwritemaxpress(serialObject, maxPress, pumpHeadSize)
function knauerpumpobjwritemaxpress(serialObject, maxPress, pumpHeadSize)
% KNAUERPUMPOBJWRITEMAXPRESS sets maximum pressure of Knauer pumps
% knauerpumpobjwritemaxpress(serialObject, maxPress, pumpHeadSize)
% changes the maximum pressure of Knauer pumps (where the pump will stop
% pumping automatically) given a valid serial object and a pressure from 0
% to 400 bar.  The function automatically rounds the minimum pressure to
% the nearest integer.  If no pump head size is supplied, it will try and
% retrieve it, but if one is supplied, then will retrieve the maximum
% pressure set for that pump head size.

% e.g. knauerpumpobjwritemaxpress(serialObject, 250) - sets maximum
% pressure of the pump to 250 bar

% Range:

% serialObject = valid serial object

% minPress = unsigned number: 0-400

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

% if a pump head size was supplied...
if nargin >= 3
    % check the input
    if ~isvalidknauerpumpheadsize(pumpHeadSize)
        % complain
        error('Must supply a valid pump head size - 10 or 50 [mL].')

    % fetch it
    pumpHeadSize = knauerpumpobjreadpumpheadsizefast(serialObject);

% depending on what it is, different pressures are possible
switch pumpHeadSize
    case 10
        % its 400 bar
        maxPossiblePress = 400;
    case 50
        % its 150 bar
        maxPossiblePress = 150;
        % issue a warning
        warning('Unknown pump head size for Knauer pump - unable to check pressure against maximum pressure.')
        % define it as infinite so its not really checked
        maxPossiblePress = inf;

% error handling
if ~isnumberbetween(maxPress, 0, maxPossiblePress)
    % errors
    error('Maximum pressure must be a number from 0 to %d bar', maxPossiblePress)

% checks the minimum pressure
if maxPress ~= round(maxPress)
    % display a warning (don't actually need to round it off as the sprintf
    % will deal with that)
    warning('KnauerPumpWriteMinPress:ValueTooPrecise', 'Supplied minimum pressure was not an integer so has been rounded off.')

% forms and writes command
knauerpumpobjcomm(serialObject, 'write', sprintf('PMAX%d:%.0f', pumpHeadSize, maxPress))

Contact us