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.

tharbprobjreadkp(tharBPRObj, profile)
function kp = tharbprobjreadkp(tharBPRObj, profile)
% THARBPROBJREADKP reads Kp of a profile in Thar BPRs
% kp = tharbprobjkp(tharBPRObj, profile) reads the Kp (PID constant) of a
% particular profile of Thar BPRs. tharBPRObj is the BPR serial object
% (generated by tharbproj).  The profile is either 'A' or 'B', or omitted,
% in which case the name of the current profile is used.  Kp is a number.

% e.g. kp = tharbprobjreadkp(tharbprobj(5), 'A') - returns the kp for
% profile A of the Thar BPR on COM5, e.g. 600.

% Range:

% tharBPRObj = valid serial port object

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


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

% if profile wasn't defined, fetch the current one, otherwise, error check
% the supplied profile
if nargin < 2
    % gets the current profile, and turns it into lower case for data input
    profile = tharbprobjreadcurrentprofile(tharBPRObj);
    
elseif ~istharbprobjprofile(profile)
    % errors
    error('Profile must be either A or B.')
end
    
% navigates to display menu
tharbprobjdisplaymenu(tharBPRObj);

% presses F5 to get to the profile setup screen, then selects a profile
tharbprobjcomm('write', tharBPRObj, [21, uint8(profile), 13])

% reads out the screen
response = tharbprobjcomm('readnoflush', tharBPRObj);

% pull out the numbers and converts them
kp = str2double(response{3}(isstrprop(response{3}, 'digit')));

% navigate back
tharbprobjcomm('write', tharBPRObj, 27)

Contact us