Serial Terminal:

Controlling RealTerm from Matlab

Realterm now has an Examples directory, which contains more up-to-date examples than below
RealtermDemo.m is on Download page

 

Contents

Realterm's ActiveX interface was added so it could be controlled from Matlab 5. Realterm is fast, runs independent of the Matlab process, and is reliable. It lets you see the data you are sending and receiving. As it runs in its own process, there are none of the problems caused by Matlabs single threaded-ness

Matlab V6 added serial port support, but it has problems with reliability, speed, and the matlab threading model


A Simple Demo

(What follows is for V5.3. V6.5 of matlab has changed some activeX stuff. eg enumerations now return strings, not numbers. See "Introducing New ActiveX Features in Matlab 6.5" )

Download


hrealterm=actxserver('realterm.realtermintf'); % start Realterm as a server
% Only use these 3 lines to see what properties and methods realterm has.....
fprintf(1,'\nProperties of Realterm\n\n');
get(hrealterm) %List all properties.
try
set(hrealterm) %In later versions of matlab, this will show you what possible values the enumerations can take
catch
end
fprintf(1,'\n\nMethods of Realterm\n\n');
invoke(hrealterm) %List all functions
% some example properties
hrealterm.baud=57600;
hrealterm.caption='Matlab Realterm Server';
hrealterm.windowstate=1; %minimized
hrealterm.PortOpen=1; %open the comm port
is_open=(hrealterm.PortOpen~=0); %check that it opened OK
hrealterm.displayas=2; %show hex in terminal window
hrealterm.CaptureFile='c:\temp\matlab_data.dat'
invoke(hrealterm,'startcapture'); %start capture
%do what you want here
fprintf(1,'\n\nTry what you want here. Type RETURN to end demo and close realterm\n')
keyboard
invoke(hrealterm,'stopcapture');
try %try to close any we can in case they are faulty.
invoke(hrealterm,'close'); delete(hrealterm);
catch
fprintf('unable to close realterm')
end; %try

back to contents


Using Capture

When you want to get data from an instrument, and process it in Matlab, I find it is easier to just capture data to a file with Realterm, then have Matlab read the file. This is a "design pattern" that appears ugly, but has been easy to get going, and sucessful. It is well decoupled, which is what makes it so easy to do.

The key point is that you can open a file for READ with Scilab, while Realterm has it open for WRITE

How:

Using Sendfile

It can be even easier to just put outgoing commands into a file, and use SendFile to send them. By setting SendRepeats and SendDelay, you can make the commands repeat automatically, and just use your matlab program to read the data at its leisure. This technique is ideal for data logging applications.

Using Commandline:

If you don't want to use the ActiveX interface, then later versions of Realterm let you directly send commands repeatedly using sendfile, and sendrep, and using capture to get the result. You can use this with Scilab for example, as it doesn't have an activeX interface.

back to contents


Books


Contact Us

crun@users.sourceforge.net

back to contents