Code covered by the BSD License  

Highlights from
Thar ABPR-20 RS232 communication via handheld emulation

Thar ABPR-20 RS232 communication via handheld emulation

by

 

20 May 2013 (Updated )

Controls and reads from a Thar ABPR-20, by emulating the handheld controller.

tharbprobjwritevalveposition(tharBPRObj, valvePosition)
function tharbprobjwritevalveposition(tharBPRObj, valvePosition)
% BPROBJWRITEVALVEPOSITION sets the valve position of Thar BPRs
% tharbprobjwritevalveposition(tharBPRObj, valvePosition) writes the
% current valve position of Thar BPRs. tharBPRObj is the BPR serial object
% (generated by tharbproj) and valve position is an integer from 0 to 6000,
% where 0 is completely closed, and 6000 is completely open.  The valve
% position cannot be set if automatic valve control is already on.

% e.g. tharbprobjwritevalveposition(tharbprobj(5), 1000) - sets the current
% valve position of the Thar BPR on COM5 to e.g. 1000 (i.e. partially
% open).

% Range:

% tharBPRObj = valid serial port object

% valvePosition = integer from 0 to 6000


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

% error handling
if ~isnumberbetween(valvePosition, 0, 6000)
    % errors
    error('valvePosition must be a scalar integer from 0 to 6000.')
    
elseif ~tharbprobjreadcontrolstatus(tharBPRObj)
    % errors
    error('Cannot set valve position when valve is being automatically controlled.')
end

% navigates to main display menu
tharbprobjdisplaymenu(tharBPRObj);

% press 'G' then the number, then enter (should bring you back into the
% main display menu) - will display a warning if the number had to be
% rounded off)
tharbprobjcomm('write', tharBPRObj, ['G', num2str(roundto(valvePosition, 0, true)), char(13)])

Contact us