LineBean.cs
33.6 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
894
895
896
using log4net;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary
{
/// <summary>
/// 流水线自动料仓-流水线类
/// </summary>
public partial class LineBean : KTK_Store
{
public bool IsDebug = false;
public bool UseAgvClient = true;
/// <summary>
/// 灯闪烁定时器
/// </summary>
private System.Timers.Timer ledProcessTimer = null;
/// <summary>
/// 分出一个线程,专门处理急停,报警,气压检测,工单信号检测等处理
/// </summary>
private System.Timers.Timer IoCheckTimer = null;
/// <summary>
/// 流水线下所有的移载装置
/// </summary>
public Dictionary<int, MoveEquip> MoveEquipMap { get; set; }
public Dictionary <int,FeedingEquip> FeedingEquipMap { get; set; }
public Dictionary<int, ProvidingEquip> ProvidingEquipMap { get; set; }
public Dictionary<int, DischargeLine> DisLineMap { get; set; }
public Dictionary<int ,EquipBase> AllEquipMap { get; set; }
/// <summary>
/// 流水线配置
/// </summary>
public Line_Config Config { get; set; }
#region 初始化
public List<string> cioList = new List<string>( );
// public List<string> rfidList = new List<string>();
private bool canStart = false;
public LineBean(Line_Config lineConfig, Dictionary<int, MoveEquip_Config> configList, Dictionary<int, FeedingEquip_Config> feedMap,
Dictionary<int, ProvidingEquip_Config> providMap, Dictionary<int, DischargeLine_Config> disLineMap)
{
if (lineConfig.IOSingle_TimerOut <= 0)
{
lineConfig.IOSingle_TimerOut = 5000;
}
Init();
InitTimer();
baseConfig = lineConfig;
this.Config = lineConfig;
this.DeviceID = lineConfig.Id;
SW41_MoveInfo = new LineMoveInfo(DeviceID, "横移轨道-41");
SW23_MoveInfo = new LineMoveInfo(DeviceID, "横移轨道-23");
MoveInfo = new LineMoveInfo(DeviceID, "[流水线-Move] ");
Name = (" 流水线_" + Config.CID + " ").ToUpper();
IsDebug = Config.IsDebug.Equals(1);
AllEquipMap = new Dictionary<int, EquipBase>();
MoveEquipMap = new Dictionary<int, MoveEquip>();
FeedingEquipMap = new Dictionary<int, FeedingEquip>();
ProvidingEquipMap = new Dictionary<int, ProvidingEquip>();
DisLineMap = new Dictionary<int, DischargeLine>();
List<string> ioList = new List<string>();
ioList = new List<string>(DeviceConfig.ProIOIpMap.Values);
AddDeviceName(ioList, Config.IOIPList);
foreach (FeedingEquip_Config config in feedMap.Values)
{
FeedingEquip equip = new FeedingEquip(lineConfig.CID, config);
//增加AGV小车客户端
AgvClient.NodeList.Add(config.AgvInName);
AgvClient.NodeList.Add(config.AgvOutName);
AddDeviceName(ioList, config.IOIPList);
FeedingEquipMap.Add(config.Id, equip);
AllEquipMap.Add(config.Id, equip);
equip.TrayPEndEvent += Equip_TrayPEndEvent;
}
foreach (MoveEquip_Config config in configList.Values)
{
MoveEquip equip = new MoveEquip(lineConfig.CID, config);
AddDeviceName(ioList, config.IOIPList);
MoveEquipMap.Add(config.Id, equip);
AllEquipMap.Add(config.Id, equip);
}
foreach (ProvidingEquip_Config config in providMap.Values)
{
ProvidingEquip equip = new ProvidingEquip(lineConfig.CID, config);
AddDeviceName(ioList, config.IOIPList);
ProvidingEquipMap.Add(config.Id, equip);
AllEquipMap.Add(config.Id, equip);
equip.TrayPEndEvent += Equip_TrayPEndEvent;
}
foreach (DischargeLine_Config config in disLineMap.Values)
{
DischargeLine equip = new DischargeLine(lineConfig.CID, config);
AddDeviceName(ioList, config.IOIPList);
DisLineMap.Add(config.Id, equip);
AllEquipMap.Add(config.Id, equip);
}
IOManager.Init();
//先初始化设备
//初始化摄像机配置
CodeManager.LoadConfig();
cioList = new List<string>(ioList);
string ids = ConfigAppSettings.GetValue(Setting_Init.DebugDeviceId);
// rfidList = new List<string>();
if (IsDebug)
{
try
{
cioList = new List<string>();
string[] testDeviceIdList = ids.Split(',');
foreach (string str in testDeviceIdList)
{
int id = Convert.ToInt32(str);
if (FeedingEquipMap.ContainsKey(id))
{
FeedingEquip feed = FeedingEquipMap[id];
cioList.AddRange(feed.Config.IOIPList);
}
else if (ProvidingEquipMap.ContainsKey(id))
{
ProvidingEquip feed = ProvidingEquipMap[id];
cioList.AddRange(feed.Config.IOIPList);
}
else if (DisLineMap.ContainsKey(id))
{
DischargeLine feed = DisLineMap[id];
cioList.AddRange(feed.Config.IOIPList);
}
else if (MoveEquipMap.ContainsKey(id))
{
MoveEquip equip = MoveEquipMap[id];
cioList.AddRange(equip.Config.IOIPList);
}
else if (id.Equals(0))
{
cioList = new List<string>(ioList);
break;
}
}
}
catch (Exception ex)
{
LogUtil.error(Name + "加载调试设备出错:",ex);
}
}
RFIDManager.Init();
Task.Factory.StartNew(delegate
{
LogUtil.info(Name + "开始连接IO模块 ");
IOManager.instance.ConnectionIOList(cioList);
addLastDI(IO_Type.Airpressure_Check, IOValue(IO_Type.Airpressure_Check));
addLastDI(IO_Type.SuddenStop_BTN, IOValue(IO_Type.SuddenStop_BTN));
addLastDI(IO_Type.Reset_BTN, IOValue(IO_Type.Reset_BTN));
addLastDI(IO_Type.Start_BTN, IOValue(IO_Type.Start_BTN));
mainTimer.Enabled = true;
IoCheckTimer.Enabled = true;
canStart = true;
});
}
private void AddDeviceName(List<string> targetList, List<string> list)
{
foreach (string str in list)
{
if (!targetList.Contains(str))
{
targetList.Add(str);
}
}
}
public void InitTimer()
{
ledProcessTimer = new System.Timers.Timer();
ledProcessTimer.Interval = 1000;
ledProcessTimer.Elapsed += LedProcess;
ledProcessTimer.AutoReset = true;
ledProcessTimer.Enabled = false;
IoCheckTimer = new System.Timers.Timer();
IoCheckTimer.Interval = 200;
IoCheckTimer.Elapsed += IoCheckTimerProcess;
IoCheckTimer.AutoReset = true;
IoCheckTimer.Enabled = false;
}
#endregion
public string CanStart()
{
if (!canStart)
{
return "启动失败:设备未初始化完成";
}
if (MoveEquipMap == null)
{
return "启动失败:未加载到移栽信息";
}
if (IsDebug)
{
return "";
}
if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
return "启动失败:急停未开";
}
else if (IOValue(IO_Type.Airpressure_Check).Equals(IO_VALUE.LOW))
{
return "启动失败:没有气压信号";
}
return "";
}
public override bool StartRun(bool isDebug = false)
{
string result = CanStart();
if (String.IsNullOrEmpty(result).Equals(false))
{
SetWarnMsg(result);
return false;
}
else if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
SetWarnMsg("启动失败:急停未开");
return false;
}
else
{
ledProcessTimer.Enabled = false;
IoCheckTimer.Enabled = false;
mainTimer.Enabled = false;
lineStatus = LineStatus.ResetMove;
runStatus = LineRunStatus.HomeMoving;
StartTime = DateTime.Now;
LogUtil.info(Name + "开始启动,启动时间:" + StartTime.ToString());
// rfidList = new List<string>();
Task.Factory.StartNew(delegate
{
LogUtil.info(Name + "RFIDManager.Open");
RFIDManager.Open();
});
Thread.Sleep(5);
//连接AGV调度
if (!AgvClient.ISConnected())
{
AgvClient.Init();
}
LineServer.StartServer(ConfigAppSettings.GetIntValue(Setting_Init.TCPServerPort));
RHomeOp();
foreach (EquipBase moveEquip in this.AllEquipMap.Values)
{
EquipStartRun(moveEquip);
}
ledProcessTimer.Enabled = true;
IoCheckTimer.Enabled = true;
mainTimer.Enabled = true;
return true;
}
}
private void EquipStartRun(EquipBase moveEquip)
{
if (moveEquip.IsDebug)
{
moveEquip.OpenStopCylinder();
}
else
{
bool result = moveEquip.StartRun();
Thread.Sleep(60);
}
}
private void RHomeOp()
{
// TrayManager.SidesWayStateMap = new System.Collections.Concurrent.ConcurrentDictionary<int, int>() ;
alarmType = LineAlarmType.None;
mainTimer.Enabled = false;
IoCheckTimer.Enabled = false;
isInSuddenDown = false;
isNoAirCheck = false;
TrayManager.TrayErrorMsg = "";
SetWarnMsg("");
MoveInfo.NewMove(LineMoveType.Reset);
MoveInfo.NextMoveStep(LineMoveStep.Wait);
if (TrayManager.ErrorDeviceId > 0)
{
if (MoveEquipMap.ContainsKey(TrayManager.ErrorDeviceId))
{
MoveEquipMap[TrayManager.ErrorDeviceId].preTrayNum = 0;
}
}
TrayManager.ErrorDeviceId = -1;
WriteDrivetMotorRun( IO_VALUE.LOW);
//横移轨道下降
SideWayStop();
CheckAndMove(IO_Type.SW2_StopDown, IO_VALUE.LOW);
CheckAndMove(IO_Type.SW4_StopDown, IO_VALUE.LOW);
//定位下降
CylinderMove(MoveInfo, IO_Type.SW1_LocationCylinder_Up, IO_Type.SW1_LocationCylinder_Down);
CylinderMove(MoveInfo, IO_Type.SW4_LocationCylinder_Up, IO_Type.SW4_LocationCylinder_Down);
CylinderMove(MoveInfo, IO_Type.SW2_LocationCylinder_Up, IO_Type.SW2_LocationCylinder_Down);
CylinderMove(MoveInfo, IO_Type.SW3_LocationCylinder_Up, IO_Type.SW3_LocationCylinder_Down);
//顶升下降
CylinderMove(MoveInfo, IO_Type.SW2_TopCylinder_Up, IO_Type.SW2_TopCylinder_Down);
CylinderMove(MoveInfo, IO_Type.SW3_TopCylinder_Up, IO_Type.SW3_TopCylinder_Down);
CylinderMove(MoveInfo, IO_Type.SW1_TopCylinder_Up, IO_Type.SW1_TopCylinder_Down);
CylinderMove(MoveInfo, IO_Type.SW4_TopCylinder_Up, IO_Type.SW4_TopCylinder_Down);
}
public override bool Reset()
{
mainTimer.Enabled = false;
IoCheckTimer.Enabled = false;
bool isNeedAllReset = false;
if (isInSuddenDown || isNoAirCheck)
{
//TrayManager.LineNeedEmptyTrayNum = 0;
isNeedAllReset = true;
LogUtil.error( Name + "收到复位信号,急停中或没有气压报警中,强制所有设备复位~");
}
else if ((runStatus == LineRunStatus.HomeMoving || runStatus == LineRunStatus.Reset) && NoAlarm())
{
LogUtil.error( Name + "收到复位信号,已经在复位或原点返回中,且当前无报警,不处理复位");
return false;
}
//停止运动
MoveInfo.EndMove();
lineStatus = LineStatus.ResetMove;
runStatus = LineRunStatus.Reset;
//重置通用处理
RHomeOp();
foreach (EquipBase equip in AllEquipMap.Values)
{
EquipReset(equip, isNeedAllReset);
}
IoCheckTimer.Enabled = true;
mainTimer.Enabled = true;
return true;
}
private void EquipReset(EquipBase equip, bool isNeedAllReset)
{
//调试状态不再重置
if (!equip.IsDebug)
{
if (isNeedAllReset || TrayManager.ErrorDeviceId.Equals(equip.DeviceID) || (!NoAlarm()))
{
LogUtil.info(Name + "收到复位信号," + equip.Name + " 需要复位");
equip.Reset();
Thread.Sleep(60);
}
else
{
LogUtil.info(Name + "收到复位信号," + equip.Name + " 正常无报警,不需要复位");
}
}
else
{
LogUtil.info(Name + "收到复位信号," + equip.Name + " 调试中,需要下降阻挡气缸");
equip.OpenStopCylinder();
}
}
public override void StopRun()
{
IoCheckTimer.Enabled = false;
mainTimer.Enabled = false;
ledProcessTimer.Enabled = false;
WriteDrivetMotorRun(IO_VALUE.LOW);
//停止运行时,把阻挡气缸上升
StopMove();
runStatus = LineRunStatus.Wait;
LineServer.StopServer();
LogUtil.info(Name + "RFIDManager.Close");
RFIDManager.Close();
TimeSpan span = DateTime.Now - StartTime;
LogUtil.info( Name + ",停止运行,总运行时间:" + span.ToString());
}
public override void Alarm(LineAlarmType alarmType )
{
if (this.alarmType.Equals(alarmType))
{
return;
}
// SaveAlarmInfo(alarmType, alarmDetial, alarmMsg, storeMoveType);
this.alarmType = alarmType;
if (alarmType == LineAlarmType.SuddenStop)
{
isInSuddenDown = true;
}
else if (alarmType.Equals(LineAlarmType.NoAirCheck))
{
isNoAirCheck = true;
}
if (alarmType == LineAlarmType.SuddenStop || alarmType.Equals(LineAlarmType.NoAirCheck))
{
LogUtil.error(WarnMsg);
StopMove();
}
IOMove(IO_Type.Alarm_HddLed, IO_VALUE.HIGH);
}
public void WriteDrivetMotorRun(IO_VALUE value)
{
IOMove(IO_Type.DriveMotor_Run1, value);
IOMove(IO_Type.DriveMotor_Run2, value);
IOMove(IO_Type.DriveMotor_Run3, value);
IOMove(IO_Type.DriveMotor_Run4, value);
}
#region 灯光处理
private void LedProcess(object sender, ElapsedEventArgs e)
{
try
{
DateTime time = DateTime.Now;
//黄灯
if ( runStatus.Equals(LineRunStatus.HomeMoving) || runStatus.Equals(LineRunStatus.Reset))
{
//开机执行中时黄灯闪烁
if (IsDoValue(IO_Type.RunSign_HddLed, IO_VALUE.HIGH))
{
IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
}
else
{
IOMove(IO_Type.RunSign_HddLed, IO_VALUE.HIGH);
}
}
//休眠状态黄灯常亮
//else if (IsSleep)
//{
// if (IsDoValue(IO_Type.RunSign_HddLed, IO_VALUE.LOW))
// {
// IOMove(IO_Type.RunSign_HddLed, IO_VALUE.HIGH);
// }
//}
//else
//{
if (IsDoValue(IO_Type.RunSign_HddLed, IO_VALUE.HIGH))
{
IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
}
//}
bool isNeedAlarmLed = false;
bool isInOut = false;
if (NoAlarm().Equals(false) || TrayManager.TrayErrorMsg != "")
{
isNeedAlarmLed = true;
}
foreach (MoveEquip moveEquip in MoveEquipMap.Values)
{
if (!moveEquip.NoAlarm())
{
isNeedAlarmLed = true;
}
if (moveEquip.MoveInfo.MoveType.Equals(LineMoveType.InStore) || moveEquip.MoveInfo.MoveType.Equals(LineMoveType.OutStore))
{
isInOut = true;
}
}
//忙碌中,判断是否有移栽在出入库执行,绿灯闪烁
if (isInOut)
{
if (IsDoValue(IO_Type.AutoRun_HddLed, IO_VALUE.LOW))
{
IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH);
}
else
{
IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
}
}
else if (IsDoValue(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH))
{
IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
}
//报警中 ,红灯闪烁
if (isNeedAlarmLed)
{
if (IsDoValue(IO_Type.Alarm_HddLed, IO_VALUE.LOW))
{
IOMove(IO_Type.Alarm_HddLed, IO_VALUE.HIGH);
}
else
{
IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
}
}
else if (IsDoValue(IO_Type.Alarm_HddLed, IO_VALUE.HIGH))
{
IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
}
}
catch (Exception ex)
{
LogUtil.error(Name + "灯处理定时器出错:",ex);
}
Thread.Sleep(5);
}
#endregion
private void IoCheckTimerProcess(object sender, ElapsedEventArgs e)
{
try
{
DateTime time = DateTime.Now;
if (this.runStatus >= LineRunStatus.HomeMoving)
{
//取新的Io状态
IO_VALUE fuweiValue = IOValue(IO_Type.Reset_BTN);
IO_VALUE suddenBtn = IOValue(IO_Type.SuddenStop_BTN);
IO_VALUE airCheck = IOValue(IO_Type.Airpressure_Check);
IO_VALUE lastAir = DILastValueMap[IO_Type.Airpressure_Check];
IO_VALUE lastFuwei = DILastValueMap[IO_Type.Reset_BTN];
addLastDI(IO_Type.Airpressure_Check, airCheck);
addLastDI(IO_Type.SuddenStop_BTN, suddenBtn);
addLastDI(IO_Type.Reset_BTN, fuweiValue);
//气压检测按钮灭三秒以上才算关闭
IO_VALUE airValue = CheckAir(airCheck, lastAir);
//急停按钮和气压检测按钮需要一起使用
if (suddenBtn.Equals(IO_VALUE.LOW))
{
SetWarnMsg("收到急停信号,报警急停");
Alarm(LineAlarmType.SuddenStop);
}
if (fuweiValue.Equals(IO_VALUE.HIGH) && (!fuweiValue.Equals(lastFuwei)))
{
if (suddenBtn.Equals(IO_VALUE.LOW))
{
SetWarnMsg("收到复位信号但急停未开,不处理复位");
}
else if (airValue.Equals(IO_VALUE.LOW))
{
SetWarnMsg("收到复位信号但未检测到气压信号,不处理复位");
}
else
{
LogUtil.info(Name + "收到复位信号,开始复位!");
Reset();
}
}
}
}
catch (Exception ex)
{
LogUtil.error(Name + "定时检测报警出错:", ex);
}
Thread.Sleep(1);
}
/// <summary>
/// 定时处理,监听信号,监听IO
/// </summary>
protected override void mainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
DateTime time = DateTime.Now;
if (runStatus.Equals(LineRunStatus.Wait))
{
//取新的Io状态
IO_VALUE fuweiValue = IOValue(IO_Type.Start_BTN);
IO_VALUE lastFuwei = DILastValueMap[IO_Type.Start_BTN];
addLastDI(IO_Type.Start_BTN, fuweiValue);
bool isAutoStart = ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun) == 1;
//收到复位信号后启动
if (isAutoStart && fuweiValue.Equals(IO_VALUE.HIGH) && lastFuwei.Equals(IO_VALUE.LOW))
{
//没有启动时收到复位按钮,相当于启动按钮
LogUtil.info( Name + "没有启动时收到复位按钮,相当于启动按钮,开始调用启动方法!");
bool isOk = StartRun();
if (!isOk)
{
LogUtil.error("启动失败,等待下次启动");
mainTimer.Enabled = true;
}
}
return;
}
//判断急停
else if (this.runStatus >= LineRunStatus.HomeMoving)
{
foreach (EquipBase moveEquip in this.AllEquipMap.Values)
{
if (!moveEquip.IsDebug)
{
moveEquip.TimerProcess();
}
}
LineTimerPro();
}
TimeSpan span = DateTime.Now - time;
if (span.TotalMilliseconds > 1000)
{
LogUtil.error(Name + "主定时器处理耗时:" + FormUtil.GetSpanStr(span));
}
}
catch (Exception ex)
{
LogUtil.error(Name + "主定时器出错:",ex);
}
Thread.Sleep(1);
}
private bool busyPro = false ;
private DateTime busyProTime = DateTime.Now;
private void LineTimerPro()
{
TimeSpan span = DateTime.Now - busyProTime;
if (busyPro && span.TotalSeconds < 3)
{
return;
}
try
{
busyPro = true;
busyProTime = DateTime.Now;
switch (runStatus)
{
case LineRunStatus.Busy:
BusyMoveProcess();
break;
case LineRunStatus.HomeMoving:
ResetProcess();
break;
case LineRunStatus.Reset:
ResetProcess();
break;
case LineRunStatus.Runing:
if ((isInSuddenDown.Equals(false) && isNoAirCheck.Equals(false)))
{
//清理超时异常
IOTimeOutProcess();
}
break;
default: break;
}
SideWayTimerProcess();
}
catch (Exception ex)
{
LogUtil.error(Name + "LineTimerPro 出错:", ex);
}
busyPro = false;
}
/// <summary>
/// 气压检测处理
/// </summary>
private IO_VALUE CheckAir(IO_VALUE airCheck, IO_VALUE lastAir)
{
IO_VALUE airValue = IO_VALUE.HIGH;
if (airCheck == IO_VALUE.LOW && (!isInSuddenDown))
{
//判断是否持续了3秒
if (lastAir == IO_VALUE.LOW)
{
if ((DateTime.Now - lastAirCloseTime).TotalSeconds > Config.AirCheckSeconds)
{
SetWarnMsg("持续"+Config.AirCheckSeconds+"秒未检测到气压信号");
//SendAlarmCode(0, LineAlarm.NoAirCheck);
airValue = IO_VALUE.LOW;
Alarm(LineAlarmType.NoAirCheck );
}
}
else
{
lastAirCloseTime = DateTime.Now;
isNoAirCheck = false;
}
}
else
{
isNoAirCheck = false;
}
return airValue;
}
#region 是否已经接收到过出库信息
/// <summary>
///是否已经接收到过出库信息
///</summary>
public bool IsReviceInPosId(MoveEquip moveEquip, string posId)
{
bool isReviceInfo = false;
if (moveEquip.MoveInfo.MoveType.Equals(LineMoveType.InStore) && moveEquip.MoveInfo.MoveParam != null && moveEquip.MoveInfo.MoveParam.PosId.Equals(posId))
{
LogInfo(" IsReviceInPosId 正在入库中:" + MoveInfo.MoveParam.ToStr());
isReviceInfo = true;
}
if (!isReviceInfo && moveEquip.waitInStoreList.Count > 0)
{
foreach (InOutParam inout in moveEquip.waitInStoreList)
{
if (inout.PosId.Equals(posId) && (!inout.WareCode.Equals("")))
{
LogInfo(" IsReviceInPosId 已存在入库任务:" + inout.ToStr());
isReviceInfo = true;
break;
}
}
}
return isReviceInfo;
}
#endregion
internal override void StopMove()
{
foreach (EquipBase equip in this.AllEquipMap.Values)
{
if (!equip.IsDebug)
{
equip.StopRun();
}
else
{
equip.CloseCylinderStop();
}
}
MoveInfo.EndMove();
WriteDrivetMotorRun(IO_VALUE.LOW);
IOMove(IO_Type.SW4_MotorRun, IO_VALUE.LOW);
IOMove(IO_Type.SW4_TopCylinder_Down, IO_VALUE.LOW);
IOMove(IO_Type.SW4_TopCylinder_Up, IO_VALUE.LOW);
SideWayStop();
}
protected override void ResetProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
if (!MoveInfo.IsInWait)
{
bool isOk = true;
string msg = "";
//判断是否所有的已经返回完成
TimeSpan span = DateTime.Now - MoveInfo.LastSetpTime;
foreach (EquipBase moveEquip in this.AllEquipMap.Values)
{
if (moveEquip.IsDebug)
{
if (!moveEquip.OpenStopCylinderOk(span))
{
msg = moveEquip.Name + "下降阻挡气缸";
TimeSpan rwSpan = DateTime.Now - preRWTime;
if (span.TotalSeconds > LineManager.Config.IOSingle_TimerOut * 2)
{
SetWarnMsg(moveEquip.Name + "下降阻挡气缸超时,已等待" + FormUtil.GetSpanStr(span));
LogUtil.error(moveEquip.Name + "下降阻挡气缸超时,已等待" + FormUtil.GetSpanStr(span), 112);
}
else if (rwSpan.TotalSeconds > 5 && span.TotalSeconds > 6 && span.TotalSeconds < LineManager.Config.IOSingle_TimerOut * 2)
{
preRWTime = DateTime.Now;
LogUtil.error(Name + "复位中:等待" + msg + "已【" + FormUtil.GetSpanStr(span) + "】重新调用OpenStopCylinder方法");
moveEquip.OpenStopCylinder();
}
isOk = false;
break;
}
continue;
}
if (moveEquip.runStatus.Equals(LineRunStatus.HomeMoving) || moveEquip.runStatus.Equals(LineRunStatus.Reset) || moveEquip.runStatus.Equals(LineRunStatus.Wait))
{
if (moveEquip.NoAlarm())
{
if (moveEquip.baseConfig.DType.Equals(DeviceType.FeedingEquip) && moveEquip.MoveInfo.MoveStep >= LineMoveStep.FR_11_BatchAxisHome)
{
continue;
}
msg = moveEquip.Name + "复位结束";
isOk = false;
break;
}
else
{
//SetWarnMsg(moveEquip.Name + "在复位过程中报警,需要重新复位");
LogUtil.error(Name + " " + moveEquip.Name + "在复位过程中报警,需要重新复位,调用 moveEquip.Reset();");
moveEquip.Reset();
//如果小于80秒,继续等待
if (span.TotalSeconds < 70)
{
isOk = false;
break;
}
}
}
}
if (isOk)
{
if (WarnMsg.Contains("下降阻挡气缸超时"))
{
SetWarnMsg("");
}
// PreIsHasProcess = false;
//打开流水线
WriteDrivetMotorRun(IO_VALUE.HIGH);
//所有原点重置完成
runStatus = LineRunStatus.Runing;
lineStatus = LineStatus.StoreOnline;
MoveInfo.EndMove();
LogUtil.info(Name + "所有移栽模块复位完成,打开流水线,开始运转,耗时 [" + FormUtil.GetSpanStr(span) + "]");
}
else if (span.TotalSeconds > 120)
{
WarnMsg = Name + "[" + MoveInfo.MoveStep + "][" + msg + "]已等待[" + Math.Round(span.TotalSeconds, 1) + "]秒";
LogUtil.error(WarnMsg, 100);
Alarm(LineAlarmType.IoSingleTimeOut);
}
}
}
public string GetMoveStr()
{
string msg = "";
// int tLength = 20;
msg += "横移41托盘: " + Sw41TrayNum + "\n";
msg += "横移23托盘:" + Sw23TrayNum + "\n";
msg += "runS: "+ runStatus + "\n";
msg += "lineS: "+ lineStatus + "\n";
msg += "alarm: " + alarmType + "\n";
msg += "Move:" + MoveInfo.MoveType + " " + MoveInfo.SLog + "\n";
msg += "SW41: "+ SW41_MoveInfo.MoveType + " "+ SW41_MoveInfo.MoveStep + "\n";
msg += "SW23: " + SW23_MoveInfo.MoveType + " " + SW23_MoveInfo.MoveStep + "\n";
return msg;
}
}
}