Code covered by the BSD License  

Highlights from
Thar ABPR-20 RS232 communication via handheld emulation

Thar ABPR-20 RS232 communication via handheld emulation



20 May 2013 (Updated )

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

function tharbprobjconnect(serialObject)
% THARBPROBJCONNECT initialises communication with Thar BPRs
% tharbprobjconnect(serialObject) initialises communication with Thar BPRs,
% given serialObject as a valid serial object (generated by tharbprobj).

% e.g. tharbprobjconnect(serialObject) - initialises communication with
% the Thar BPR

% Range:

% serialObject = valid serial port object

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

% error handling
if ~isserial(serialObject) || isrunning(serialObject)
    % errors
    error('serialObject must be a valid closed serial object.')
elseif isfield(serialObject.UserData, 'realTermHandle') && isrunning(serialObject.UserData.realTermHandle)
    % errors
    error('The realterm application must not be connected.')

% if the real term handle is there, do a different sequence of events
if isfield(serialObject.UserData, 'realTermHandle')
    % run the real term opener
    serialObject.UserData.captureFileID = realtermfopen(serialObject.UserData.realTermHandle);

    % opens communication

% sends initiating command - at the moment this MUST be sent within ~10
% seconds of the BPR being switched on - after this is done the first time,
% then as long as the BPR is not turned off, then this is not necessary
tharbprobjcomm('write', serialObject, [char(27), '[0n'])

% Notes (<ESC> is char(27)):

% First command is sent by the BPR: '<ESC>[4n' (~4.5 s after turning on)
% HOWEVER, have also seen: '<ESC>[1[4n' (suspected read error since this
% does not normally fit the BPR communications syntax and '<ESC>[1s'

% The hand-held appears to check its own memory (this message does not come
% from the BPR), before sending the initialisation command below:

% Response by the hand-held: '<ESC>[0n' (~7.3 s after turning on)

% The BPR immediately responds by sending the first batch of screen content
% to self-test the BPR, then sends another command: '<ESC>[0q' - this also
% seems to mean "bad key press"

Contact us