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.

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

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

% Range:

% tharBPRObj = valid serial port object

% kd = integer from 0 to 1000

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

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

% 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 kd
roundkd = round(kd);

% checks the kd
if kd ~= roundkd
    % rounds the number
    kd = roundkd;
    % display a warning
    warning('TharBPRWriteKD:ValueTooPrecise', 'Supplied Kd 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 and kp and ki, enters kp, presses enter twice, then 'y' to save
% the changes - it takes around 4 seconds before the BPR starts sending
% screen updates out again (no idea why)
tharbprobjcomm('writesave', tharBPRObj, [char(21), profile, char([13, 13, 13]), num2str(kd), char([13, 13]), 'Y'])

Contact us