Code covered by the BSD License  

Highlights from
Knauer pump RS232 communication

Knauer pump RS232 communication



Functions for communicating with Knauer pumps via RS232.

knauerpumpobjwriteminpress(serialObject, minPress, pumpHeadSize)
function knauerpumpobjwriteminpress(serialObject, minPress, pumpHeadSize)
% KNAUERPUMPTCPOBJWRITEMINPRESS sets minimum pressure of Knauer pumps
% knauerpumpobjwriteminpress(serialObject, minPress, pumpHeadSize)
% changes the minimum 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. knauerpumpobjwriteminpress(serialObject, 250) - sets minimum
% 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 the pump head size 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 ~isscalar(minPress) || ~isreal(minPress) || isnan(minPress) || minPress < 0 || minPress > maxPossiblePress
    % errors
    error('Maximum pressure must be a number from 0 to %d bar', maxPossiblePress)

% checks the minimum pressure
if minPress ~= round(minPress)
    % 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('PMIN%d:%.0f', pumpHeadSize, minPress))

Contact us