Code covered by the BSD License  

Highlights from
Thar ABPR-20 RS232 communication via handheld emulation

Thar ABPR-20 RS232 communication via handheld emulation

by

 

20 May 2013 (Updated )

Controls and reads from a Thar ABPR-20, by emulating the handheld controller.

tharbprobjdisplaymenu2(serialObject)
function response = tharbprobjdisplaymenu2(serialObject)
% BPROBJREADDISPLAYMENU2 navigates to the second display menu of Thar BPRs
% response = tharbprobjdisplaymenu2(serialObject) navigates to the SECOND
% display menu of Thar BPRs. serialObject is the BPR serial object
% (generated by tharbproj). Response is the displayed menu itself, so that
% its contents can be used immediately if necessary.

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

% fetches contents of screen (quite a quick operation)
try
    % fetches screen contents - it will error if there is no data - if this
    % is the right screen, then we don't need to do anything more
    response = tharbprobjcomm('read', serialObject);
    
    % if the first part of the 3nd line is 'POS:' then we know we are in
    % the display menu already and only need to press F3 once
    if strcmp(response{3}(1:4), 'POS:')
        % presses F3
        tharbprobjcomm('write', serialObject, 19)
        
        % fetches screen contents - it SHOULD be the second display menu, but if
        % it errors it is not a problem anyway
        response = tharbprobjcomm('read', serialObject);
        
    elseif ~any(strfind(response{2}, 'External Heat:'))
        % if it didn't error, then we are already in a position where we
        % can press F3 to get to the display menu, then F3 again to get to
        % the second half of it
        
        % presses F3 twice
        tharbprobjcomm('write', serialObject, [19, 19])
        
        % fetches screen contents - it SHOULD be the second display menu,
        % but if it errors it is not a problem anyway - this is not
        % rationalised into the above if block because subsequent commands
        % should be sent as the same string to keep the time spacing
        % correct
        response = tharbprobjcomm('read', serialObject);
    end
    
catch
    % if there is no data, 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', serialObject, [97, 27])
    
    % try reading the display again
    response = tharbprobjcomm('read', serialObject);
    
    % if we are not in the second part of the display menu...
    if ~any(strfind(response{2}, 'External Heat:'))
        % press F3 twice
        tharbprobjcomm('write', serialObject, [19, 19])
        
        % read the display again
        response = tharbprobjcomm('read', serialObject);
    end
end

% at the end, if it still hasn't got to the right menu, errors
if numel(response{2}) < 14 || (numel(response{2}) >= 14 && ~strcmp(response{2}(1:14), 'External Heat:'))
    % displays a warning
    warning('tharBPRObjDisplayMenu2:CouldNotReachMenu', 'Could not access the second display menu.')
    
    % displays the data
    response
    
    % errors
    error('Could not get to the second display menu.')
end

Contact us