Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation



06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

tharbprobjwritealarmpress(tharBPRObj, alarmPress, profile)
function tharbprobjwritealarmpress(tharBPRObj, alarmPress, profile)
% THARBPROBJWRITEALARMPRESS writes the alarm pressure of Thar BPRs
% tharbprobjwritealarmpress(tharBPRObj, alarmPress, profile) writes the
% alarm 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 alarm pressure is applied to the current
% profile. The pressure must be supplied in bar.

% e.g. tharbprobjwritealarmpress(tharbprobj(5), 500) - sets the alarm pressure
% of the current profile to 500 bar on the Thar BPR attached to COM5

% Range:

% tharBPRObj = valid serial port object

% alarmPress = integer from 0 to 650

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

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

% 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 pressure
roundAlarmPress = round(alarmPress);

% checks the alarm pressure
if alarmPress ~= roundAlarmPress
    % rounds the number
    alarmPress = roundAlarmPress;
    % display a warning
    warning('TharBPRWriteAlarmPress:ValueTooPrecise', 'Supplied alarm pressure was not an integer so has been rounded off.')

% checks the external heater status, as if this is on then there will be
% two extra screens to pass through at the end
if strcmp(tharbprobjreadextheaterstatus(tharBPRObj), 'on')
    % sets the extra keystrokes
    enters = char([13, 13]);
    % adds no extra keystrokes
    enters = '';

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

% reads out the screen to find out the allowed range of alarm pressures
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{4}, '%s', 'delimiter', '-');

% checks the new alarm pressure to see if its in the right range
if alarmPress < 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 press as it is smaller than the set pressure.')
    % enters the new alarm pressure, 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, [num2str(alarmPress), char([13, 13]), enters, 'Y'])

Contact us