Code covered by the BSD License  

Highlights from
CO2gui - lab control and automation

CO2gui - lab control and automation

by

 

06 Jan 2010 (Updated )

Software used for controlling and data logging lab equipment.

tharbprobjwriteprofilesetup.m
function tharbprobjwriteprofilesetup(tharBPRObj, setPress, alarmPress, extSetTemp, extAlarmTemp, profile)
% THARBPROBJWRITEPROFILESETUP writes a full profile setup to a Thar BPR
% tharbprobjwriteprofilesetup(tharBPRObj, setPress, alarmPress, extSetTemp,
% extAlarmTemp, profile) writes the set pressure, alarm pressure, external
% set temperature, and the external heater alarm temperature. tharBPRObj is
% the BPR serial object (generated by tharbproj), and profile is either 'A'
% or 'B'.  If the profile is not supplied, the current profile is written
% to. The pressures are required in bar and the temperatures in C.  Both
% the extSetTemp and extAlarmTemp are not set if the external heater is
% disabled.


% gets the current external heater status
extHeaterStatus = tharbprobjreadextheaterstatus(tharBPRObj);

% first pass error handling - only checks the arguments if they are not
% empty - if they are empty, those values will not be entered later -
% num2str([]) returns '' - which is exactly what we want
if nargin < 5
    % errors
    error('Insufficient arguments')
    
elseif ~isempty(setPress) && (~isscalar(setPress) || ~isnnumber(setPress) || setPress < 0 || setPress > 600)
    % errors
    error('setPress must be a scalar integer between 0 and 600.')
    
elseif ~isempty(alarmPress) && (~isscalar(alarmPress) || ~isnumber(alarmPress) || alarmPress < setPress || alarmPress > 650)
    % errors
    error('alarmPress must be a scalar integer between the set pressure (%d) and 650.', setPress)
    
elseif extHeaterStatus
    % only checks the temperature parameters if they are going to be set
    if ~isempty(extSetTemp) && (~isscalar(extSetTemp) || isnumber(extSetTemp) || extSetTemp < 0 || extSetTemp > 75)
        % errors
        error('extSetTemp must be a scalar integer between 0 and 75.')
        
    elseif ~isempty(extAlarmTemp) && (~isscalar(extAlarmTemp) || isnumber(extAlarmTemp) || extAlarmTemp < extSetTemp || extAlarmTemp > 75)
        % errors
        error('extAlarmTemp must be a scalar integer between the set temperature (%d) and 75.', extSetTemp)
    end
end

% if profile wasn't defined, fetch the current one, otherwise, error check
% the supplied profile
if nargin < 6
    % gets the current profile
    profile = tharbprobjreadcurrentprofile(tharBPRObj);
    
elseif ~istharbprobjprofile(profile)
    % errors
    error('Profile must be either A or B.')
end

% checks the set pressure
if isInteger(setPress)
    % rounds the number
    setPress = round(setPress);
    
    % display a warning
    warning('TharBPRWriteProfileSetup:ValueTooPrecise', 'Supplied set pressure was not an integer so has been rounded off.')
end

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

% sets the pressures (and temperatures if the heater is enabled)
tharbprobjcomm('write', tharBPRObj, [char(20), profile, num2str(setPress), char(13), num2str(alarmPress), char(13)]')

% checks the most recent screen
response = tharbprobjcomm('readnoflush', tharBPRObj);

% if this is the save setup screen, press Y straight away, and ignore the
% setExtTemp and setAlarmTemp
if strcmp(response{3}(1:4), 'Save')
    % saves
    tharbprobjcomm('writesave', tharBPRObj, 'Y')
    
    % displays a warning if extSetTemp and extAlarmTemp were supplied
    if ~isempty(extSetTemp) || ~isempty(extAlarmTemp)
        % warning
        warning('tharbprobjwriteprofilesetup:noTempsSet', 'The extSetTemp and the extAlarmTemp were not set.')
    end
    
else
    % checks the external set temperature
    if isInteger(extSetTemp)
        % rounds the number
        extSetTemp = roundExtSetTemp;

        % display a warning
        warning('TharBPRWriteProfileSetup:ValueTooPrecise', 'Supplied exteral set temperature was not an integer so has been rounded off.')
    end
    
    % rounds the alarm temperature
    roundExtAlarmTemp = round(extAlarmTemp);

    % checks the alarm temperature
    if extAlarmTemp ~= roundExtAlarmTemp
        % rounds the number
        extAlarmTemp = roundExtAlarmTemp;

        % display a warning
        warning('TharBPRWriteProfileSetup:ValueTooPrecise', 'Supplied alarm temperature was not an integer so has been rounded off.')
    end
    
    % sends the values and saves it
    tharbprobjcomm('writesave', tharBPRObj, [num2str(extSetTemp), char(13), num2str(extAlarmTemp), char(13), 'Y'])
end

Contact us