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.

realtermfwrite(handle, input)
function realtermfwrite(handle, input)
% REALTERMFWRITE sends a command to the serial device via realterm.

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

% error handling
if ~isrealtermhandle(handle)
    % the real term handle must be a valid handle
    error('The realTermHandle is not valid.')
elseif ~isrunning(handle)
    % realterm must be connected
    error('Realterm is not connected to the serial object.')
elseif (~isnumeric(input) && ~ischar(input)) || ~isvector(input)
    % the input must be a string
    error('Must send the data as a numeric vector.')

% converts the input if it needs to be
if isnumeric(input)
    % converts it
    input = char(input);

% depending on the size of the input, and if it contains any 0s - UPDATE -
% this has been deprecated because realterm appears to be modifying the
% last byte in the string if it is larger than 129 (seen for 132 but OK for
% 129) - unknown why! - for security, done for larger than 127 (suspect its
% an issue with post-ASCII codes)
if numel(input) == 1 || any(~input) || any(double(input) > 127)
    % sends it a character at a time
    for m = 1:numel(input)
        % sends it
        invoke(handle, 'PutChar', input(m))

    % send it as a string
	invoke(handle, 'PutString', input)

Contact us