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.

function tharbprobjwriteextalarmtemp(tharBPRObj, extAlarmTemp, profile)
% THARBPROBJWRITEEXTALARMTEMP writes the external alarm temp. of Thar BPRs
% tharbprobjwriteextalarmtemp(tharBPRObj, extAlarmTemp, profile) writes the
% external heater alarm temperature 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 alarm temperature (in C) is applied
% to the current profile.

% e.g. tharbprobjwriteextalarmtemp(tharbprobj(5), 75) - sets the external
% heater alarm temperature of the current profile to 75 C on the Thar BPR
% attached to COM5

% Range:

% tharBPRObj = valid serial port object

% extAlarmTemp = integer from 0 to 75 (actually from the setTemp to 75, but
% initially it is only tested to be more than 0)

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

% error handling
if nargin < 2
    % errors
    error('Insufficient arguments')
elseif ~isnumeric(extAlarmTemp) || ~isscalar(extAlarmTemp) || isnan(extAlarmTemp) || ~isreal(extAlarmTemp) || extAlarmTemp < 0 || extAlarmTemp > 75
    % errors
    error('extAlarmTemp must be a scalar integer between 0 and 75.')
elseif strcmp(tharbprobjreadextheaterstatus(tharBPRObj), 'on')
    % errors
    error('Cannot set external heater set temperature if the heater is not enabled.')

% more error handling
if nargin < 3
    % gets the current profile, and turns it into lower case for data input
    profile = tharbprobjreadcurrentprofile(tharBPRObj);
elseif numel(profile) ~= 1 || ~any(strcmp(profile, {'A', 'B'}))
    % errors if not 'A' or 'B'
    error('Profile must be either A or B.')

% rounds the alarm temperature
roundExtAlarmTemp = round(extAlarmTemp);

% checks the alarm temperature
if extAlarmTemp ~= roundExtAlarmTemp
    % rounds the number
    extAlarmTemp = roundExtAlarmTemp;
    % display a warning
    warning('TharBPRWriteExtAlarmTemp:ValueTooPrecise', 'Supplied alarm temperature was not an integer so has been rounded off.')

% presses F4, then the profile name, then presses enter 3 times to get to
% the correct screen
tharbprobjcomm('write', tharBPRObj, [20, uint8(profile), 13, 13, 13])

% reads out the screen to find out the allowed range of alarm temperatures
response = tharbprobjcomm('readnoflush', tharBPRObj);

% the fourth line has the allowed range on - use textscan to use the '-' as
% a delimiter because the position of the numbers may shift
response = textscan(response, '%s', 'delimiter', '-');

% checks the new alarm temperature to see if its in the right range
if extAlarmTemp < str2double(response{1}{1}(isstrprop(response{1}{1}, 'digit')))
    % navigates out of the menu
    tharbprobjcomm('write', tharBPRObj, 27)
    % errors
    error('Could not set new alarm temperature as it is smaller than the set temperature.')
    % enters the new alarm temperature, presses enter once, 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, [num2str(extAlarmTemp), char(13), 'Y'])

Contact us