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.

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.')
end

% 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.')
else
    % navigates to the display menu
    tharbprobjdisplaymenu(tharBPRObj);
end

% 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.')
end

% 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