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 tharbprobjdisconnect(serialObject)
% THARBPROBJDISCONNECT terminates communication with Thar BPRs
% tharbprobjdisconnect(serialObject) terminates communication with Thar BPRs,
% given serialObject as a valid serial object (generated by tharbprobj), also
% deleting and clearing the object at the end.

% e.g. tharbprobjdisconnect(serialObject)) - terminates communication with
% the Thar BPR

% Range:

% serialObject = valid open serial port object

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

% error handling
if ~isserial(serialObject) || (~isfield(serialObject.UserData, 'realTermHandle') && ~isrunning(serialObject))
    % errors if the realterm handle isn't there, and the serial object is
    % closed
    error('serial must be a valid open serial object.')
elseif isfield(serialObject.UserData, 'realTermHandle') && ~isrunning(serialObject.UserData.realTermHandle)
    % errors
    error('The realterm application must be connected.')

elseif isfield(serialObject.UserData, 'realTermHandle') && (~isfield(serialObject.UserData, 'captureFileID') || ~isfid(serialObject.UserData.captureFileID))
    % if using realterm, the capture file ID must be there
    error('If using Realterm, the capture file handle must be in the serial object''s UserData.')

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

    % closes communication conventionally

% deletes it afterwards

Contact us