AC_BOX_Bean.cs
35.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
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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
using Asa;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
/// <summary>
/// 流水线自动料仓-Box类
/// </summary>
public partial class AC_BOX_Bean : KTK_Store
{
private TaskData taskData = null;
public EnteryDoorBean DoorBean = null;
private bool IsIntSlvBlock = false;
public AutoInoutInfo AutoInout = new AutoInoutInfo();
public string CID = "";
public AC_BOX_Config Config;
public string lastPosId = "";
public StoreStatus lastPosIdStatus = StoreStatus.StoreOnline;
public List<ConfigMoveAxis> moveAxisList = new List<ConfigMoveAxis>();
/// <summary>
/// 所有料仓库位列表
/// </summary>
public List<string> PositionNumList = new List<string>();
/// <summary>
/// 所有料架库位列表
/// </summary>
public List<string> ShelfPosList = new List<string>();
public HumitureBean humBean = null;
private System.Timers.Timer serverConnectTimer = new System.Timers.Timer();
private System.Timers.Timer IoCheckTimer = new System.Timers.Timer();
/// <summary>
/// 是否有料架在来的路上
/// </summary>
public bool WaitShelfEnter=false;
private int logType = 1000;
public AC_BOX_Bean(AC_BOX_Config config)
{
Init();
baseConfig = config;
CID = config.CID;
serverConnectTimer = new System.Timers.Timer();
serverConnectTimer.Interval = 1000;
serverConnectTimer.AutoReset = true;
serverConnectTimer.Enabled = false;
serverConnectTimer.Elapsed += server_connect_timer_Tick;
IoCheckTimer = new System.Timers.Timer();
IoCheckTimer.Interval = 200;
IoCheckTimer.AutoReset = true;
IoCheckTimer.Enabled = false;
IoCheckTimer.Elapsed += IoCheckTimer_Elapsed;
logType = config.DeviceID * 1000;
//添加调试
IsDebug = config.IsInDebug.Equals(1);
Name = (" BOX_" + config.DeviceID + " ").ToUpper();
this.DeviceID = config.DeviceID;;
this.Config = config;
DoorBean = new EnteryDoorBean(DeviceID);
//温湿度
humBean = new HumitureBean(config.Humiture_Port, Name);
// humBean.Init();
moveAxisList = new List<ConfigMoveAxis>();
MoveAxisConfig();
List<ACBoxPosition> positionList = CSVPositionReader<ACBoxPosition>.getPositionList();
PositionNumList = new List<string>();
foreach (ACBoxPosition position in positionList)
{
if (position.StoreId.Equals(DeviceID) && ACBoxPosition.CheckPosition(position, Config))
{
PositionNumList.Add(position.PositionNum);
}
}
List<ShelfPosition> sPlist = CSVPositionReader<ShelfPosition>.getPositionList();
ShelfPosList = new List<string>();
foreach (ShelfPosition p in sPlist)
{
if (p.StoreId.Equals(DeviceID))
{
ShelfPosList.Add(p.PositionNum);
}
}
mainTimer.Enabled = false;
int isAuto = ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun);
if (isAuto == 1)
{
mainTimer.Enabled = true;
}
}
private void IoCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//判断急停
if (storeRunStatus >= StoreRunStatus.HomeMoving)
{
if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
if (isInSuddenDown.Equals(false))
{
isInSuddenDown = true;
LogUtil.error(Name + "收到急停信号,报警急停");
WarnMsg = Name + "收到急停信号,报警急停";
//报警时会关闭所有轴
Alarm(StoreAlarmType.SuddenStop, "1", WarnMsg, StoreMoveType.None);
}
}
}
}
/// <summary>
/// 配置速度,加减速时间
/// </summary>
public void MoveAxisConfig()
{
AC_BOX_Config.ConfigAxis(Config);
moveAxisList = new List<ConfigMoveAxis>();
moveAxisList.Add(Config.Middle_Axis);
moveAxisList.Add(Config.UpDown_Axis);
moveAxisList.Add(Config.InOut_Axis);
moveAxisList.Add(Config.Comp_Axis);
}
/// <summary>
/// 开始运行
/// </summary>
public override bool StartRun(bool isDebug = false)
{
if (!StoreManager.Store.canStart)
{
WarnMsg = "启动失败:设备未初始化完成";
LogUtil.error(Name + "启动失败:设备未初始化完成");
return false;
}
LogInfo("开始启动,启动时间:" + StartTime.ToString());
AutoInout.StopAuto();
mainTimer.Enabled = false;
alarmType = StoreAlarmType.None;
//急停按钮和气压检测需要一起判断
IO_VALUE suddenBtn = IOValue(IO_Type.SuddenStop_BTN);
IO_VALUE airCheck = IOValue(IO_Type.Airpressure_Check);
if (suddenBtn.Equals(IO_VALUE.HIGH) && (airCheck.Equals(IO_VALUE.HIGH)))
{
//lastAirValue = airCheck;
lastAirCloseTime = DateTime.Now;
if (!RunAxis(true))
{
return false;
}
//TODO 启动时先所有轴远点返回,测试暂时关闭
storeRunStatus = StoreRunStatus.HomeMoving;
storeStatus = StoreStatus.ResetMove;
//启动温湿度服务器
HumitureController.Init(Config.Humiture_Port);
ReturnHome();
StartTime = DateTime.Now;
mainTimer.Enabled = true;
IoCheckTimer.Enabled = true;
serverConnectTimer.Enabled = true;
return true;
}
else
{
if (suddenBtn.Equals(IO_VALUE.LOW))
{
WarnMsg = "启动失败:急停没开";
LogUtil.error(" (" + Name + ")启动失败:急停没开!");
}
else
{
WarnMsg = "启动失败:没有气压信号";
LogUtil.error(" (" + Name + ")启动失败:没有气压信号!");
}
return false;
}
}
public string GetWarnMsg()
{
string msg = WarnMsg;
if (alarmType.Equals(StoreAlarmType.None).Equals(false))
{
msg= LastAlarmTime.ToLongTimeString() + " " + WarnMsg + " ";
}
//if (IOValue(IO_Type.DoorLimit).Equals(IO_VALUE.LOW))
//{
// msg = msg + " 无门禁信号";
//}
if (humBean.TempOrHumidityIsAlarm)
{
msg = msg + " 温湿度报警[" + humBean.TempAlarmTime.ToLongTimeString() + "]";
}
return msg;
}
#region 原点返回和复位处理
private void ReturnHome()
{
CurrShelfID = "";
WaitShelfEnter = false;
lastPosId = "";
lastPosIdStatus = StoreStatus.ResetMove;
AutoInout.ClearCount();
storeRunStatus = StoreRunStatus.HomeMoving;
MoveInfo.NewMove(StoreMoveType.ReturnHome);
InoutStartReset();
}
public void MoveToP1()
{
//压紧轴回原点,叉子回到P1,关闭门旋转轴和升降轴回到P1
MoveInfo.NewMove(StoreMoveType.StoreReset);
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H54_InOutToP1);
LogInfo("到待机状态,进出轴到P1,判断叉子没有料盘");
ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed);
}
public override void Reset(bool isNeedClearAuto = true)
{
AutoInout.ClearCount();
//复位之前先停止运行
if (isNeedClearAuto)
{
AutoInout.StopAuto();
}
storeRunStatus = StoreRunStatus.Reset;
storeStatus = StoreStatus.ResetMove;
MoveInfo.NewMove(StoreMoveType.StoreReset);
if (!RunAxis(true))
{
LogInfo("复位时打开轴失败,需要再次复位,直接报警停止复位");
return;
}
InoutStartReset();
isInPro = false;
}
private void InoutStartReset()
{
//清理报警
WarnMsg = "";
isInSuddenDown = false;
isNoAirCheck = false;
alarmType = StoreAlarmType.None;
DoorBean.Stop();
//开始复位动作
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H01_InOutBack);
LogInfo(MoveInfo.MoveType + ": 开始料架入库,线体停止,进出轴先原点返回,设置agv" + Config.AgvNodeName + "为None");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
LineStop();
ACAxisHomeMove(Config.InOut_Axis);
AgvClient.SetStatus(Config.AgvNodeName,"","",ClientAction.None,ClientLevel.High,true);
}
/// <summary>
/// 复位处理
/// </summary>
protected override void ResetProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait();
}
if (MoveInfo.IsInWait)
{
return;
}
switch (MoveInfo.MoveStep)
{
case StoreMoveStep.BOX_H01_InOutBack:
Thread.Sleep(200);
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H02_TopDown);
LogInfo(MoveInfo.MoveType + ": 线体停止,进出轴到待机点P1,顶升气缸下降,NG门下降,入料移门关闭");
LineStop();
AxisCountClear(Config.InOut_Axis);
ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed);
CylinderMove(MoveInfo, IO_Type.NGDoowCylinder_Up, IO_Type.NGDoorCylinder_Down);
CylinderMove(MoveInfo, IO_Type.TopCylinder_Up, IO_Type.TopCylinder_Down);
DoorBean.StartClose(MoveInfo);
break;
case StoreMoveStep.BOX_H02_TopDown:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H03_LineRun);
if (IOValue(IO_Type.LineTake_Check).Equals(IO_VALUE.HIGH))
{
LogInfo(MoveInfo.MoveType + ":取料工位有料架,线体停止 ");
LineStop();
}
else
{
LogInfo(MoveInfo.MoveType + ":取料工位无料架, 线体先正转3000或等待取料工位有料架");
LineRun();
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000));
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LineTake_Check, IO_VALUE.HIGH));
MoveInfo.OneWaitCanEndStep = true;
}
break;
case StoreMoveStep.BOX_H03_LineRun:
LineStop();
//如果此时轴三还在报警,需要提示错误并等待
if (ACServerManager.GetAlarmStatus(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue()) > 0)
{
LogUtil.error(Name + MoveInfo.MoveType + "复位失败: " + Config.InOut_Axis.Explain + "报警");
WarnMsg = Name + "复位失败: " + Config.InOut_Axis.Explain + "报警";
Alarm(StoreAlarmType.AxisAlarm, GetAlarmCodeByAxis(Config.InOut_Axis).ToString(), WarnMsg, StoreMoveType.None);
return;
}
//复位和回原点要等轴3进出轴ORG亮了以后才能返回其他轴
LogInfo(MoveInfo.MoveType + ": 停止线体, 压紧轴,旋转轴,上下轴开始 原点返回");
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H05_OtherAxisBack);
ACAxisHomeMove(Config.Comp_Axis);
ACAxisHomeMove(Config.Middle_Axis);
ACAxisHomeMove(Config.UpDown_Axis);
break;
case StoreMoveStep.BOX_H05_OtherAxisBack:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H06_MiddleAxisToP1);
LogInfo(MoveInfo.MoveType + ": 旋转轴运动到P1,上下轴走到P1,压紧轴到P1 ");
ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1, Config.MiddleAxis_P1_Speed);
ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_P1, Config.UpDownAxis_P1_Speed);
ACAxisMove(Config.Comp_Axis, Config.CompAxis_P1_Position, Config.CompAxis_P1_Speed);
break;
case StoreMoveStep.BOX_H06_MiddleAxisToP1:
LogInfo(MoveInfo.MoveType + ": 完成");
MoveEndToRuningStatus();
AgvClient.SetCancelState(AgvClient.CurrCancelState);
break;
case StoreMoveStep.BOX_H54_InOutToP1:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H55_CompHome);
LogInfo("到待机状态,压紧轴回原点,关闭舱门");
ACAxisHomeMove(Config.Comp_Axis);
break;
case StoreMoveStep.BOX_H55_CompHome:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H56_OtherAxisToP1);
LogInfo(MoveInfo.MoveType + ": 旋转轴运动到P1,上下轴走到P1,压紧轴到P1 ");
ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1, Config.MiddleAxis_P1_Speed);
ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_P1, Config.UpDownAxis_P1_Speed);
ACAxisMove(Config.Comp_Axis, Config.CompAxis_P1_Position, Config.CompAxis_P1_Speed);
break;
case StoreMoveStep.BOX_H56_OtherAxisToP1:
LogInfo("到待机状态完成");
MoveEndToRuningStatus();
AgvClient.SetCancelState(AgvClient.CurrCancelState);
break;
default: break;
}
}
#endregion
public bool RunAxis(bool isCheck)
{
IOMove(IO_Type.Run_Signal, IO_VALUE.HIGH);
Thread.Sleep(1000);
//打开所有轴
foreach (ConfigMoveAxis moveAxis in moveAxisList)
{
string portName = moveAxis.DeviceName;
short slvAddr = moveAxis.GetAxisValue();
ACServerManager.OpenPort(portName);
Thread.Sleep(50);
//初始化串口
//ACServerManager.InitSlvAddr(portName, slvAddr);
if (!IsIntSlvBlock)
{
ACServerManager.InitSlvAddr(portName, slvAddr, moveAxis.TargetSpeed, moveAxis.AddSpeed, moveAxis.DelSpeed);
Thread.Sleep(100);
}
ACServerManager.AlarmClear(portName, slvAddr);
Thread.Sleep(50);
ACServerManager.ServoOn(portName, slvAddr);
}
Thread.Sleep(1000);
//打开所有轴
if (isCheck)
{
if (!OpenAllAxis())
{
return false;
}
}
IsIntSlvBlock = true;
IOMove(IO_Type.Axis_Brake, IO_VALUE.HIGH);
return true;
}
/// <summary>
/// 打开所有轴
/// </summary>
/// <returns></returns>
private bool OpenAllAxis()
{
//判断轴是否正常
foreach (ConfigMoveAxis axis in moveAxisList)
{
if (ACServerManager.ServerOnStatus(axis.DeviceName, axis.GetAxisValue()))
{
LogInfo("成功打开轴:" + axis.Explain);
}
else
{
//清理报警,再重新打开一次
LogInfo("第一次打开轴" + axis.Explain + "失败,先清理一下报警,再重新打开一次");
ACServerManager.AlarmClear(axis.DeviceName, axis.GetAxisValue());
System.Threading.Thread.Sleep(1200);
ACServerManager.ServoOn(axis.DeviceName, axis.GetAxisValue());
System.Threading.Thread.Sleep(100);
if (ACServerManager.ServerOnStatus(axis.DeviceName, axis.GetAxisValue()))
{
LogInfo("清理报警后重新打卡轴成功:" + axis.Explain);
}
else
{
ACServerManager.ServoOff(axis.DeviceName, axis.GetAxisValue());
int alarmCode = GetAlarmCodeByAxis(axis);
WarnMsg = Name + "打开轴" + axis.Explain + "失败 ";
LogInfo(WarnMsg);
Alarm(StoreAlarmType.AxisAlarm, GetAlarmCodeByAxis(axis).ToString(), WarnMsg, MoveInfo.MoveType);
return false;
}
}
}
return true;
}
public void CloseAllAxis()
{
LogUtil.info(Name + "关闭刹车,关闭伺服");
IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
foreach (ConfigMoveAxis axis in moveAxisList)
{
ACServerManager.ServoOff(axis.DeviceName, axis.GetAxisValue());
}
Thread.Sleep(100);
IOMove(IO_Type.Run_Signal, IO_VALUE.LOW);
}
/// <summary>
/// 停止运行
/// </summary>
public override void StopRun()
{
AgvClient.SetStatus(Config.AgvNodeName);
lastPosId = "";
lastPosIdStatus = StoreStatus.StoreOnline;
WarnMsg = "";
AutoInout.StopAuto();
IoCheckTimer.Enabled = false;
serverConnectTimer.Enabled = false;
StopMove();
storeRunStatus = StoreRunStatus.Wait;
mainTimer.Enabled = false;
TimeSpan span = DateTime.Now - StartTime;
LogInfo(",停止运行,总运行时间:" + span.ToString());
}
public DateTime LastAlarmTime = DateTime.Now;
public override void Alarm(StoreAlarmType alarmType, string alarmDetial, string alarmMsg, StoreMoveType storeMoveType)
{
if (alarmType.Equals(StoreAlarmType.None).Equals(false))
{
LastAlarmTime = DateTime.Now;
}
SaveAlarmInfo(alarmType, alarmDetial, alarmMsg, storeMoveType);
AutoInout.StopAuto();
if (this.alarmType.Equals(alarmType) && alarmType != StoreAlarmType.SuddenStop && alarmType != StoreAlarmType.NoAirCheck)
{
return;
}
LogUtil.error(Name + " 报警,报警类型:" + alarmType);
this.alarmType = alarmType;
if (alarmType.Equals(StoreAlarmType.AxisAlarm) | alarmType.Equals(StoreAlarmType.AxisMoveError))
{
LogUtil.error(Name + "轴报警, 停止运动, 打开报警灯");
StopMove();
}
else if (alarmType == StoreAlarmType.SuddenStop)
{
isInSuddenDown = true;
LogUtil.error(Name + "收到急停信号,停止运动, 打开报警灯 ");
StopMove();
storeStatus = StoreStatus.SuddenStop;
}
else if (alarmType.Equals(StoreAlarmType.NoAirCheck))
{
isNoAirCheck = true;
LogUtil.error(Name + " 未检测到气压信号 ,停止运动, 打开报警灯 ");
StopMove();
storeStatus = StoreStatus.SuddenStop;
}
}
private bool InProcess = false;
//private DateTime preProcessTime = DateTime.Now;
private bool IsChongfu = false;
private Stopwatch stopwatch = new Stopwatch();
protected override void timersTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (InProcess)
{
//TimeSpan span = DateTime.Now - preProcessTime;
if (stopwatch.Elapsed.TotalSeconds < 10)
{
return;
}
else
{
LogUtil.error("主定时器:InProcess已等待" + stopwatch.Elapsed.ToString() + "重新处理");
IsChongfu = true;
}
}
try
{
InProcess = true;
//preProcessTime = DateTime.Now;
stopwatch.Restart();
IoCheckProcess();
ShowTimeLog("IoCheckProcess");
TimerProcess();
ShowTimeLog("TimerProcess");
//检查运动轴报警
if (storeRunStatus > StoreRunStatus.Wait && (!isInSuddenDown) && (!isNoAirCheck))
{
ShowTimeLog("开始检测轴报警");
CheckAxisAlarm();
ShowTimeLog("轴报警检测完成");
}
}
catch (Exception ex)
{
LogUtil.error(Name + "定时处理出错:" + ex.ToString());
}
IsChongfu = false;
InProcess = false;
}
private IO_VALUE preAirValue = IO_VALUE.HIGH;
private void AirCheckProcess()
{
IO_VALUE currAirValue = IOValue(IO_Type.Airpressure_Check);
if (isInSuddenDown)
{
return;
}
if (isNoAirCheck)
{
return;
}
if (currAirValue.Equals(IO_VALUE.LOW))
{
//判断是否持续了3秒
if (preAirValue.Equals(IO_VALUE.LOW))
{
TimeSpan span = DateTime.Now - lastAirCloseTime;
if (span.TotalSeconds > Config.AirCheckSeconds)
{
WarnMsg = "未检测到气压信号";
preAirValue = IO_VALUE.LOW;
LogUtil.info("已持续【" + FormUtil.GetSpanStr(span) + "】未检测到气压信号,报警");
Alarm(StoreAlarmType.NoAirCheck, "2", WarnMsg, StoreMoveType.None);
return;
}
}
else
{
lastAirCloseTime = DateTime.Now;
isNoAirCheck = false;
}
}
else
{
isNoAirCheck = false;
}
preAirValue = currAirValue;
}
private void ShowTimeLog(string info)
{
if (IsChongfu)
{
LogUtil.info( Name+"【" + info + "】 处理完成,耗时:" + stopwatch.Elapsed.ToString());
}
}
private IO_VALUE lastAutoRun = IO_VALUE.LOW;
public void IoCheckProcess()
{
DateTime time = DateTime.Now;
//if (storeRunStatus.Equals(StoreRunStatus.Wait))
//{
// //取新的Io状态
// IO_VALUE autoSingle = IOValue(IO_Type.Reset_BTN);
// if (ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun).Equals(1))
// {
// if (autoSingle.Equals(IO_VALUE.HIGH) && lastAutoRun.Equals(IO_VALUE.LOW))
// {
// //没有启动时收到复位按钮,相当于启动按钮
// LogInfo("没有启动时收到复位按钮,相当于启动按钮,开始调用启动方法!");
// bool result = StartRun();
// if (result.Equals(false))
// {
// LogUtil.error(Name + "料仓启动失败,继续等待下次启动!");
// mainTimer.Enabled = true;
// }
// }
// lastAutoRun = autoSingle;
// return;
// }
// lastAutoRun = autoSingle;
//}
////判断急停
//else
if (storeRunStatus >= StoreRunStatus.HomeMoving)
{
////取新的Io状态
//IO_VALUE suddenBtn = IOValue(IO_Type.SuddenStop_BTN);
//IO_VALUE resetBtn = IOValue(IO_Type.Reset_BTN);
//急停按钮
if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
return;
}
else if (IOValue(IO_Type.Reset_BTN).Equals(IO_VALUE.HIGH))
{
//收到复位信号,若报警直接复位,若不报警且无操作,回到待机点
if (alarmType.Equals(StoreAlarmType.None) && isInSuddenDown.Equals(false) && isNoAirCheck.Equals(false))
{
if (MoveInfo.MoveType.Equals(StoreMoveType.None))
{
LogUtil.info(Name + "收到复位信号,当前无报警,且空闲中,只回到待机点");
MoveToP1();
}
else
{
LogUtil.info(Name + "收到复位信号,当前无报警, 在" + MoveInfo.MoveType + "处理中,不处理复位");
}
}
else
{
//收到复位信号
LogUtil.info("收到复位信号,自动复位");
WarnMsg = "收到复位信号,自动复位";
Reset();
}
}
AirCheckProcess();
}
}
public void TimerProcess()
{
try
{
DateTime time = DateTime.Now;
if (MoveInfo.MoveType != StoreMoveType.None)
{
BusyMoveProcess();
ShowTimeLog("BusyMoveProcess");
}
else if (storeRunStatus.Equals(StoreRunStatus.Runing))
{
ShowTimeLog("判断是否需要出入库");
AutoResetProcess();
ShowTimeLog("AutoResetProcess");
IOTimeOutProcess();
ShowTimeLog("IOTimeOutProcess");
//如果入口有料架需要入库
if (StoreManager.Store.AutoShelfInstore &&
MoveInfo.MoveType.Equals(StoreMoveType.None) &&
(IOValue(IO_Type.LineIn_Check).Equals(IO_VALUE.HIGH) || IOValue(IO_Type.LineTake_Check).Equals(IO_VALUE.HIGH)))
{
LogUtil.info(Name + "AutoShelfInstore=true ,检测到料架,开始料架入库");
StartShelfInStore();
}
if (IsDebug)
{
AgvClient.SetStatus(Config.AgvNodeName);
}
else
{
//判断是否要更新状态为None 顶升下降时才需要needEnter
if (IOValue(IO_Type.LineIn_Check).Equals(IO_VALUE.LOW) && IOValue(IO_Type.LineTake_Check).Equals(IO_VALUE.LOW)
&& IOValue(IO_Type.TopCylinder_Down).Equals(IO_VALUE.HIGH) && IOValue(IO_Type.TopCylinder_Up).Equals(IO_VALUE.LOW))
{
AgvClient.NeedEnter(Config.AgvNodeName);
}
else
{
AgvClient.SetToNone(Config.AgvNodeName);
}
}
}
}
catch (Exception ex)
{
LogUtil.error(Name + "定时处理出错" + ex.ToString());
}
}
private DateTime preIoTimerOutTime = DateTime.Now;
/// <summary>
/// io检测异常
/// </summary>
private void IOTimeOutProcess()
{
try
{
TimeSpan span = DateTime.Now - preIoTimerOutTime;
if (span.TotalSeconds > 1)
{
preIoTimerOutTime = DateTime.Now;
if (!alarmType.Equals(StoreAlarmType.IoSingleTimeOut))
{
return;
}
if (storeRunStatus < StoreRunStatus.Runing || isInSuddenDown || isNoAirCheck)
{
return;
}
//若BOX和移栽都没有在等待Io的过程中则此Io超时异常可能已经处理过
if (MoveInfo.IsInWait == false)
{
LogUtil.info(Name + "之前有IO超时异常【" + alarmInfo.alarmDetail + "】,但是当前已经没有在等待中,清理信号超时异常!");
alarmType = StoreAlarmType.None;
WarnMsg = "";
}
}
}
catch (Exception ex)
{
LogUtil.error(Name + "IOTimeOutProcess出错:" + ex.ToString());
}
}
/// <summary>
/// 超过配置次数时需要复位
/// </summary>
private void AutoResetProcess()
{
try
{
bool noInStore = true;
if (AutoInout.CurrInOutACount >= this.Config.Box_ResetACount && noInStore)
{
if (storeRunStatus < StoreRunStatus.Runing || MoveInfo.MoveType == StoreMoveType.InStore || MoveInfo.MoveType == StoreMoveType.OutStore)
{
// LogInfo("已经累计出入库" + AutoInout.CurrInOutACount + "次,当时当前正在忙碌中暂不复位");
}
else
{
LogInfo("已经累计出入库" + AutoInout.CurrInOutACount + "次,需要复位一下");
Reset();
}
return;
}
else if (waitOutStoreList.Count > 0)
{
InOutParam param = null;
bool result = waitOutStoreList.TryDequeue(out param);
if (result && param != null)
{
LogInfo("执行排队的出库【" + param.ToStr() + "】");
StartExecuctOut(param);
}
}
}
catch (Exception ex)
{
LogUtil.error(Name + "处理出入库排队列表出错:" + ex.ToString());
}
}
/// <summary>
/// 判断是否报警,返回 true表示报警 报警检测2秒钟检测一次
/// </summary>
/// <returns></returns>
private DateTime checkAlarmTime = DateTime.Now;
public bool CheckAxisAlarm()
{
if (alarmType.Equals(StoreAlarmType.AxisAlarm) || alarmType.Equals(StoreAlarmType.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 (ConfigMoveAxis axisInfo in moveAxisList)
{
short axis = axisInfo.GetAxisValue();
string deviceName = axisInfo.GetNameStr();
if (ACServerManager.GetAlarmStatus(deviceName, axis) == 1)
{
WarnMsg = Name + " 运动轴" + axisInfo.Explain + "报警";
Alarm(StoreAlarmType.AxisAlarm, GetAlarmCodeByAxis(axisInfo).ToString(), WarnMsg, StoreMoveType.None);
isInAlarm = true;
}
}
//判断报警状态
return isInAlarm;
}
/// <summary>
/// 停止所有运行
/// </summary>
public override void StopMove()
{
AgvClient.SetStatus(Config.AgvNodeName);
DoorBean.Stop();
IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
MoveInfo.EndMove();
IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
//运动版停止
ACServerManager.SuddenStop(Config.Middle_Axis.DeviceName, Config.Middle_Axis.GetAxisValue());
ACServerManager.SuddenStop(Config.UpDown_Axis.DeviceName, Config.UpDown_Axis.GetAxisValue());
ACServerManager.SuddenStop(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue());
ACServerManager.SuddenStop(Config.Comp_Axis.DeviceName, Config.Comp_Axis.GetAxisValue());
CloseAllAxis();
LogInfo("StopMove");
isInPro = false;
}
private void MoveEndToRuningStatus()
{
MoveInfo.EndMove();
storeRunStatus = StoreRunStatus.Runing;
storeStatus = StoreStatus.StoreOnline;
if (alarmType.Equals(StoreAlarmType.None))
{
WarnMsg = "";
}
}
public void LineRun()
{
IOMove(IO_Type.Line_BackRun, IO_VALUE.LOW);
IOMove(IO_Type.Line_Run, IO_VALUE.HIGH);
}
public void LineBackRun()
{
IOMove(IO_Type.Line_Run, IO_VALUE.LOW);
IOMove(IO_Type.Line_BackRun, IO_VALUE.HIGH);
}
public void LineStop()
{
IOMove(IO_Type.Line_BackRun, IO_VALUE.LOW);
IOMove(IO_Type.Line_Run, IO_VALUE.LOW);
}
public string GetMoveStr()
{
string msg = "";
msg += "状态: " + storeRunStatus + " " + storeStatus + "\n";
// msg += "lineS: " + storeStatus + "\n";
msg += "报警: " + alarmType + "\n";
msg += MoveInfo.MoveType + " " + MoveInfo.SLog + "\n";
// msg += "MoveS: " + MoveInfo.SLog + "\n";
msg += "料架: " + CurrShelfID + " " + LastOutParam.rfid + "\n";
msg += Config.AgvNodeName + ":" + AgvClient.GetAction(Config.AgvNodeName);
return msg;
}
}
}