ProvidingEquip.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
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
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
{
/// <summary>
/// 流水线自动料仓-出料装置类
/// </summary>
public partial class ProvidingEquip : KTK_Store
{
private bool IsIntSlvBlock = false;
public bool IsDebug = false;
public bool UpdownUseAxis = false;
public AxisAlarmInfo AxisAlarm = new AxisAlarmInfo();
public ProvidingEquip_Config Config;
/// <summary>
///出料装置后面分为两条移动线
/// </summary>
public LineMoveInfo SecondMoveInfo = null;
// public List<InOutParam> waitOutStoreList = new List<InOutParam>();
public List<InOutParam> waitInStoreList = new List<InOutParam>();
public object waitInListLock = "";
// public object waitOutListLock = "";
public ProvidingEquip(string cid, ProvidingEquip_Config config)
{
baseConfig = config;
this.DeviceID = config.Id;
this.Config = config;
Name = (" " + "_出料_" + DeviceID % 10 + " ").ToUpper();
//Name = (" " + cid + "_出料_" + DeviceID + " ").ToUpper();
Init();
//添加调试
if (config.IsDebug == 1)
{
IsDebug = true;
}
//this.Box = box;
MoveInfo = new LineMoveInfo(DeviceID,"出料-"+DeviceID+"-MoveInfo");
SecondMoveInfo = new LineMoveInfo(DeviceID, "出料-" + DeviceID + "-SecondMoveInfo");
IsDebug = config.IsDebug.Equals(1);
UpdownUseAxis = config.UpDownUseAxis.Equals(1);
if (UpdownUseAxis)
{
Config.UpDown_Axis.TargetSpeed = Config.UpdownAxis_TargetSpeed;
Config.UpDown_Axis.AddSpeed = Config.UpdownAxis_AddSpeed;
Config.UpDown_Axis.DelSpeed = Config.UpdownAxis_DelSpeed;
Config.UpDown_Axis.HomeAddSpeed = Config.UpdownAxis_HomeAddSpeed;
Config.UpDown_Axis.HomeHighSpeed = Config.UpdownAxis_HomeHighSpeed;
Config.UpDown_Axis.HomeLowSpeed = Config.UpdownAxis_HomeLowSpeed;
portName = Config.UpDown_Axis.DeviceName;
slvAddr = config.UpDown_Axis.GetAxisValue();
}
}
/// <summary>
/// 开始运行
/// </summary>
public override bool StartRun( )
{
//preTrayNum = 0;
// currMoveTrayNum = 0;
mainTimer.Enabled = false;
MoveInfo.EndMove();
SecondMoveInfo.EndMove();
lineStatus = LineStatus.StoreOnline;
//TODO 调试时暂时注释
runStatus = LineRunStatus.HomeMoving;
return MoveEquipMentHome();
}
public bool StartDebugRun()
{
//preTrayNum = 0;
//currMoveTrayNum = 0;
mainTimer.Enabled = false;
MoveInfo.EndMove();
SecondMoveInfo.EndMove();
lineStatus = LineStatus.StoreOnline;
//TODO 调试时暂时注释
runStatus = LineRunStatus.HomeMoving;
bool result= MoveEquipMentHome();
if (result)
{
mainTimer.Enabled = true;
}
return result;
}
/// <summary>
/// 停止运行
/// </summary>
public override void StopRun()
{
// preTrayNum = 0;
// currMoveTrayNum = 0;
if (mainTimer != null)
{
mainTimer.Enabled = false;
}
StopMove();
//停止运行时,把所有IO 置零
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
IOMove(IO_Type.TopCylinder_UP, IO_VALUE.LOW);
IOMove(IO_Type.TopCylinder_Down, IO_VALUE.LOW);
IOMove(IO_Type.BeforeAfterCylinder_Before, IO_VALUE.LOW);
IOMove(IO_Type.BeforeAfterCylinder_After, IO_VALUE.LOW);
IOMove(IO_Type.UpDownCylinder_Up, IO_VALUE.LOW);
IOMove(IO_Type.UpDownCylinder_Down, IO_VALUE.LOW);
IOMove(IO_Type.ClampCylinder_Slack, IO_VALUE.LOW);
IOMove(IO_Type.ClampCylinder_Tighten, IO_VALUE.LOW);
runStatus = LineRunStatus.Wait;
}
/// <summary>
/// 运动处理
/// </summary>
protected override void BusyMoveProcess()
{
switch (MoveInfo.MoveType)
{
case LineMoveType.InStore:
InStoreProcess();
break;
case LineMoveType.OutStore:
OutStoreProcess();
break;
case LineMoveType.ReturnHome:
ReturnHomeProcess();
break;
case LineMoveType.Reset:
ResetProcess();
break;
//case StoreMoveType.StopMove:
// StopMoveProcess();
// 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)
{
ReturnHomeProcess();
}
else if (MoveInfo.MoveType == LineMoveType.Reset)
{
ResetProcess();
}
else if (MoveInfo.MoveType == LineMoveType.StopMove)
{
StopMoveProcess();
}
if (SecondMoveInfo.MoveType .Equals( LineMoveType.CheckFixture))
{
// CheckFixtureProcess();
}
}
protected override void mainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
TimerProcess();
}
public void TimerProcess()
{
if (isInPro)
{
return;
}
isInPro = true;
try
{
if (IsDebug)
{
isInPro = false;
return;
}
BusyMoveProcess();
//判断流水线打开了才可以运行
if (SecondMoveInfo.MoveType.Equals(LineMoveType.None))
{
LineBean lineBean = LineManager.Line;
if (lineBean.isCanProcessLine() && IOManager.IOValue(IO_Type.DriveMotor_Run,0).Equals(IO_VALUE.HIGH) && lineBean.runStatus >= LineRunStatus.Runing && lineBean.IsSleep.Equals(false))
{
// LogUtil.info("StartCheckFixture");
// StartCheckFixture();
}
}
IOTimeOutProcess();
}
catch (Exception ex)
{
LogUtil.error(Name + "TimerProcess出错:" + ex.ToString());
}
isInPro = false;
}
private DateTime preIoTimerOutTime = DateTime.Now;
private 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.IsInWait .Equals(false)&&SecondMoveInfo.IsInWait.Equals(false))
{
LogUtil.info(Name + "清理信号超时报警【" + WarnMsg + "】 ");
alarmType = LineAlarmType.None;
WarnMsg = "";
}
}
}
catch (Exception ex)
{
LogUtil.error( "IOTimeOutProcess出错:" + ex.ToString());
}
}
/// <summary>
/// 出料装置原点返回
/// </summary>
public bool MoveEquipMentHome()
{
mainTimer.Stop();
if (!RunAxis(true))
{
return false;
}
alarmType = LineAlarmType.None;
runStatus = LineRunStatus.HomeMoving;
LogInfo( "开始原点返回: (上下气缸回原点,阻挡气缸输入=0 )开始");
MoveInfo.NewMove(LineMoveType.ReturnHome);
//移载装置原点状态:顶升气缸下降端,前后气缸后退端,上下气缸上升端,夹料气缸放松端,阻挡气缸输入=0
UpdownHomeMove();
// CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
if (IsDebug)
{
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
}
else
{
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
}
return true;
}
/// <summary>
/// 出料装置重置
/// </summary>
public override bool Reset()
{
WarnMsg = "";
//如果正在出库中,需要减去托盘号
if (MoveInfo.MoveType.Equals(LineMoveType.OutStore))
{
LogInfo("重置之前发现在出库执行中,减去托盘数;");
//减去需要的盘数
TrayManager.DelNeedEmptyTrayNum();
MoveInfo.EndMove();
}
if (!RunAxis(true))
{
return false;
}
alarmType = LineAlarmType.None;
//重置时清理盘号,从头开始判断
// preTrayNum = 0;
// currMoveTrayNum = 0;
LogInfo( "开始重置:清零上一个托盘号,(上下气缸回原点,阻挡气缸输入=0 )开始;");
runStatus = LineRunStatus.Reset;
SecondMoveInfo.EndMove();
MoveInfo.NewMove(LineMoveType.Reset);
UpdownHomeMove();
// CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
if (IsDebug)
{
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
}
else
{
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
}
isInPro = false;
return true;
}
/// <summary>
/// 重置处理
/// </summary>
protected override void ResetProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
else if (SecondMoveInfo.IsInWait)
{
CheckWait(SecondMoveInfo);
}
if (!MoveInfo.IsInWait && !SecondMoveInfo.IsInWait)
{
//流水线各装置复原位,夹料气缸状态不变
//阻挡气缸全部=0
//上下气缸上升,、
//上升到位,顶升气缸下降,前后气缸回退
//复位时夹紧气缸需要发送,不然后面出入库会有问题
switch (MoveInfo.MoveStep)
{
case LineMoveStep.MH_UpDownHomeMove:
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
LogInfo("重置: (上下轴原点返回完成,上下轴走到待机点 )开始");
UpdownUpMove();
break;
case LineMoveStep.MH_UpDownCylinder_Up:
MoveInfo.NextMoveStep(LineMoveStep.MH_OtherCylinder_Back);
LogInfo( "重置: (上升到位,顶升气缸下降,前后气缸回退 )开始");
CylinderMove(MoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
CylinderMove(MoveInfo, IO_Type.ClampCylinder_Slack, IO_Type.ClampCylinder_Tighten);
break;
case LineMoveStep.MH_OtherCylinder_Back:
LogInfo( "重置完成!");
runStatus = LineRunStatus.Runing;
MoveInfo.EndMove();
SecondMoveInfo.EndMove();
break;
//TODO 需要继续之前的的出入库处理
//ContinueInOutStore();
default: break;
}
}
}
/// <summary>
/// 原点返回处理
/// </summary>
protected void ReturnHomeProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
if (SecondMoveInfo.IsInWait)
{
CheckWait(SecondMoveInfo);
}
if (!MoveInfo.IsInWait && !SecondMoveInfo.IsInWait)
{
switch (MoveInfo.MoveStep)
{
case LineMoveStep.MH_UpDownHomeMove:
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
LogInfo("原点返回: (上下轴原点返回完成,上下轴走到待机点 )开始");
UpdownUpMove();
break;
case LineMoveStep.MH_UpDownCylinder_Up:
LogInfo("原点返回:(上升到位,顶升气缸下降,前后气缸回退 )开始");
MoveInfo.NextMoveStep(LineMoveStep.MH_OtherCylinder_Back);
CylinderMove(MoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
CylinderMove(MoveInfo, IO_Type.ClampCylinder_Slack, IO_Type.ClampCylinder_Tighten);
break;
case LineMoveStep.MH_OtherCylinder_Back:
MoveInfo.EndMove();
SecondMoveInfo.EndMove();
LogInfo( "原点返回完成!");
runStatus = LineRunStatus.Runing;
//如果是调试模式,出料装置两个阻挡气缸落下,并且不再移动
if (IsDebug)
{
lineStatus = LineStatus.Debugging;
}
else
{
lineStatus = LineStatus.StoreOnline;
}
break;
default: break;
}
}
}
private void StopMoveProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait(MoveInfo);
}
if (SecondMoveInfo.IsInWait)
{
CheckWait(SecondMoveInfo);
}
if (!MoveInfo.IsInWait && !SecondMoveInfo.IsInWait)
{
switch (MoveInfo.MoveStep)
{
//流水线各装置复原位,夹料气缸状态不变 //阻挡气缸全部=0 //上下气缸上升,、 //上升到位,顶升气缸下降,前后气缸回退
case LineMoveStep.MH_UpDownCylinder_Up:
{
MoveInfo.NextMoveStep(LineMoveStep.MH_OtherCylinder_Back);
LogInfo( "停止运动: (上升到位,顶升气缸下降,前后气缸回退 )开始");
IOMove(IO_Type.UpDownCylinder_Up, IO_VALUE.LOW);
CylinderMove(MoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
break;
}
case LineMoveStep.MH_OtherCylinder_Back:
{
LogInfo("停止运行完成,停止伺服!");
CloseAxis();
if (UpdownUseAxis)
{
LogInfo("停止运动:停止伺服");
ACServerManager.SuddenStop(Config.UpDown_Axis);
}
runStatus = LineRunStatus.Runing;
MoveInfo.EndMove();
break;
}
default: break;
}
}
}
/// <summary>
/// 停止运动
/// </summary>
public override void StopMove()
{
//如果正在出库中,需要减去托盘号
if (MoveInfo.MoveType.Equals(LineMoveType.OutStore))
{
LogInfo( "停止运动时出库执行中,减去托盘数;");
//减去需要的盘数
TrayManager.DelNeedEmptyTrayNum();
MoveInfo.EndMove();
}
runStatus = LineRunStatus.Busy;
SecondMoveInfo.EndMove();
LogInfo( "停止运动:(上下气缸上升端,阻挡气缸输入=0 )开始 ");
MoveInfo.NewMove(LineMoveType.StopMove);
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
UpdownUpMove();
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
}
public void ChangeDebug()
{
if (Config.IsDebug == 1)
{
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 void OpenStopCylinder()
{
LogInfo( "下降阻挡气缸,上下气缸上升,顶升气缸下降");
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
//上下气缸上升
if (UpdownUseAxis.Equals(false))
{
IOMove(IO_Type.UpDownCylinder_Down, IO_VALUE.LOW);
IOMove(IO_Type.UpDownCylinder_Up, IO_VALUE.HIGH);
}
//顶升气缸下降
IOMove(IO_Type.TopCylinder_UP, IO_VALUE.LOW);
IOMove(IO_Type.TopCylinder_Down, IO_VALUE.HIGH);
}
internal void CloseCylinderStop()
{
LogInfo( "上升阻挡气缸,关闭上下气缸,顶升气缸IO");
IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
//上下气缸上升
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);
}
#region 上下气缸伺服运动
private string portName;
private short slvAddr;
public bool RunAxis(bool isCheck)
{
if (!UpdownUseAxis)
{
return true;
}
IOMove(IO_Type.UpDownAxis_ServoOn, IO_VALUE.HIGH);
Thread.Sleep(1000);
//打开所有轴
ACServerManager.OpenPort(portName);
Thread.Sleep(50);
//初始化
if (!IsIntSlvBlock)
{
ACServerManager.InitSlvAddr(portName, slvAddr, Config.UpDown_Axis.TargetSpeed, Config.UpDown_Axis.AddSpeed, Config.UpDown_Axis.DelSpeed);
Thread.Sleep(100);
}
ACServerManager.AlarmClear(portName, slvAddr);
Thread.Sleep(50);
ACServerManager.ServoOn(portName, slvAddr);
Thread.Sleep(1000);
//打开所有轴
if (isCheck)
{
if (!OpenAxis())
{
return false;
}
}
IsIntSlvBlock = true;
IOMove(IO_Type.UpDownAxis_BreakOn, IO_VALUE.HIGH);
return true;
}
/// <summary>
/// 打开所有轴
/// </summary>
/// <returns></returns>
private bool OpenAxis()
{
//判断轴是否正常
if (ACServerManager.ServerOnStatus(portName, slvAddr))
{
LogUtil.info( Name + "成功打开轴:" + Config.UpDown_Axis.Explain);
}
else
{
//清理报警,再重新打开一次
LogUtil.info( Name + "第一次打开轴" + Config.UpDown_Axis.Explain + "失败,先清理一下报警,再重新打开一次");
ACServerManager.AlarmClear(portName, slvAddr);
System.Threading.Thread.Sleep(1200);
ACServerManager.ServoOn(portName, slvAddr);
System.Threading.Thread.Sleep(100);
if (ACServerManager.ServerOnStatus(portName, slvAddr))
{
LogUtil.info( Name + "清理报警后重新打卡轴成功:" + Config.UpDown_Axis.Explain);
}
else
{
ACServerManager.ServoOff(portName, slvAddr);
WarnMsg = Name + "打开轴" + Config.UpDown_Axis.Explain + "失败 ";
LogUtil.info( Name + WarnMsg);
Alarm(LineAlarmType.AxisAlarm, 5.ToString(), WarnMsg, MoveInfo.MoveType);
return false;
}
}
return true;
}
public void CloseAxis()
{
LogUtil.info(Name + "关闭刹车,关闭伺服");
IOMove(IO_Type.UpDownAxis_BreakOn, IO_VALUE.LOW);
ACServerManager.ServoOff(portName, slvAddr);
//关闭串口,等下次重新打开
ACServerManager.ColsePort(portName);
Thread.Sleep(100);
IOMove(IO_Type.UpDownAxis_ServoOn, IO_VALUE.LOW);
}
private void ACAxisHomeMove(ConfigMoveAxis moveAxis)
{
moveAxis.TargetPosition = 0;
LogUtil.info( moveAxis.DisplayStr + "speed[" + moveAxis.TargetSpeed + "]开始原点返回");
MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
}
/// <summary>
/// 松下伺服电机运动
/// </summary>
private void ACAxisMove(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed)
{
MoveInfo.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, targetPosition, targetSpeed));
moveAxis.TargetPosition = targetPosition;
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
}
/// <summary>
/// 判断AC伺服电机轴是否运动完成
/// </summary>
private bool ACAxisMoveIsEnd(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed, out string msg)
{
msg = "";
string deviceName = moveAxis.DeviceName;
short axisNo = moveAxis.GetAxisValue();
bool isOk = ACServerManager.GetBusyStatus(deviceName, axisNo).Equals(0);
int outCount = ACServerManager.GetActualtPosition(deviceName, axisNo);
int errorCount = Math.Abs(outCount - targetPosition);
if (isOk)
{
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
}
//判断是否需要重新运动
if (MoveInfo.CanWhileCount > 0)
{
LogUtil.error( moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount +
"],误差过大,重新开始运动,剩余[" + MoveInfo.CanWhileCount + "]次");
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
MoveInfo.CanWhileCount--;
}
else
{
msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "目标位置[" + targetPosition + "]当前位置[" + outCount
+ "],误差过大,需要报警";
LogUtil.error( msg);
}
}
return false;
}
private bool ACHomeMoveIsEnd(ConfigMoveAxis moveAxis, out string msg)
{
msg = "";
if (ACServerManager.IsHomeMoveEnd(moveAxis.DeviceName, moveAxis.GetAxisValue()))
{
//原点完成并且位置=0
int outCount = ACServerManager.GetActualtPosition(moveAxis.DeviceName, moveAxis.GetAxisValue());
int errorCount = Math.Abs(outCount);
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
}
//判断是否需要重新运动
if (MoveInfo.CanWhileCount > 0)
{
LogUtil.error( moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],重新回原点,剩余[" + MoveInfo.CanWhileCount + "]次");
//LogUtil.error( StoreName + moveAxis.DisplayStr + "重新回原点");
ACServerManager.HomeMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
MoveInfo.CanWhileCount--;
}
else
{
msg = Name + " storeMoveStep=" + MoveInfo.MoveStep + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],误差过大,需要报警";
LogUtil.error( msg);
}
}
return false;
}
/// <summary>
/// 上下气缸移动到上升端
/// </summary>
private void UpdownUpMove()
{
if (UpdownUseAxis)
{
ACAxisMove(Config.UpDown_Axis, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed);
}
else
{
CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
}
}
private void UpdownDownMove(int trayHeight)
{
if (UpdownUseAxis)
{
int position = Config.GetUpdownPosition(trayHeight);
ACAxisMove(Config.UpDown_Axis, position, Config.UpdownAxis_DownSpeed);
}
else
{
CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Up, IO_Type.UpDownCylinder_Down);
}
}
private void UpdownDownBoxMove(int trayHeight)
{
if (UpdownUseAxis)
{
int position = Config.GetUpdownBoxPosition(trayHeight);
ACAxisMove(Config.UpDown_Axis, position,Config.UpdownAxis_DownSpeed);
}
else
{
CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Up, IO_Type.UpDownCylinder_Down);
}
}
private void UpdownHomeMove()
{
if (UpdownUseAxis)
{
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownHomeMove);
ACAxisHomeMove(Config.UpDown_Axis);
}
else
{
MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
}
}
public override void Alarm(LineAlarmType alarmType, string alarmDetial, string alarmMsg, LineMoveType storeMoveType)
{
throw new NotImplementedException();
}
public override bool StartOutStoreMove(InOutParam param)
{
throw new NotImplementedException();
}
protected override void OutStoreProcess()
{
throw new NotImplementedException();
}
public override void StartInStoreMove(InOutParam param)
{
throw new NotImplementedException();
}
protected override void InStoreProcess()
{
throw new NotImplementedException();
}
#endregion
private DateTime preRWTime = DateTime.Now;
private 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(1))
{
string msg = "";
if (wait.IsHomeMove)
{
wait.IsEnd = ACHomeMoveIsEnd(wait.AxisInfo, out msg);
}
else
{
wait.IsEnd = ACAxisMoveIsEnd(wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
}
if (!msg.Equals(""))
{
isOk = false;
WarnMsg = msg;
Alarm(LineAlarmType.AxisMoveError, 5.ToString(), WarnMsg, moveInfo.MoveType);
break;
}
}
else if (wait.WaitType.Equals(2))
{
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 + ",直接跳过检测继续下一步");
}
//夹紧按钮若果超过一秒钟还未收到,默认成功
else if (wait.IoType.Equals(IO_Type.ClampCylinder_Slack) && wait.IoValue.Equals(IO_VALUE.HIGH) && span.TotalMilliseconds > 3000)
{
LogInfo("未检测到:ClampCylinder_Slack=HIGH,超过2秒钟,默认下一步骤");
wait.IsEnd = true;
}
else
{
TimeSpan rwSpan = DateTime.Now - preRWTime;
//一分钟还未检测到
if (span.TotalMilliseconds > LineManager.Config.IOSingle_TimerOut)
{
//把IO重置位0
LogUtil.error(moveInfo.Name + " : " + wait.IoType + "=" + wait.IoValue + " 已等待" + Math.Abs(span.TotalMilliseconds) + ",将DO写0", 17);
ConfigIO io = Config.getWaitIO(wait.IoType);
WarnMsg = Name + "等待信号(" + io.DisplayStr + "=" + wait.IoValue + ") 超时";
Alarm(LineAlarmType.IoSingleTimeOut, io.ElectricalDefinition, WarnMsg, MoveInfo.MoveType);
LogUtil.error(MoveInfo.Name + " : " + wait.IoType + "等待信号(" + io.DisplayStr + "=" + wait.IoValue + ") 超时", 13);
foreach (WaitResultInfo ww in list)
{
if (ww != null && ww.WaitType.Equals(2))
{
if (Config.DOList.ContainsKey(ww.IoType))
{
IOMove(wait.IoType, IO_VALUE.LOW);
}
}
}
}
isOk = false;
break;
}
}
}
else if (wait.WaitType.Equals(3))
{
wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
}
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, 18);
Alarm(LineAlarmType.IoSingleTimeOut, "", WarnMsg, moveInfo.MoveType);
}
}
}
}