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.

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

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

% Range:

% tharBPRObj = valid serial port object

% ki = integer from 0 to 1000

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

% error handling
if nargin < 2
    % errors
    error('Insufficient arguments')
elseif ~isnumeric(ki) || ~isscalar(ki) || isnan(ki) || ~isreal(ki) || ki < 0 || ki > 1000
    % errors
    error('ki 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 ki
roundki = round(ki);

% checks the ki
if ki ~= roundki
    % rounds the number
    ki = roundki;
    % display a warning
    warning('TharBPRWriteKI:ValueTooPrecise', 'Supplied Ki 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, enters ki, presses enter three times, 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]), num2str(ki), char([13, 13, 13]), 'Y'])

Contact us