EquipBase.cs
19.9 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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public abstract class EquipBase : KTK_Store
{
public bool IsDebug = false;
public bool UseAxis = false;
public ConcurrentQueue<InOutParam> waitOutStoreList = new ConcurrentQueue<InOutParam>();
public List<InOutParam> waitInStoreList = new List<InOutParam>();
internal object waitInListLock = "";
/// <summary>
///移栽装置后面分为两条移动线
/// </summary>
public LineMoveInfo SecondMoveInfo = null;
private int trayCount = 0;
/// <summary>
/// 上一个盘号
/// </summary>
internal int preTrayNum = 0;
/// <summary>
/// 当前正在通过的托盘号
/// </summary>
internal int currTrayNum = 0;
/// <summary>
/// 升降轴
/// </summary>
public AxisBean UpdownAxis = null;
public delegate void TrayProcessEnd(int swNum, int trayNum);
protected virtual void StopMoveProcess()
{
}
protected abstract void BaseTimerProcess();
protected abstract void CheckFixtureProcess();
protected override void mainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
TimerProcess();
}
public override void Alarm(LineAlarmType alarmType)
{
if (this.alarmType.Equals(alarmType))
{
return;
}
if (alarmType.Equals(LineAlarmType.SuddenStop))
{
isInSuddenDown = true;
}
else if (alarmType.Equals(LineAlarmType.NoAirCheck))
{
isNoAirCheck = true;
}
this.alarmType = alarmType;
if (alarmType.Equals(LineAlarmType.SuddenStop) || alarmType.Equals(LineAlarmType.NoAirCheck))
{
StopMove();
}
}
public bool MoveStop = false;
/// <summary>
/// 运动处理
/// </summary>
protected override void BusyMoveProcess()
{
if (MoveStop)
{
return;
}
switch (MoveInfo.MoveType)
{
case LineMoveType.InStore:
InStoreProcess();
break;
case LineMoveType.OutStore:
OutStoreProcess();
break;
case LineMoveType.ReturnHome:
ResetProcess();
break;
case LineMoveType.Reset:
ResetProcess();
break;
default: break;
}
if (MoveInfo.MoveType == LineMoveType.InStore || this.SecondMoveInfo.MoveType == LineMoveType.InStore)
{
InStoreProcess();
}
else if (MoveInfo.MoveType == LineMoveType.OutStore || SecondMoveInfo.MoveType == LineMoveType.OutStore)
{
OutStoreProcess();
}
else if (MoveInfo.MoveType == LineMoveType.ReturnHome)
{
ResetProcess();
}
else if (MoveInfo.MoveType == LineMoveType.Reset)
{
ResetProcess();
}
else if (MoveInfo.MoveType == LineMoveType.StopMove)
{
StopMoveProcess();
}
if (SecondMoveInfo.MoveType.Equals(LineMoveType.CheckFixture))
{
CheckFixtureProcess();
}
}
private DateTime lastProTimer = DateTime.Now;
protected int TimerMaxSeconds = 1;
public void TimerProcess()
{
TimeSpan span = DateTime.Now - lastProTimer;
if (isInPro && span.TotalSeconds < TimerMaxSeconds)
{
return;
}
isInPro = true;
lastProTimer = DateTime.Now;
try
{
if (IsDebug&&runStatus<=LineRunStatus.Wait)
{
isInPro = false;
return;
}
BaseTimerProcess();
}
catch (Exception ex)
{
LogUtil.error(Name + "TimerProcess出错:" + ex.ToString());
}
isInPro = false;
}
protected DateTime preIoTimerOutTime = DateTime.Now;
protected void IOTimeOutProcess()
{
try
{
TimeSpan span = DateTime.Now - preIoTimerOutTime;
if (span.TotalSeconds > 1 && alarmType.Equals(LineAlarmType.IoSingleTimeOut))
{
preIoTimerOutTime = DateTime.Now;
if (runStatus < LineRunStatus.Runing || isInSuddenDown || isNoAirCheck)
{
return;
}
//若BOX和出料都没有在等待Io的过程中则此Io超时异常可能已经处理过
if (MoveInfo.MoveType.Equals(LineMoveType.None)&& SecondMoveInfo.MoveType.Equals(LineMoveType.None)&& MoveInfo.IsInWait.Equals(false) && SecondMoveInfo.IsInWait.Equals(false))
{
LogUtil.info(Name + "清理信号超时报警【" + WarnMsg + "】 ");
alarmType = LineAlarmType.None;
SetWarnMsg("");
}
}
}
catch (Exception ex)
{
LogUtil.error("IOTimeOutProcess出错:" + ex.ToString());
}
}
protected bool CanStartRun()
{
string canResult = LineManager.Line.CanStart();
if (String.IsNullOrEmpty(canResult).Equals(false))
{
SetWarnMsg(canResult);
return false;
}
return true;
}
protected void ResetClearData()
{
trayCount = 0;
SetWarnMsg("");
alarmType = LineAlarmType.None;
preTrayNum = 0;
currTrayNum = 0;
}
public void ChangeDebug(bool isDebug)
{
if (baseConfig.DType.Equals(DeviceType.MoveEquip) || baseConfig.DType.Equals(DeviceType.ProvidingEquip))
{
if (isDebug)
{
IsDebug = true;
//两个阻挡气缸下降
lineStatus = LineStatus.Debugging;
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
LogInfo("从正常状态切换到调试状态!");
}
else if (lineStatus.Equals(LineStatus.Debugging))
{
IsDebug = false;
lineStatus = LineStatus.StoreOnline;
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
LogInfo("从调试状态切换到正常状态!");
}
}
}
/// <summary>
/// 下降所有阻挡气缸
/// </summary>
internal virtual void OpenStopCylinder()
{
if (baseConfig.DType.Equals(DeviceType.MoveEquip) || baseConfig.DType.Equals(DeviceType.ProvidingEquip))
{
LogInfo("OpenStopCylinder: 下降阻挡气缸,上下气缸上升,顶升气缸下降");
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
//上下气缸上升
if (!UseAxis)
{
CylinderMove(null, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
}
//顶升气缸下降
CylinderMove(null, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
Thread.Sleep(30);
}
}
internal virtual void CloseCylinderStop()
{
if (baseConfig.DType.Equals(DeviceType.MoveEquip) || baseConfig.DType.Equals(DeviceType.ProvidingEquip))
{
LogInfo("CloseCylinderStop: 上升阻挡气缸,关闭上下气缸,顶升气缸IO");
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
//上下气缸上升
if (!UseAxis)
{
IOMove(IO_Type.UpDownCylinder_Down, IO_VALUE.LOW);
IOMove(IO_Type.UpDownCylinder_Up, IO_VALUE.LOW);
}
//顶升气缸下降
IOMove(IO_Type.TopCylinder_UP, IO_VALUE.LOW);
IOMove(IO_Type.TopCylinder_Down, IO_VALUE.LOW);
Thread.Sleep(30);
}
}
internal bool UpdateTrayNum()
{
trayCount++;
//此处先对托盘号进行验证
preTrayNum = currTrayNum;
currTrayNum = RFIDManager.GetTrayNum(DeviceID, true);
LogInfo("编号" + trayCount + "***************上个托盘[" + preTrayNum + "]当前托盘[" + currTrayNum + "]");
return true;
}
#region 伺服运动
public bool RunAxis(bool isCheck, AxisBean axis)
{
if (!UseAxis)
{
return true;
}
IOMove(axis.Config.ServerOnDO, IO_VALUE.HIGH);
string msg = "";
bool result = axis.Open(isCheck, out msg);
if (result && String.IsNullOrEmpty(msg))
{
IOMove(axis.Config.BreakOnDO, IO_VALUE.HIGH);
return true;
}
WarnMsg = Name + msg;
Alarm(LineAlarmType.AxisAlarm);
return false;
}
public void CloseAxis(AxisBean axis)
{
LogUtil.info(Name + "关闭刹车,关闭伺服");
IOMove(axis.Config.BreakOnDO, IO_VALUE.LOW);
axis.ServoOff();
Thread.Sleep(100);
IOMove(axis.Config.ServerOnDO, IO_VALUE.LOW);
}
#endregion
#region CheckWait处理
protected DateTime preRWTime = DateTime.Now;
internal void CheckWait(LineMoveInfo moveInfo)
{
List<WaitResultInfo> list = moveInfo.WaitList;
if (list.Count <= 0)
{
moveInfo.EndStepWait();
return;
}
//当等待超过一分钟时,需要打印提示
TimeSpan span = DateTime.Now - moveInfo.LastSetpTime;
string NotOkMsg = "";
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 = Name + msg;
Alarm(LineAlarmType.AxisMoveError);
LogUtil.error(WarnMsg, DeviceID + 18);
break;
}
}
else if (wait.WaitType.Equals(WaitEnum.W002_IOValue))
{
NotOkMsg = " (" + baseConfig.GetDisplayName(wait.IoType) + "=" + wait.IoValue + ") ";
wait.IsEnd = IOValue(wait.IoType).Equals(wait.IoValue);
if (!wait.IsEnd)
{
////屏蔽料盘检测信号
//if (wait.IoType.Equals(IO_Type.TrayCheck) && wait.IoValue.Equals(IO_VALUE.HIGH) && LineManager.Config.IsUse_Tray_Check.Equals(0))
//{
// LogUtil.debug(moveInfo.Name + "未检测到:IsUse_Tray_Check= " + wait.IoValue + ",直接跳过检测继续下一步");
//}
//夹紧按钮若果超过一秒钟还未收到,默认成功
if (wait.IoType.Equals(IO_Type.ClampCylinder_Slack) && wait.IoValue.Equals(IO_VALUE.HIGH) && span.TotalMilliseconds > 6000)
{
LogInfo("未检测到:ClampCylinder_Slack=HIGH,超过6秒钟,默认下一步骤");
wait.IsEnd = true;
}
else if (wait.IoType.Equals(IO_Type.SL_MoveCylinder_Tighten) && wait.IoValue.Equals(IO_VALUE.HIGH) && span.TotalMilliseconds > 6000)
{
LogInfo("未检测到:SL_MoveCylinder_Tighten=HIGH,超过6秒钟,默认下一步骤");
wait.IsEnd = true;
}
else
{
TimeSpan rwSpan = DateTime.Now - preRWTime;
//一分钟还未检测到
if (span.TotalMilliseconds > LineManager.Config.IOSingle_TimerOut&&NoAlarm())
{
ConfigIO io = baseConfig.getWaitIO(wait.IoType);
WarnMsg = Name + "等待" + NotOkMsg + " 超时";
Alarm(LineAlarmType.IoSingleTimeOut);
LogUtil.error(MoveInfo.Name + WarnMsg, DeviceID + 13);
}
else if (rwSpan.TotalSeconds > 5 && span.TotalSeconds > 6)
{
preRWTime = DateTime.Now;
string msg = moveInfo.Name + " " + NotOkMsg + "已等待 " + Math.Abs(span.TotalSeconds) + "秒,重写DO:";
bool isLog = false;
foreach (WaitResultInfo ww in list)
{
if (ww != null && ww.WaitType.Equals(2) && baseConfig.DOList.ContainsKey(ww.IoType))
{
isLog = true;
IOMove(ww.IoType, ww.IoValue);
msg += ww.ToStr() + ",";
}
}
if (isLog)
{
LogUtil.error(msg);
}
}
isOk = false;
break;
}
}
}
else if (wait.WaitType.Equals(WaitEnum.W003_Time))
{
wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
}
else if (wait.WaitType.Equals(WaitEnum.W008_InStoreCheckOK))
{
string posId = moveInfo.MoveParam.PosId;
int id = moveInfo.MoveParam.GetStoreId();
wait.IsEnd = LineServer.RightInPosId(id, posId);
}
else if (wait.WaitType.Equals(WaitEnum.W009_BoxCanInstore))
{
int storeId = moveInfo.MoveParam.GetStoreId();
wait.IsEnd = LineServer.BoxCanReviceTray(storeId);
}
else
{
wait.IsEnd = CheckWaitResult(moveInfo, wait);
}
//else if (wait.WaitType.Equals(10))
//{
// wait.IsEnd = LineManager.Line.SideWay34HasTray().Equals(false);
//}
if (wait.IsEnd && moveInfo.OneWaitCanEndStep)
{
isOk = true;
break;
}
else if (!moveInfo.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
if (isOk)
{
moveInfo.EndStepWait();
}
else if (span.TotalSeconds > moveInfo.TimeOutSeconds )
{
WarnMsg = moveInfo.Name + "[" + moveInfo.MoveType + "][" + moveInfo.MoveStep + "]等待[" + NotOkMsg
+ "]超时[" + Math.Round(span.TotalSeconds, 1) + "]秒";
LogUtil.error(WarnMsg, DeviceID + 15);
Alarm(LineAlarmType.IoSingleTimeOut);
}
}
protected virtual bool CheckWaitResult(LineMoveInfo moveInfo, WaitResultInfo wait)
{
return false;
}
#endregion
protected void CheckLog(string msg)
{
LogUtil.debug(Name + msg);
}
protected void InLog(string msg)
{
string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosId : "";
if (String.IsNullOrEmpty( posId))
{
LogUtil.info(Name + " " + msg);
}
else
{
LogUtil.info(Name + " " + "[" + posId + "]" + msg);
}
}
protected void OutLog(string msg)
{
string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosId : "";
if (String.IsNullOrEmpty(posId))
{
LogUtil.info(Name +" "+ msg);
}
else
{
LogUtil.info(Name + " " + "[" + posId + "] " + msg);
}
}
protected void SInLog(string msg)
{
string posId = SecondMoveInfo.MoveParam != null ? SecondMoveInfo.MoveParam.PosId : "";
if (String.IsNullOrEmpty(posId))
{
LogUtil.info(Name + " " + msg);
}
else
{
LogUtil.info(Name + " " + "[" + posId + "]" + msg);
}
}
protected void SOutLog(string msg)
{
string posId = SecondMoveInfo.MoveParam != null ? SecondMoveInfo.MoveParam.PosId : "";
if (String.IsNullOrEmpty(posId))
{
LogUtil.info(Name + " " + msg);
}
else
{
LogUtil.info(Name + " " + "[" + posId + "] " + msg);
}
}
public virtual string GetMoveStr()
{
string msg = "";
int tLength = 15;
msg += "preTrayNum:".PadRight(tLength, ' ') + preTrayNum + "\n";
msg += "currTrayNum:".PadRight(tLength, ' ') + currTrayNum + "\n";
msg += "runStatus:".PadRight(tLength, ' ') + runStatus + "\n";
msg += "lineStatus:".PadRight(tLength, ' ') + lineStatus + "\n";
msg += "MoveType:".PadRight(tLength, ' ') + MoveInfo.MoveType+"\n";
msg += "MoveStep:".PadRight(tLength, ' ') + MoveInfo.SLog + "\n";
msg += "SMoveType:".PadRight(tLength, ' ') + SecondMoveInfo.MoveType + "\n";
msg += "SMoveStep:".PadRight(tLength, ' ') + SecondMoveInfo.MoveStep + "";
return msg;
}
}
}