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.

tharbprobjwritekp(tharBPRObj, kp, profile)
function tharbprobjwritekp(tharBPRObj, kp, profile)
% THARBPROBJWRITEKP writes the kp of a profile in a Thar BPR
% tharbprobjwritekp(tharBPRObj, kp, profile) writes the kp to a profile in
% a Thar BPR. 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. kp is an integer from 0
% to 1000.

% e.g. tharbprobjwritekp(tharbprobj(5), 500) - sets the kp of the current
% profile to 500 on the Thar BPR attached to COM5

% Range:

% tharBPRObj = valid serial port object

% kp = integer from 0 to 1000

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

% error handling
if nargin < 2
    % errors
    error('Insufficient arguments')
elseif ~isnumeric(kp) || ~isscalar(kp) || isnan(kp) || ~isreal(kp) || kp < 0 || kp > 300
    % errors
    error('kp must be a scalar integer between 0 and 300.')

% more error handling
if nargin < 3
    % gets the current profile
    profile = tharbprobjreadcurrentprofile(tharBPRObj);
elseif numel(profile) ~= 1 || ~any(strcmp(profile, {'A', 'B'}))
    % errors
    error('Profile must be either A or B.')
    % navigates to the display menu

% rounds the kp
roundkp = round(kp);

% checks the kp
if kp ~= roundkp
    % rounds the number
    kp = roundkp;
    % display a warning
    warning('TharBPRWriteKP:ValueTooPrecise', 'Supplied Kp was not an integer so has been rounded off.')

% presses F5 then the profile name to get to the correct screen, skips past
% the name, enters kp, presses enter four times, then 'y' to save the
% changes
tharbprobjcomm('writesave', tharBPRObj, [char(21), profile, char(13), num2str(kp), char([13, 13, 13, 13]), 'Y'])

Contact us