An example, Ex_Timer
, shows how to define a concrete atomic
class from Atomic
. In Timer.cs
file, Timer
is
defined to generat an output op
every 3.3 seconds as
illustrated in Figure 3.1.
Thus Timer
has one output port op
that is op
is assigned by calling AddOP
in the constructor. The
function init()
does nothing because the class has no
internal variable. The function tau()
returns 3.3 all the
time.
public class Timer : Atomic { private OutputPort op; public Timer(string name): base(name, TimeUnit.Sec) { op = AddOP("op"); init(); } public override void init(){} public override double tau() { return 3.3; }
Since there is no input transition defined, delta_x
has the
null body except returns false
4.1.
However, delta_y
returns the output op
by making the
output event y
set to op
.
public override bool delta_x(PortValue x) { return false; } public override void delta_y(ref PortValue y) { y.Set(op); }The display function
Get_s()
returns the current status,
which is constantly Working
.
public override string Get_s() { return "Working"; } }
The file Program_Timer.cs
has the main function for a
console application as follows. As we can see, we make an instance
timer
from Timer
class. And then we make an instance
of SRTEngine
. Here, we don't have to pass the third
Callback
function argument because this Timer
example doesn't need the user input. Finally, this codes run the
console menu of SRTEngine
class.
class Program { static void Main(string[] args) { Timer timer = new Timer("STimer"); SRTEngine Engine = new SRTEngine(timer, 10000, null); Engine.RunConsoleMenu(); } }
If you try step
, you can see the animation is increasing the
elapsed time. The following display shows the state at time
2.188 where the schedule time t_s
=3.3 and
the elapsed time t_e
=2.188.
(STimer:Working, t_s=3.300, t_e=2.188) at 2.188The simulation run will stop at 3.3 because its run mode is step-by-step when using
step
. At that time, it will display
the discrete state transition as follows.
(STimer:Working, t_s=3.300, t_e=3.300) --({!STimer.op},t_c=3.3)--> (STimer:Working, t_s=3.300, t_e=0.000)The first state is the source of state transition. An arc shows a triggering event which is the output
op
of STimer
at
the current time=3.3. The second state is the destination of the
state transition in which the lifespan is also 3.3 but the elapsed
time has been reset to zero.
Ex_Timer
.
te
to
tr
by applying the command dtmode
. Then preset the
simulation ending time to ``5'' by pause_at
5. Now
run
until the simulation stops. When it stops at
t_c
=5, print the total state using pinrt
with option
q
. What are the values of t_s
and t_r
,
respectively? Guess the value of t_e
at this moment.
int n
in Timer
class. n
should be set = zero in init()
, and it
should increase by one in delta_y()
. Get_s()
shows
n
in the string format
string.Format("Working, n={0}", n);