-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCDoorStatus.cs
179 lines (143 loc) · 5.34 KB
/
CDoorStatus.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace MarsDoorMonitoring
{
class CDoorStatus
{
public int iDoorNumber; // PLC_ID
public int iDoorID; // Door_ID = Button_Tag
public Button LinkedButton;
public System.Drawing.Color BtnColor;
public bool bConnectionError;
public bool bAlarmLogged;
private bool _bDoorOpen;
private bool _bAlarmNotAcknowledged;
private bool _bAlarmNotCleared;
private bool _bIsAlarmActive;
private bool _bOutOfCoverage;
public CDoorStatus()
{
bAlarmLogged = false;
iDoorNumber = 0;
_bDoorOpen = false;
_bAlarmNotAcknowledged=false;
_bAlarmNotCleared = false;
_bIsAlarmActive = false;
_bOutOfCoverage = false;
}
private CTwinCatInterface _TwinCatInterface;
public void SetTwinCatInterface(CTwinCatInterface TCInterface)
{
_TwinCatInterface = TCInterface;
}
public void AcknowledgeAlarm()
{
byte bStatus = _TwinCatInterface.GetByte(".aDoors[" + iDoorNumber.ToString() + "].bStatus");
bStatus = (byte)((int)bStatus & 253); // bStatus[1] = 0
_TwinCatInterface.SetByte(".aDoors[" + iDoorNumber.ToString() + "].bStatus", bStatus);
bConnectionError = _TwinCatInterface.bConnectionError;
bAlarmLogged = false;
}
public void ClearAlarm()
{
this.UpdateDoorStatus();
if (this.IsAlarmClearable())
{
byte bStatus = _TwinCatInterface.GetByte(".aDoors[" + iDoorNumber.ToString() + "].bStatus");
bStatus = (byte)((int)bStatus & 251); // bStatus[2] = 0
_TwinCatInterface.SetByte(".aDoors[" + iDoorNumber.ToString() + "].bStatus", bStatus);
}
bConnectionError = _TwinCatInterface.bConnectionError;
}
public bool IsAlarmClearable()
{
bool bRet = false;
if ((!this._bAlarmNotAcknowledged) && (!this._bDoorOpen)) bRet = true; // if Alarm is Acknowledged and Door is Closed
return bRet;
}
public void UpdateDoorStatus()
{
byte bStatus = _TwinCatInterface.GetByte(".aDoors[" + iDoorNumber.ToString() + "].bStatus");
if ((bStatus & 1) != 0) // bStatus[0] == 1 -> the Door is opened
{
this._bDoorOpen = true;
}
else // door is not opened closed
{
this._bDoorOpen = false;
}
if ((bStatus & 2) != 0) // bStatus[1] == 1 -> Alarm is Not Acknowledged
{
this._bAlarmNotAcknowledged = true;
}
else
{
this._bAlarmNotAcknowledged = false;
}
if ((bStatus & 4) != 0) // bStatus[2] == 1 -> Alarm is Not Cleared
{
this._bAlarmNotCleared = true;
}
else
{
this._bAlarmNotCleared = false;
}
if ((bStatus & 8) != 0) // bStatus[3] == 1 -> Sensor is out of coverage
{
this._bOutOfCoverage = true;
}
else
{
this._bOutOfCoverage = false;
}
if(this._bOutOfCoverage)
{
this._bIsAlarmActive = true;
BtnColor = System.Drawing.Color.Black;
}
else
{
if ((!this._bAlarmNotAcknowledged) && (!this._bAlarmNotCleared)) // Alarm is Acknowledged & Cleared -> Button -> Green
{
this._bIsAlarmActive = false;
BtnColor = System.Drawing.Color.LawnGreen;
}
else
{
this._bIsAlarmActive = true;
if (this._bAlarmNotAcknowledged) // Alarm is Not Acknowledged -> Button -> Red
{
BtnColor = System.Drawing.Color.Red;
}
else // Alarm is Acknowledged -> Button -> Yellow
{
BtnColor = System.Drawing.Color.Yellow;
}
}
}
bConnectionError = _TwinCatInterface.bConnectionError;
}
public bool DoorOpen()
{
return this._bDoorOpen;
}
public bool AlarmActive()
{
return this._bIsAlarmActive;
}
public bool AlarmAcknowledged()
{
return !this._bAlarmNotAcknowledged;
}
public bool AlarmCleared()
{
return !this._bAlarmNotCleared;
}
public bool SensorOutOfCoverage()
{
return this._bOutOfCoverage;
}
}
}