Controlling RealTerm from
||Realterm now has an Examples directory, which contains more up-to-date examples than below
RealtermDemo.m is on Download
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.
New ActiveX Features in Matlab 6.5" )
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.
set(hrealterm) %In later versions of matlab, this will show you what possible values the enumerations can take
fprintf(1,'\n\nMethods of Realterm\n\n');
invoke(hrealterm) %List all functions
% some example properties
hrealterm.caption='Matlab Realterm Server';
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
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')
try %try to close any we can in case they are faulty.
fprintf('unable to close realterm')
back to contents
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
- Doesn't care how fast or slow matlab runs your program.
- serial comms runs in its own thread, completely independent
- very easy to get going and debug, as the matlab program
just reads data into a file
- Matlab program can be tested on data files without real,
- Start file capture. (Realterm opens file for write)
- Send commands to your instrument through Realterm using Putstring
and Putchar. (see note
about 0) or Sendfile
- Open file for read in matlab.
- Check Charcount in realterm. When there is some more data,
read the file.
- Matlab can close and open the file for read, as much as it
likes. However fileopen does take a little bit of time (ie 10's per
second is OK, millions isn't)
- Seek to the last position in the file you read, and start
reading from there. Seeking takes no time, even for files which are
- You might want to close the file every now and then if it
gets to be many MB in length.
- Capturelength can set either how long Realterm captures
for, or how many bytes it will capture
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
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
back to contents