Write(", compare to {0}", previous);
if (Math.Abs(data - previous) < tol) {
previous = data;
sensor = Sensor.OK;
}
else sensor = Sensor.Error; // retain old previous
Console.WriteLine(", {0}", sensor);
}
catch {
sensor = Sensor.Error;
Console.WriteLine(", Error");
}
CancelTimer(); // cancel MessageTimeout
StartTimer(PollingInterval); // wait for next time to poll
waitfor = WaitFor.Timeout;
}
bool ReportLostMessageEnabled()
{
return (cevent == ControlEvent.Timeout && waitfor == WaitFor.Message
&& sensor == Sensor.OK);
}
void ReportLostMessage()
{
Console.WriteLine(" ReportLostMessage");
// sensor = Sensor.Error; NOT! Doesn??™t change sensor
StartTimer(PollingInterval); // wait for next time to poll
waitfor = WaitFor.Timeout;
}
void PollSensor() {}
void ResetSensor() {}
void CancelTimer() { timer.Enabled = false; }
void StartTimer(int interval) {
timer.Interval = interval; timer.Enabled = true;
}
}
}
Figure 3.4. Process controller class with dispatcher and handlers (3).
38 Why We Need Model-Based Analysis
namespace ReactiveImpl
{
using System;
using System.Drawing;
using System.Windows.Forms;
public class Simulator: Form
{
Controller c;
Button btnMessageOK, btnMessageBad, btnCommand, btnExit;
public Simulator()
{
// Controller
c = new Controller();
c.timer.Interval = Controller.PollingInterval;
c.timer.Enabled = true;
c.
Pages:
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75