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.

realterm(serialObject, varargin)
function handle = realterm(serialObject, varargin)
% REALTERM generates an ActiveX object from a previously configured serial
% object.  Multiple serial objects are not supported.

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

% checks the serial object
if ~isserial(serialObject) || ~isscalar(serialObject) || isrunning(serialObject)
    % errors
    error('This only works for valid single CLOSED serial objects.')
elseif nargin >= 2 && ~ispv(varargin{:})
    % can add additional properties is provided
    error('Additional properties must be set with valid property/value pairs.')

% tries to set up the realTermHandle in the structure (deliberately not
% done inside the serial object so that if it errors it is not as much
% of a problem)
    % defines the flow control
    switch serialObject.FlowControl
        case 'none'
            flowControl = 0;

        case 'hardware'
            % this is for standard DTR/DSR control - for RTS/CTS you use code 2
            flowControl = 1;

        case 'software'
            % this appears to be currently unavailable via the ActiveX
            % interface
            error('Cannot currently implement software flow control using Realterm and ActiveX.')

            % unknown flow control type
            error('Unknown flow control type.')
    % sets up the server
    handle = actxserver('realterm.realtermintf');

    % sets it up as per the serial properties already described (to
    % prevent unecessary duplication of code)
    set(handle, 'baud', serialObject.BaudRate,...
                'StopBits', serialObject.StopBits,...
                'DataBits', serialObject.DataBits,...
                'Parity', upper(serialObject.Parity),...
                'FlowControl', flowControl,...
                'Caption', 'MATLAB RealTerm Server',...
                'WindowState', 'wsMinimized',...
                'CaptureDirect', 1,...
                'Visible', 0)

    % inexplicably have to assign the port after everything else or it
    % doesn't work
    handle.Port = serialObject.Port(isstrprop(serialObject.Port, 'digit'));
    % if some more properties were provided, try to apply those (it will
    % error if the properties are invalid)
    if nargin >= 2
        % applies them
        set(handle, varargin{:})

    % if the handle exists and its a valid handle, close the object
    if exist('handle', 'var') && isa(handle, 'COM.realterm_realtermintf')
        % closes it

        % deletes it
    % rethrows the error so we know what went wrong

Contact us