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.

function response = tharbprobjdisplaymenufast(tharBPRObj)
% BPROBJREADDISPLAYMENUFAST navigates to the first display menu of Thar BPRs
% response = tharbprobjdisplaymenufast(tharBPRObj) navigates to the display
% menu of Thar BPRs. tharBPRObj is the BPR serial object (generated by
% tharbproj). Response is the displayed menu itself, so that its contents
% can be used immediately if necessary.  This fast version attempts to read
% from the buffer first.

% checks the number of arguments
error(nargchk(1, 1, nargin))

% fetches contents of screen (quite a quick operation)
    % quickly fetches the most recent screen contents - it will error if
    % there is no data but will not be a valid "menu" if its not fully
    % collected
    response = tharbprobjcomm('readfast', tharBPRObj);
    % check the read was successful
    if ~isMenu(response)
        % try again with a more robust read of fresh data
        response = tharbprobjcomm('read', tharBPRObj);
        % tests it again
        if ~isMenu(response)
            % otherwise, as it didn't error before, we can press F3 again to
            % get into the first half of the display menu, regardless of our
            % location in the menu structure
            tharbprobjcomm('write', tharBPRObj, 19)

            % fetches screen contents - it SHOULD be the display menu, but if
            % it errors it is not a problem anyway
            response = tharbprobjcomm('read', tharBPRObj);
    % if there is no data from the first read, we know we are probably in a
    % sub-menu
    % if the sub-menu is the system configuration menu, then almost any
    % keystroke will take you back to the more options menu, where <ESC>
    % will not break anything
    % press A (ascii 97) - this is to choose a profile if we are in the
    % annoying profile menu which does not allow escaping, then shift + z
    % to get out (<ESC>)
    tharbprobjcomm('write', tharBPRObj, [97, 27])
    % try reading the display again
    response = tharbprobjcomm('read', tharBPRObj);
    % if we are in the second part of the display menu...
    if strcmp(response{2}(1:14), 'External Heat:')
        % press F3 again
        tharbprobjcomm('write', tharBPRObj, 19)
        % try reading the display again
        response = tharbprobjcomm('read', tharBPRObj);

% if the profile isn't there, display the response and error
if ~isMenu(response)
    % displays a warning
    warning('tharBPRObjDisplayMenu:CouldNotReachMenu', 'Could not access the main display menu.')
    % displays the response
    % errors
    error('Could not get to the main display menu as stuck - unit possibly not responding to keypresses.')

% decides if its in the right screen or not
function value = isMenu(response)

% it must have...
secondLineA = numel(response{2}) >= 8 && strcmp(response{2}(1:8), 'Profile:');
secondLineB = numel(response{2}) >= 16 && strcmp(response{2}(12:16), 'CTRL:');
thirdLineA = numel(response{3}) >= 4 && strcmp(response{3}(1:4), 'POS:');
thirdLineB = numel(response{3}) >= 16 && strcmp(response{3}(12:16), 'VTMP:');
fourthLineA = numel(response{4}) >= 4 && strcmp(response{4}(1:4), 'SET:');
fourthLineB = numel(response{4}) >= 15 && strcmp(response{4}(11:16), 'PRESS:');

% returns a value
value = secondLineA && secondLineB && thirdLineA && thirdLineB && fourthLineA && fourthLineB;

Contact us