How do I use Matlab's timer and MatlabClock?

As of Release 13 (Version 6.5) Matlab comes with a timer class that will call a specified matlab command with a given frequency and parameters.  For example, you could use the command:

t = timer('Period', 1, 'Name','Greeting','TimerFcn','disp(''hello'')','ExecutionMode','fixedRate')

to create a timer called tthat with the name Greeting that displays "hello" at a fixed rate of 1 time per second.   This clock has many other features, such as the ability to be either reliable or unreliable.  To find out more about this object, use the Matlab help files.

Since most applications working with TinyOS are event-driven, a graphical interface that allows the user to change the period or stop/start the timer without typing the command might be useful.  If you want to use such a timer, replace your MATLAB/java/jar/timer.jar file with the one found in tinyos-1.x/tools/java/net/tinyos/matlab/.  This .jar file will replace your standard Matlab timer with a new one that has a GUI.  All other functionality is exactly identical.

MatlabClock is a class in the net.tinyos.matlab package.  It also calls matlab commands with a given frequency.  You can use MatlabClock with the following type of command:

mClock = net.tinyos.matlab.MatlabClock('Title', 'functionName', 500)

To create a clock that calls "functionName" every 500ms.  The GUI has title 'Title'.  The disadvantage of MatlabClock is that it doesn't allow you to pass parameters to your function, nor does it print out the error messages of your function.  However, you may want to use this class if you are using a version of Matlab prior to R13.