Code covered by the BSD License  

Highlights from
Thar ABPR-20 RS232 communication via handheld emulation

Thar ABPR-20 RS232 communication via handheld emulation



20 May 2013 (Updated )

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

tharbprobjwritesetpress(tharBPRObj, setPress, profile)
function tharbprobjwritesetpress(tharBPRObj, setPress, profile)
% THARBPROBJWRITESETPRESS writes the set pressure of Thar BPRs
% tharbprobjwritesetpress(tharBPRObj, setPress, profile) writes the set
% pressure of Thar BPRs. tharBPRObj is the BPR serial object (generated by
% tharbproj), and profile is either 'A' or 'B'.  If the profile is not
% supplied, the set pressure is applied to the current profile. The
% pressure must be supplied in bar.

% e.g. tharbprobjwritesetpress(tharbprobj(5), 100) - sets the set pressure
% of the current profile to 100 bar on the Thar BPR attached to COM5

% Range:

% tharBPRObj = valid serial port object

% setPress = integer from 0 to 600

% profile = 'A', 'B' or omitted

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

% error handling
if ~isnumberbetween(setPress, 0, 600)
    % errors
    error('setPress must be a scalar integer between 0 and 600.')

% if the serial object is "conventional"
if ~isfield(tharBPRObj.UserData, 'realTermHandle')
    % responds more reliably if you do fclose/fopen before the command - unsure
    % of long-term stability of this technique so this is not employed in the
    % low-level comms protocols

    % if this part errors...
        % reconnects
        % displays a warning
        warning('tharBPRObjWriteSetPress:fopenFailed', 'Could not reconnect serial object.')

% more error handling
if nargin < 3
    % gets the current profile
    profile = tharbprobjreadcurrentprofile(tharBPRObj);
elseif ~istharbprobjprofile(profile)
    % errors
    error('Profile must be either A or B.')

% presses F4 then the profile name to get to the correct screen, enters the
% pressure, presses enter twice
tharbprobjcomm('write', tharBPRObj, [char(20), profile, num2str(roundto(setPress, 0, true)), char([13, 13])])

% checks its on the right screen first...
response = tharbprobjcomm('readnoflush', tharBPRObj);

% if its on the save screen, then press yes to save, otherwise press enter
% twice again then press yes to save
if ~strcmp(response{3}(1:11), 'Save setup?')
    % otherwise skip past the next two temperature fields
    keyStrokes = [char([13, 13]), 'Y'];
    % presses y to save it
    keyStrokes = 'Y';

% presses the last few keys
tharbprobjcomm('writesave', tharBPRObj, keyStrokes)

Contact us