timer.Tick += new EventHandler(timer_Tick);
1 The Controller class does use the .NET Timer class from System.Windows.Forms.
Overview 35
namespace ReactiveImpl
{
using System;
public enum ControlEvent { Timeout, Message, Command, Exit }
public enum WaitFor { Timeout, Message }
public enum Sensor { OK, Error }
public class Controller
{
public const int MessageTimeout = 3000; // msec, plenty of time
public const int PollingInterval = 3000; // msec
ControlEvent cevent;
WaitFor waitfor = WaitFor.Timeout; // enable Reset
Sensor sensor = Sensor.Error; // enable Reset
string buffer;
double previous = Double.MaxValue; // missing value flag
public System.Windows.Forms.Timer timer =
new System.Windows.Forms.Timer();
public void ReceiveEvent(ControlEvent cevent, string buffer)
{
bool msgevent = (cevent == ControlEvent.Message);
Console.WriteLine("?{0}{1}, {2}, {3}",
cevent, msgevent ? " ??™"+buffer+"??™" : "",
waitfor, sensor);
this.cevent = cevent;
if (msgevent) this.buffer = buffer; // else ignore buffer arg.
}
public void DispatchHandler()
{
if (ResetEnabled()) Reset();
else if (PollEnabled()) Poll();
else if (CheckMessageEnabled()) CheckMessage();
else if (ReportLostMessageEnabled()) ReportLostMessage();
else if (CalibrateEnabled()) Calibrate();
}
// to be continued ...
Figure 3.2. Process controller class with dispatcher and handlers (1).
Pages:
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73