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 status = knauerpumpobjstatusold(serialObject)
% KNAUERPUMPOBJSTATUSOLD returns the current status of Knauer pumps
% status = knauerpumpobjstatusold(serialObject) returns the status of Knauer
% pumps connected to a valid serial object.  If the pump is running, the
% status is 1, and 0 if it is not pumping.  This is currently only reliable
% for flow rates of >0.25 mL min-1 on a pump fitted with a 50 mL pump head,
% since the method it uses is based on the current being used by the pump
% at any given time.  It is not yet clear what the lower flow rate bound is
% for the 10 mL pump head, but it is expected to be closer to 0.05 mL min-1
% based on the technical specifications.  If the flow rate is too low to
% reliable determine pumping status, then this tries to locate the
% historical date located in UserData.status, which assumes that a) no-one
% has changed the pump on the front panel and b) the UserData has not been
% messed with. If at this point there is no status field in the UserData
% (or there isn't a structure there in the first place) then it will just
% error as there is no way to estimate the flow rate at all.  Unfortunately
% measurement of pump status at lower flow rates can be very slow due to
% the time taken for a piston to move to a point in the cycle where it
% consumes some amount of power.  This has since been deprecated due to the
% discovery of the 'STATUS?' command.

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

% need to get the flow rate to start...
flowRate = knauerpumpobjreadflow(serialObject);

% and the pump head size too
pumpHeadSize = knauerpumpobjreadpumpheadsizefast(serialObject);

% calculates a utilisation
utilisationFraction = flowRate / pumpHeadSize;

% if the flow rate is <0.5% of capacity, then flow rate measurements are
% going to be unreliable
if utilisationFraction < 0.005

    % warning we can't reliable measure this
    warning('Set flow rate is too low to reliably measure the pump operating status - estimating from historical pump behaviour.')
    % tries the fast method
    status = knauerpumpobjstatusfast(serialObject);
    % maximum number of tries to get a non-zero power measurement from the
    % pump
    % 0.25 mL min-1 = 145 max
    % 0.5 mL min-1 = 68 max
    % 0.75 mL min-1 = 43 max
    % 1 mL min-1 = 27 max
    % 2 mL min-1 = 6 max
    % 3 mL min-1 = 1 max
    % plotting 1/flow (x) versus number of tries (y) gives a linear
    % correlation - y = 39.479x - 11.982 - can give us an estimate of the
    % number of tries required, instead of binning per flow rate i.e. y =
    % (39.479 / x) - 11.982
    expectedTries = (39.479 / flowRate) - 11.982;
    % and then add a 25% error margin to be sure, rounding off
    tries = round(1.25 * expectedTries);
    % pre-initialise matrix for speed
    motorCurrent = zeros(tries, 1);
    % assume the pump is not pumping - if the current is always 0 then this
    % will not be changed
    status = 0;
    % loops round
    for m = 1:tries

        % finds out what it is - takes about 70 ms per communication
        motorCurrent(m) = knauerpumpobjcomm(serialObject, 'read', 'IMOTOR?');

        % if this is positive, then we don't need to ask anymore
        if motorCurrent(m)
            % then set the status to 1 - its pumping
            status = 1;
            % then break out of the loop early

Contact us