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.

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

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

% Range:

% tharBPRObj = valid serial port object

% kd = integer from 0 to 1000

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


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

% checks the kd
if kd ~= roundkd
    % rounds the number
    kd = roundkd;
    
    % display a warning
    warning('TharBPRWriteKD:ValueTooPrecise', 'Supplied Kd 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 and ki, enters kp, 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, [char(21), profile, char([13, 13, 13]), num2str(kd), char([13, 13]), 'Y'])

Contact us