EquipBase.cs
10.5 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
using DeviceLib;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public abstract class EquipBase : KTK_Store
{
internal int logType = 1000;
public DateTime LastAlarmTime = DateTime.Now;
public override void Alarm(AlarmType alarmType, string alarmDetial = "", string alarmMsg = "", MoveType storeMoveType = MoveType.None)
{
if (alarmType.Equals(AlarmType.None).Equals(false))
{
LastAlarmTime = DateTime.Now;
}
SaveAlarmInfo(alarmType, alarmDetial, alarmMsg, storeMoveType);
if (this.alarmType.Equals(alarmType) && alarmType != AlarmType.SuddenStop && alarmType != AlarmType.NoAirCheck)
{
return;
}
LogUtil.error(Name + " 报警,报警类型:" + alarmType);
this.alarmType = alarmType;
if (alarmType.Equals(AlarmType.AxisAlarm) | alarmType.Equals(AlarmType.AxisMoveError))
{
LogUtil.error(Name + "轴报警, 停止运动, 打开报警灯");
StopMove();
}
else if (alarmType == AlarmType.SuddenStop)
{
isInSuddenDown = true;
LogUtil.error(Name + "收到急停信号,停止运动, 打开报警灯 ");
StopMove();
storeStatus = StoreStatus.SuddenStop;
}
else if (alarmType.Equals(AlarmType.NoAirCheck))
{
isNoAirCheck = true;
LogUtil.error(Name + " 未检测到气压信号 ,停止运动, 打开报警灯 ");
StopMove();
storeStatus = StoreStatus.SuddenStop;
}
}
private bool InProcess = false;
private bool IsChongfu = false;
private Stopwatch stopwatch = new Stopwatch();
protected override void timersTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (InProcess)
{
if (stopwatch.Elapsed.TotalSeconds < 10)
{
return;
}
else
{
LogUtil.error("主定时器:InProcess已等待" + stopwatch.Elapsed.ToString() + "重新处理");
IsChongfu = true;
}
}
try
{
InProcess = true;
stopwatch.Restart();
TimerProcess();
ShowTimeLog("TimerProcess");
}
catch (Exception ex)
{
LogUtil.error(Name + "定时处理出错:" + ex.ToString());
}
IsChongfu = false;
InProcess = false;
}
internal virtual void TimerProcess()
{
}
internal void ShowTimeLog(string info)
{
if (IsChongfu)
{
LogUtil.info(Name + "【" + info + "】 处理完成,耗时:" + stopwatch.Elapsed.ToString());
}
}
internal DateTime preIoTimerOutTime = DateTime.Now;
internal void IOTimeOutProcess()
{
try
{
TimeSpan span = DateTime.Now - preIoTimerOutTime;
if (span.TotalSeconds > 1)
{
preIoTimerOutTime = DateTime.Now;
if (!alarmType.Equals(AlarmType.IoSingleTimeOut))
{
return;
}
if (storeRunStatus < StoreRunStatus.Runing || isInSuddenDown || isNoAirCheck)
{
return;
}
//若BOX和移栽都没有在等待Io的过程中则此Io超时异常可能已经处理过
if (MoveInfo.IsInWait == false)
{
LogUtil.info(Name + "之前有IO超时异常【" + alarmInfo.alarmDetail + "】,但是当前已经没有在等待中,清理信号超时异常!");
alarmType = AlarmType.None;
WarnMsg = "";
}
}
}
catch (Exception ex)
{
LogUtil.error(Name + "IOTimeOutProcess出错:" + ex.ToString());
}
}
/// <summary>
/// 判断是否报警,返回 true表示报警 报警检测2秒钟检测一次
/// </summary>
/// <returns></returns>
internal DateTime checkAlarmTime = DateTime.Now;
internal bool CheckAxisAlarm(AxisBean[] axisList)
{
if (alarmType.Equals(AlarmType.AxisAlarm) || alarmType.Equals(AlarmType.AxisMoveError))
{
return true;
}
TimeSpan span = DateTime.Now - checkAlarmTime;
//在回原点,复位,出入库时,检测报警间隔减小
if ((storeRunStatus.Equals(StoreRunStatus.Runing) && span.TotalSeconds < 3) || span.TotalSeconds < 1)
{
return false;
}
checkAlarmTime = DateTime.Now;
bool isInAlarm = false;
foreach (AxisBean axisInfo in axisList)
{
short axis = axisInfo.Config.GetAxisValue();
string deviceName = axisInfo.Config.GetNameStr();
if (ACServerManager.GetAlarmStatus(deviceName, axis) == 1)
{
WarnMsg = Name + " 运动轴" + axisInfo.Config.Explain + "报警";
Alarm(AlarmType.AxisAlarm, GetAlarmCodeByAxis(axisInfo.Config).ToString(), WarnMsg, MoveType.None);
isInAlarm = true;
}
}
//判断报警状态
return isInAlarm;
}
internal bool IsDoValue(string ioType, IO_VALUE ioValue)
{
return IOValue(ioType).Equals(ioValue);
}
internal void MoveEndP()
{
MoveInfo.EndMove();
storeRunStatus = StoreRunStatus.Runing;
storeStatus = StoreStatus.StoreOnline;
if (alarmType.Equals(AlarmType.None))
{
WarnMsg = "";
}
}
#region 出入库结果验证
internal void CheckWait()
{
List<WaitResultInfo> list = MoveInfo.WaitList;
//当等待超过一分钟时,需要打印提示
TimeSpan span = DateTime.Now - MoveInfo.LastSetpTime;
string NotOkMsg = "";
if (list.Count <= 0)
{
MoveInfo.EndStepWait();
return;
}
bool isOk = true;
if (MoveInfo.OneWaitCanEndStep)
{
isOk = false;
}
foreach (WaitResultInfo wait in list)
{
if (wait.IsEnd)
{
continue;
}
NotOkMsg = wait.ToStr();
if (wait.WaitType.Equals(WaitEnum.W001_AxisMove))
{
string msg = "";
if (wait.IsHomeMove)
{
wait.IsEnd = AxisBean.HomeMoveIsEnd(MoveInfo, wait.AxisInfo, out msg);
}
else
{
wait.IsEnd = AxisBean.ACAxisMoveIsEnd(MoveInfo, wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
}
if (!msg.Equals(""))
{
isOk = false;
WarnMsg = msg;
Alarm(AlarmType.AxisMoveError, GetAlarmCodeByAxis(wait.AxisInfo).ToString(), WarnMsg, MoveInfo.MoveType);
break;
}
}
else if (wait.WaitType.Equals(WaitEnum.W002_IOValue))
{
wait.IsEnd = IOValue(wait.IoType).Equals(wait.IoValue);
int timeOutMs = StoreManager.Config.IOSingle_TimerOut;
if ((!wait.IsEnd) && span.TotalMilliseconds > timeOutMs && NoAlarm())
{
ConfigIO io = baseConfig.getWaitIO(wait.IoType);
WarnMsg = Name + "[" + MoveInfo.MoveType + "][" + MoveInfo.MoveStep + "] 等待(" + io.DisplayStr + "=" + wait.IoValue + ") 超时";
Alarm(AlarmType.IoSingleTimeOut, io.ElectricalDefinition, WarnMsg, MoveInfo.MoveType);
LogUtil.error(Name + "[" + MoveInfo.MoveType + "][" + MoveInfo.MoveStep + "] 等待(" + io.DisplayStr + "=" + wait.IoValue + ") 超时", logType + 14);
if (!MoveInfo.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
}
else if (wait.WaitType.Equals(WaitEnum.W003_Time))
{
wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
}
if (wait.IsEnd)
{
if (MoveInfo.OneWaitCanEndStep)
{
isOk = true;
break;
}
}
else
{
if (!MoveInfo.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
}
if (isOk)
{
MoveInfo.EndStepWait();
}
else if (span.TotalSeconds > MoveInfo.TimeOutSeconds)
{
WarnMsg = Name + "[" + MoveInfo.MoveType + "][" + MoveInfo.MoveStep + "]等待" + NotOkMsg
+ "超时[" + Math.Round(span.TotalSeconds, 1) + "]秒";
int second = 10;
second = (int)(MoveInfo.TimeOutSeconds / span.TotalSeconds) * 10;
if (second > 120)
{
second = 120;
}
else if (second < 10)
{
second = 10;
}
LogUtil.error(WarnMsg, logType + 100, second);
Alarm(AlarmType.IoSingleTimeOut, "", WarnMsg, MoveInfo.MoveType);
}
}
#endregion
}
}