VerticalStoreBean.cs
47.3 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
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
using CodeLibrary;
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;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public partial class VerticalStoreBean : DeviceBase
{
private static bool IsIntSlvBlock = false;
public string CID = "";
public VerticalStoreConfig Config;
public bool UseBuzzer = ConfigAppSettings.GetIntValue(Setting_Init.UseBuzzer).Equals(1);
private System.Timers.Timer serverConnectTimer = new System.Timers.Timer();
private System.Timers.Timer IoCheckTimer = new System.Timers.Timer();
public AxisBean MiddleAxis = null;
public VerticalStoreBean(VerticalStoreConfig config)
{
Init();
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;
//添加调试
if (config.IsInDebug == 1)
{
IsDebug = true;
}
Name = ("垂直货柜" + config.Id + " ").ToUpper();
this.StoreID = config.Id;
this.Config = config;
MoveAxisConfig();
List<VerticalPosition> positionList = CSVPositionReader<VerticalPosition>.getPositionList();
PositionNumList = new List<string>();
foreach (VerticalPosition position in positionList)
{
if (position.StoreId.Equals(StoreID))
{
bool result = VerticalPosition.CheckPosition(position, Config);
if (result)
{
PositionNumList.Add(position.PositionNum);
}
}
}
//初始化摄像机配置
IOManager.Init();
IOManager.instance.ConnectionIOList(Config.DIODeviceNameList);
ACServerManager.LogEvent += ACServerManager_LogEvent;
LEDManager.deviceMap.Add(Config.LED_IP, LEDBaseModule.GetModule(Config.LED_IP));
MiddleAxis = new AxisBean(Config.Middle_Axis,"料斗旋转轴");
mainTimer.Enabled = false;
if (ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun).Equals(1))
{
mainTimer.Enabled = true;
}
Thread.Sleep(300);
CloseAllLed();
}
public override bool StartRun()
{
LogUtil.info(Name + "开始启动 ");
autoNext = false;
mainTimer.Enabled = false;
alarmType = StoreAlarmType.None;
if (IOManager.IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.HIGH))
{
if (!MiddleAxis.Open(true, out WarnMsg))
{
return false;
}
runStatus = StoreRunStatus.HomeMoving;
StartReset();
mainTimer.Enabled = true;
IoCheckTimer.Enabled = true;
serverConnectTimer.Enabled = true;
return true;
}
else
{
LogUtil.error(" (" + Name + ")启动出现错误:急停没开 !启动失败!");
return false;
}
}
#region 复位处理
public override void Reset(bool isNeedClearAuto = true)
{
//复位之前先停止运行
if (isNeedClearAuto)
{
autoNext = false;
}
MoveInfo.EndMove();
MiddleAxis.SuddenStop();
runStatus = StoreRunStatus.Reset;
if (!MiddleAxis.Open(true, out WarnMsg))
{
LogUtil.info(Name + "复位时打开轴失败,需要再次复位,直接报警停止复位");
return;
}
mainTimer.Enabled = false;
isInPro = false;
StartReset();
mainTimer.Enabled = true;
}
private void CloseAllLed()
{
IOManager.IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
}
private void StartReset()
{
WarnMsg = "";
isInSuddenDown = false;
CurrInOutCount = 0;
CurrInOutACount = 0;
CloseAllLed();
IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH);
alarmType = StoreAlarmType.None;
storeStatus = StoreStatus.ResetMove;
MoveInfo.NewMove(MoveType.StoreReset);
MoveInfo.NextMoveStep(StoreMoveStep.R01_DoorClose);
LogUtil.info(Name + "开始复位:关闭升降门,关闭所有灯");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
DoorBean.StartClose(MoveInfo);
LEDManager.GetLedModule(Config.LED_IP).AllLightOff();
}
protected override void ResetProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait();
}
if (MoveInfo.IsInWait)
{
return;
}
//switch (MoveInfo.MoveStep)
//{
// case StoreMoveStep.R01_InOutBack:
// Thread.Sleep(200);
// MoveInfo.NextMoveStep(StoreMoveStep.R02_InOutToP1);
// ResetLog("复位: 进出轴回P1,关闭仓门,冷藏门");
// MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
// ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1, Config.InOutAxis_P1_Speed);
// CylinderMove(MoveInfo, IO_Type.Door_Up, IO_Type.Door_Down);
// break;
// case StoreMoveStep.R02_InOutToP1:
// //如果此时轴三还在报警,需要提示错误并等待
// if (ACServerManager.GetAlarmStatus(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue()) > 0)
// {
// WarnMsg = "进出轴报警!复位失败,请检查!";
// LogUtil.error ( "进出轴报警!复位失败,请检查!");
// return;
// }
// MoveInfo.NextMoveStep(StoreMoveStep.R03_OtherAxisBack);
// MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
// ResetLog(" 复位:升降轴,旋转轴,搅拌轴,回温轴,冷藏轴原点返回");
// ACAxisHomeMove(Config.Middle_Axis);
// ACAxisHomeMove(Config.UpDown_Axis);
// ACAxisHomeMove(Config.Stir_Axis);
// ACAxisHomeMove(Config.Warming_Axis);
// ACAxisHomeMove(Config.Colding_Axis);
// break;
// case StoreMoveStep.R03_OtherAxisBack:
// MoveInfo.NextMoveStep(StoreMoveStep.R04_AxisToP1);
// MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
// ResetLog( "复位:旋转轴,升降轴,搅拌轴到待机点");
// ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1, Config.MiddleAxis_P1_Speed);
// ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_OL_P1, Config.UpDownAxis_P1_Speed);
// ACAxisMove(Config.Stir_Axis, Config.Stir_Axis_P1, Config.StirAxis_P1_Speed);
// break;
// case StoreMoveStep.R04_AxisToP1:
// MoveInfo.NextMoveStep(StoreMoveStep.R05_StartWork);
// MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
// ResetLog("复位:启动吹气冷气,冷藏旋转,回温旋转 ");
// StartWork();
// break;
// case StoreMoveStep.R05_StartWork:
// LogUtil.info(Name + "复位完成");
// runStatus = StoreRunStatus.Runing;
// MoveInfo.EndMove();
// storeStatus = StoreStatus.StoreOnline;
// if (alarmType.Equals(StoreAlarmType.None))
// {
// WarnMsg = "";
// }
// break;
// case StoreMoveStep.P01_InOutToP1:
// MoveInfo.NextMoveStep(StoreMoveStep.P02_AxisToP1);
// MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
// ResetLog("复位: 进出轴回P1,关闭仓门,冷藏门");
// ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1, Config.InOutAxis_P1_Speed);
// CylinderMove(MoveInfo, IO_Type.Door_Up, IO_Type.Door_Down);
// break;
// case StoreMoveStep.P02_AxisToP1:
// MoveInfo.NextMoveStep(StoreMoveStep.P03_StartWork);
// MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
// ResetLog("复位:启动吹气冷气,冷藏旋转,回温旋转 ");
// StartWork();
// break;
// case StoreMoveStep.P03_StartWork:
// LogUtil.info( Name + "到待机状态完成");
// MoveInfo.EndMove();
// storeStatus = StoreStatus.StoreOnline;
// runStatus = StoreRunStatus.Runing;
// if (alarmType.Equals(StoreAlarmType.None))
// {
// WarnMsg = "";
// }
// break;
// default: break;
//}
}
internal void MoveAxisConfig()
{
VerticalStoreConfig.ConfigAxis(Config);
moveAxisList = new List<ConfigMoveAxis>();
Config.Middle_Axis.Axis_Brake_DO = IO_Type.Axis_Brake;
Config.Middle_Axis.Axis_Run_DO = IO_Type.Run_Signal;
moveAxisList.Add(Config.Middle_Axis);
this.AxisAlarmCodeMap = new Dictionary<string, AxisAlarmInfo>();
foreach (ConfigMoveAxis axis in moveAxisList)
{
this.AxisAlarmCodeMap.Add(axis.GetNameStr(), new AxisAlarmInfo());
}
}
#endregion
//public bool RunAxis(bool isCheck)
//{
// IOManager.IOMove(IO_Type.Run_Signal, IO_VALUE.HIGH);
// Thread.Sleep(1000);
// //打开所有轴
// foreach (ConfigMoveAxis moveAxis in moveAxisList)
// {
// string portName = moveAxis.DeviceName;
// short slvAddr = moveAxis.GetAxisValue();
// int bro = ConfigAppSettings.GetIntValue(Setting_Init.ACBaudRate);
// ACServerManager.OpenPort(portName,bro);
// Thread.Sleep(50);
// 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;
// IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.HIGH);
// return true;
//}
//private bool OpenAllAxis()
//{
// //判断轴是否正常
// foreach (ConfigMoveAxis axis in moveAxisList)
// {
// if (ACServerManager.ServerOnStatus(axis.DeviceName, axis.GetAxisValue()))
// {
// LogUtil.info( Name + "成功打开轴:" + axis.Explain);
// }
// else
// {
// //清理报警,再重新打开一次
// LogUtil.info( Name + "第一次打开轴" + 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()))
// {
// LogUtil.info( Name + "清理报警后重新打卡轴成功:" + axis.Explain);
// }
// else
// {
// ACServerManager.ServoOff(axis.DeviceName, axis.GetAxisValue());
// WarnMsg = Name + "打开轴" + axis.Explain + "失败 ";
// LogUtil.info( Name + WarnMsg);
// Alarm(StoreAlarmType.AxisAlarm, axis.ProName, WarnMsg, MoveInfo.MoveType);
// return false;
// }
// }
// }
// return true;
//}
//public void CloseAllAxis()
//{
// LogUtil.info(Name + "关闭刹车,关闭伺服");
// IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
// foreach (ConfigMoveAxis axis in moveAxisList)
// {
// ACServerManager.ServoOff(axis.DeviceName, axis.GetAxisValue());
// }
// Thread.Sleep(100);
// IOManager.IOMove(IO_Type.Run_Signal, IO_VALUE.LOW);
//}
public override void StopRun()
{
runStatus = StoreRunStatus.Wait;
autoNext = false;
IoCheckTimer.Enabled = false;
serverConnectTimer.Enabled = false;
mainTimer.Enabled = false;
StopMove(true);
IOManager.instance.CloseAllDO();
LogUtil.info( Name + ",停止运行" );
}
public override void Alarm(StoreAlarmType alarmType, string alarmDetial, string alarmMsg, MoveType storeMoveType)
{
SaveAlarmInfo(alarmType, alarmDetial, alarmMsg, storeMoveType);
autoNext = false;
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 + "轴报警,关闭刹车,停止运动,关闭轴,打开报警灯");
IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
StopMove(true);
}
else if (alarmType == StoreAlarmType.SuddenStop)
{
isInSuddenDown = true;
LogUtil.error ( Name + "收到急停信号,关闭刹车,停止运动,关闭轴,打开报警灯 ");
IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
MoveInfo.EndMove();
StopMove(true);
storeStatus = StoreStatus.SuddenStop;
}
else if (alarmType.Equals(StoreAlarmType.NoAirCheck))
{
LogUtil.error ( Name + " 未检测到气压信号 ,打开刹车,停止运动,关闭轴,打开报警灯 ");
IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
MoveInfo.EndMove();
StopMove(true);
storeStatus = StoreStatus.SuddenStop;
}
}
#region 定时器处理
private bool InProcess = false;
private Stopwatch stopwatch = new Stopwatch();
private IO_VALUE preAirValue = IO_VALUE.HIGH;
private IO_VALUE lastAutoRun = IO_VALUE.LOW;
protected override void timersTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (InProcess && stopwatch.Elapsed.TotalSeconds < 30)
{
return;
}
try
{
InProcess = true;
stopwatch.Restart();
IoCheckProcess();
TimerProcess();
//检查运动轴报警
if (runStatus > StoreRunStatus.Wait && (!isInSuddenDown) )
{
CheckAxisAlarm();
}
}
catch (Exception ex)
{
LogUtil.error(Name + "定时处理出错:" + ex.ToString());
}
InProcess = false;
}
private void IoCheckProcess()
{
DateTime time = DateTime.Now;
if (runStatus.Equals(StoreRunStatus.Wait))
{
//取新的Io状态
IO_VALUE autoSingle = IOManager.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))
{
//没有启动时收到复位按钮,相当于启动按钮
LogUtil.info(Name + "没有启动时收到复位按钮,相当于启动按钮,开始调用启动方法!");
bool result = StartRun();
if (result.Equals(false))
{
LogUtil.error("料仓启动失败,继续等待下次启动!");
mainTimer.Enabled = true;
}
}
lastAutoRun = autoSingle;
return;
}
lastAutoRun = autoSingle;
}
//判断急停
else if (runStatus >= StoreRunStatus.HomeMoving)
{
//取新的Io状态
IO_VALUE suddenBtn = IOManager.IOValue(IO_Type.SuddenStop_BTN);
IO_VALUE resetBtn = IOManager.IOValue(IO_Type.Reset_BTN);
if (resetBtn.Equals(IO_VALUE.HIGH))
{
//收到复位信号,若报警直接复位,若不报警且无操作,回到待机点
if (alarmType.Equals(StoreAlarmType.None) && isInSuddenDown.Equals(false) )
{
if (MoveInfo.MoveType.Equals(MoveType.None))
{
LogUtil.info("收到复位信号但是没有报警,且当前无操作,暂不复位");
}
else
{
LogUtil.info("收到复位信号但是已经在" + MoveInfo.MoveType + "处理中,且无报警,不处理");
}
}
else
{
//判断已经在复位中并且没有报警,不需要重新复位
if (MoveInfo.MoveType.Equals(MoveType.StoreReset) && alarmType.Equals(StoreAlarmType.None))
{
LogUtil.error("收到复位信号:已经在复位中且没有报警,不需要重新复位!");
}
else
{
//收到复位信号
LogUtil.info("收到复位信号,自动复位");
WarnMsg = "收到复位信号,自动复位";
Reset();
}
}
}
}
}
private void IoCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//判断急停
if (runStatus >= StoreRunStatus.HomeMoving)
{
if (IOManager.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, MoveType.None);
}
}
else
{
//光栅处理
SafetyLightProcess();
}
}
}
private void TimerProcess()
{
try
{
DateTime time = DateTime.Now;
if (MoveInfo.MoveType != MoveType.None)
{
BusyMoveProcess();
}
else if (runStatus.Equals(StoreRunStatus.Runing))
{
IOTimeOutProcess();
}
}
catch (Exception ex)
{
LogUtil.error(Name + "定时处理出错" + ex.ToString());
}
}
private DateTime preIoTimerOutTime = DateTime.Now;
private void IOTimeOutProcess()
{
try
{
TimeSpan span = DateTime.Now - preIoTimerOutTime;
if (span.TotalSeconds > 1)
{
preIoTimerOutTime = DateTime.Now;
if (!alarmType.Equals(StoreAlarmType.IoSingleTimeOut))
{
return;
}
if (runStatus < StoreRunStatus.Runing)
{
return;
}
if (isInSuddenDown )
{
return;
}
//若BOX和移栽都没有在等待Io的过程中则此Io超时异常可能已经处理过
if (MoveInfo.IsInWait == false)
{
LogUtil.info(Name + "之前有IO超时异常【" + alarmInfo.alarmDetail + "】,但是当前已经没有在等待中,清理信号超时异常!");
alarmType = StoreAlarmType.None;
WarnMsg = "";
}
}
}
catch (Exception ex)
{
LogUtil.error("IOTimeOutProcess出错:" + ex.ToString());
}
}
private DateTime checkAlarmTime = DateTime.Now;
private bool CheckAxisAlarm()
{
if (alarmType.Equals(StoreAlarmType.AxisAlarm) || alarmType.Equals(StoreAlarmType.AxisMoveError))
{
return true;
}
TimeSpan span = DateTime.Now - checkAlarmTime;
//在回原点,复位,出入库时,检测报警间隔减小
if (runStatus.Equals(StoreRunStatus.Busy) || runStatus.Equals(StoreRunStatus.HomeMoving) || runStatus.Equals(StoreRunStatus.Reset))
{
if (span.TotalSeconds < 1)
{
return false;
}
}
else
{
if (span.TotalSeconds < 3)
{
return false;
}
}
checkAlarmTime = DateTime.Now;
bool isInAlarm = false;
//Task.Factory.StartNew(delegate
// {
foreach (ConfigMoveAxis axisInfo in moveAxisList)
{
short axis = axisInfo.GetAxisValue();
string deviceName = axisInfo.GetNameStr();
AxisAlarmInfo info = AxisAlarmCodeMap[deviceName];
int alarmIo = ACServerManager.GetAlarmStatus(deviceName, axis);
if (alarmIo == 1)
{
WarnMsg = Name + " 运动轴" + axisInfo.Explain + "报警";
info.AlarmIoValue = alarmIo;
Alarm(StoreAlarmType.AxisAlarm, axisInfo.ProName, WarnMsg, MoveType.None);
isInAlarm = true;
}
else
{
if (!info.AlarmIoValue.Equals(alarmIo))
{
LogUtil.error(Name + " 运动轴 " + axisInfo.Explain + ",报警已解除!");
info.AlarmIoValue = alarmIo;
}
}
AxisAlarmCodeMap[deviceName] = info;
}
//});
//判断报警状态
return isInAlarm;
}
#endregion
#region 光栅处理
private object safetyInProcess = "";
private void SafetyLightProcess()
{
if (Monitor.TryEnter(safetyInProcess))
{
try
{
//遮挡光栅信号
if (IOManager.IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.LOW))
{
if (NeedCheckSafetyLight.Equals(1))
{
//if (MoveInfo.MoveType.Equals(MoveType.OutStore) && MoveInfo.IsStep(StoreMoveStep.SO_13_InoutToP2))
//{
// NeedCheckSafetyLight = 2;
// LogUtil.info("出库 " + MoveInfo.MoveStep + " 运动中,光栅被遮挡,停止进出轴运动");
// ACServerManager.SuddenStop(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue());
//}
//else if (MoveInfo.MoveType.Equals(MoveType.InStore) && MoveInfo.IsStep(StoreMoveStep.SI_05_InoutToP2))
//{
// NeedCheckSafetyLight = 2;
// LogUtil.info("入库 "+ MoveInfo.MoveStep + " 运动中,光栅被遮挡,停止进出轴运动");
// ACServerManager.SuddenStop(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue());
//}
}
}
else
{
if (NeedCheckSafetyLight.Equals(2))
{
//if (MoveInfo.MoveType.Equals(MoveType.OutStore) && MoveInfo.IsStep(StoreMoveStep.SO_13_InoutToP2))
//{
// LogUtil.info("出库 " + MoveInfo.MoveStep + " 运动中,光栅已恢复,继续进出轴运动");
// SO_13_InoutToP2();
//}
//else if (MoveInfo.MoveType.Equals(MoveType.InStore) && MoveInfo.IsStep(StoreMoveStep.SI_05_InoutToP2))
//{
// LogUtil.info("入库 " + MoveInfo.MoveStep + " 运动中,光栅已恢复,继续进出轴运动");
// SI_05_InoutToP2();
//}
}
}
}
catch (Exception ex)
{
LogUtil.error("光栅处理出错:" + ex.ToString());
}
finally
{
Monitor.Exit(safetyInProcess);
}
}
}
#endregion
public override void StopMove(bool IsCloseAxis=false)
{
IOManager.IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
MiddleAxis.SuddenStop();
if (IsCloseAxis)
{
MiddleAxis.ServoOff();
}
LogUtil.info( Name + "StopMove");
IOManager.IOMove(IO_Type.Door_Down, IO_VALUE.LOW);
IOManager.IOMove(IO_Type.Door_Up, IO_VALUE.LOW);
isInPro = false;
}
public bool CanStarInOut()
{
if (isInSuddenDown ||
(!runStatus.Equals(StoreRunStatus.Runing))
|| storeStatus.Equals(StoreStatus.InStoreExecute) || storeStatus.Equals(StoreStatus.OutStoreExecute)
|| storeStatus.Equals(StoreStatus.InStoreEnd) || storeStatus.Equals(StoreStatus.OutStoreBoxEnd))
{
return false;
}
return true;
}
#region 与服务器通信定时器
private float Max_Humidity = 0;
private float Max_Temperature = 0;
public string currTempStr = "";
private void HumidityProcess()
{
try
{
ASTemperateParam param = HumitureController.ColdLastData;
currTempStr = "";
if (param != null)
{
currTempStr = ("冷藏区湿度:" + param.Humidity.ToString() + " 温度:" + param.Temperate.ToString() + " \n ");
}
param = HumitureController.WarmLastData;
if (param != null)
{
currTempStr += ("回温区湿度:" + param.Humidity.ToString() + " 温度:" + param.Temperate.ToString() + "\n ");
}
}
catch (Exception ex)
{
LogUtil.error(Name + "HumidityProcess出错:" + ex.ToString());
}
}
private bool isInProcess = false;
public void server_connect_timer_Tick(object sender, EventArgs e)
{
if (isInProcess)
{
return;
}
isInProcess = true;
if (StoreManager.IsConnectServer)
{
try
{
SendLineStatus();
}
catch (Exception ex)
{
LogUtil.error("定时给服务器发送消息出错:" + ex.ToString());
}
}
HumidityProcess();
LedProcess();
isInProcess = false;
}
private Operation getLineBoxStatus()
{
//构建发送给服务器的对象
Operation lineOperation = new Operation();
lineOperation.msg = "";
lineOperation.alarmList = new List<AlarmInfo>();
lineOperation.cid = CID;
lineOperation.seq = ConfigAppSettings.nextSeq();
lineOperation.status = 1;
if (WarnMsg != "")
{
lineOperation.status = (int)StoreStatus.Warning;
lineOperation.msg = WarnMsg;
}
lineOperation.status = (int)StoreStatus.StoreOnline;
BoxStatus boxStatus = new BoxStatus();
boxStatus.boxId = StoreID;
//状态
boxStatus.status = (int)storeStatus;
if (IsDebug)
{
boxStatus.status = (int)StoreStatus.Debugging;
}
boxStatus.msg = WarnMsg;
lineOperation.msg = WarnMsg;
//状态
boxStatus.status = (int)storeStatus;
if (IsDebug)
{
boxStatus.status = (int)StoreStatus.Debugging;
}
else if (storeStatus.Equals(StoreStatus.OutStoreBoxEnd) || storeStatus.Equals(StoreStatus.InStoreEnd))
{
boxStatus.data.Add(ParamDefine.posId, lastPosId);
}
else if (!lastPosId.Equals(""))
{
boxStatus.data.Add(ParamDefine.posId, lastPosId);
boxStatus.status = (int)lastPosIdStatus;
if (lastPosId != "")
{
LogUtil.info( "给服务器发送出入库完成消息:" + Name + ",status【" + lastPosIdStatus + "】posId【" + lastPosId + "】");
}
lastPosId = "";
}
//温湿度
//ASTemperateParam param = HumitureServer.GetTemperateParam(Config.Temperate_Serveraddress);
ASTemperateParam param = HumitureController.ColdLastData;
if (param != null)
{
boxStatus.humidity = param.Humidity.ToString();
boxStatus.temperature = param.Temperate.ToString();
}
lineOperation.boxStatus.Add(StoreID, boxStatus);
if (!alarmType.Equals(StoreAlarmType.None))
{
lineOperation.alarmList.Add(alarmInfo);
}
return lineOperation;
}
private void SendLineStatus()
{
DateTime time = DateTime.Now;
//构建发送给服务器的对象
Operation lineOperation = getLineBoxStatus();
//如果还没湿度范围,先获取
if (Max_Humidity <= 0 || (Max_Temperature <= 0))
{
lineOperation.op = 5;
LogUtil.info( Name + "没有湿度预警范围,需要从服务器获取,发送OP=" + lineOperation.op);
}
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
Operation resultOperation = HttpHelper.Post(StoreManager.GetPostApi(server), lineOperation, false);
//发送状态信息到服务器
if (resultOperation == null || (resultOperation.op <= 0))
{
//判断服务端是否返回出库操作
return;
}
if (resultOperation.op.Equals(1))
{
ReviceInStoreProcess("", resultOperation);
}
else if (resultOperation.op.Equals(2))
{
ReviceOutStoreProcess(resultOperation);
}
else if (resultOperation.op.Equals(5))
{
ProcessHumidityCMD(resultOperation);
}
else
{
LogUtil.error("收到服务器命令:op=" + resultOperation.op + ",未找到对应处理");
}
TimeSpan span = DateTime.Now - time;
if (span.TotalMilliseconds > 10)
{
LogUtil.info(Name + "执行TimerProcess 共处理了【" + span.TotalMilliseconds + "】毫秒");
}
}
private void ProcessHumidityCMD(Operation resultOperation)
{
Dictionary<string, string> data = resultOperation.data;
if (data != null && data.ContainsKey(ParamDefine.maxHumidity) && data.ContainsKey(ParamDefine.maxTemperature))
{
string maxHumidity = data[ParamDefine.maxHumidity];
string maxTemp = data[ParamDefine.maxTemperature];
LogUtil.info( "收到服务器温湿度预警值:maxHumidity=" + maxHumidity + ",maxTemperature=" + maxTemp);
try
{
this.Max_Humidity = (float)Convert.ToDouble(maxHumidity);
this.Max_Temperature = (float)Convert.ToDouble(maxTemp);
LogUtil.info( "保存温湿度预警值:Max_Humidity=" + Max_Humidity + ",Max_Temperature=" + Max_Temperature);
}
catch (Exception ex)
{
LogUtil.error("转换温湿度失败:" + ex.ToString());
}
}
}
private void ReviceOutStoreProcess(Operation resultOperation)
{
DateTime time = DateTime.Now;
Dictionary<string, string> data = resultOperation.data;
if (data != null && data.ContainsKey(ParamDefine.posId)
&& data.ContainsKey(ParamDefine.plateH) && data.ContainsKey(ParamDefine.plateW))
{
string posIdStr = data[ParamDefine.posId];
string plateWStr = data[ParamDefine.plateW];
string plateHStr = data[ParamDefine.plateH];
LogUtil.info("收到服务器出库消息:poaIs=" + posIdStr + ",platew=" + plateWStr + ",plateh=" + plateHStr);
char splitChar = '|';
string[] posIdArray = posIdStr.Split(splitChar);
string[] plateWArray = plateWStr.Split(splitChar);
string[] plateHArray = plateHStr.Split(splitChar);
int index = -1;
foreach (string posId in posIdArray)
{
index++;
int plateW = Convert.ToInt32(plateWArray[index]);
int plateH = Convert.ToInt32(plateHArray[index]);
string[] posArray = posId.Split('#');
if (posArray.Length != 2)
{
WarnMsg = Name + "出库格式错误:库位号【" + posId + "】";
LogUtil.error("收到服务器出库命令:库位号【" + posId + "】格式错误");
continue;
}
int storeId = int.Parse(posArray[0]);
//根据发送的posId获取位置列表
VerticalPosition position = CSVPositionReader<VerticalPosition>.GetPositon(posId);
if (position == null)
{
//出入库没有找到服务器发送的库位,需要打印日志方便查询原因
WarnMsg = Name + "出库未找库位:【" + posId + "】";
LogUtil.error("收到服务器出库命令:未找到【" + posId + "】的库位信息");
continue;
}
else
{
InOutParam currInOutFixture = new InOutParam(MoveType.OutStore, posId, "", plateW, plateH);
//if (CanStarInOut())
//{
// bool result = StartOutStore(currInOutFixture);
// if (!result)
// {
// LogUtil.info(Name + " 执行出库【" + currInOutFixture.ToStr() + "】失败,加入等待队列");
// AddWaitMoveParam(currInOutFixture);
// }
//}
//else
//{
// LogUtil.error("执行出库【" + currInOutFixture.ToStr() + "】失败,当前在忙碌中,加入等待队列");
// AddWaitMoveParam(currInOutFixture);
//}
}
}
TimeSpan span = DateTime.Now - time;
if (span.TotalMilliseconds > 10)
{
LogUtil.info(Name + "执行TimerProcess 共处理了【" + span.TotalMilliseconds + "】毫秒");
}
}
}
private void ReviceInStoreProcess(string message, Operation resultOperation)
{
Dictionary<string, string> data = resultOperation.data;
if (data != null && data.ContainsKey(ParamDefine.posId) && data.ContainsKey(ParamDefine.plateH) && data.ContainsKey(ParamDefine.plateW))
{
//服务器返回时有:posId库位编号,plateW:料盘宽度,plateH:料盘高度,
//postId格式BoxId#位置
string posId = data[ParamDefine.posId];
int plateW = Convert.ToInt32(data[ParamDefine.plateW].Trim());
int plateH = Convert.ToInt32(data[ParamDefine.plateH].Trim());
string[] posArray = posId.Split('#');
if (!(posArray.Length == 2))
{
WarnMsg = Name + "入库库位格式错误:二维码【" + message + "】库位【" + posId + "】";
LogUtil.error("服务器反馈 入库库位格式错误:二维码【" + message + "】库位【" + posId + "】");
return;
}
int storeId = int.Parse(posArray[0]);
//根据发送的posId获取位置列表
VerticalPosition position = CSVPositionReader<VerticalPosition>.GetPositon(posId);
if (position == null)
{
//出入库没有找到服务器发送的库位,需要打印日志方便查询原因
WarnMsg = "入库未找到库位:二维码【" + message + "】库位【" + posId + "】 ";
LogUtil.error("收到服务器入库命令:入库未找到库位:二维码【" + message + "】库位【" + posId + "】");
return;
}
//TODO:判断BOX是否处于可以入库状态,如果调试或急停中,需要返回给服务器;
if (CanStarInOut())
{
InOutParam param = new InOutParam(MoveType.InStore, posId, message, plateH, plateW);
StartInStore(param);
//如果当前正在出入库中,需要记录下来,等待空闲时执行
LogUtil.info(Name + " 收到服务器入库命令:库位号【" + posId + "】二维码【" + message + "】 开始入库!");
}
else
{
LogUtil.info(Name + " 收到服务器入库命令:库位号【" + posId + "】二维码【" + message + "】 正在忙碌中,无法入库!");
}
}
}
private void LedProcess()
{
try
{
// 机器状态 顶灯显示
// 绿 黄 红
//机器复位中 闪 灭 灭
//机器待机中 亮 灭 灭
//机器出入库中 闪 闪 灭
//温湿度超限报警中 亮 闪 灭
//温湿度超限报警中超过30分钟 亮 闪 闪
//机器未启动 灭 灭 灭
//机器设备故障(非温湿度)报警 亮 灭 闪
//报警时只需要亮红灯
DateTime time = DateTime.Now;
bool isNeedAlarmLed = false;
//报警灯
if (!alarmType.Equals(StoreAlarmType.None) )
{
isNeedAlarmLed = true;
}
if (isNeedAlarmLed && IOManager.IOValue(IO_Type.Alarm_HddLed).Equals(IO_VALUE.LOW))
{
IOManager.IOMove(IO_Type.Alarm_HddLed, IO_VALUE.HIGH);
}
else
{
if (IOManager.IOValue(IO_Type.Alarm_HddLed).Equals(IO_VALUE.HIGH))
{
IOManager.IOMove(IO_Type.Alarm_HddLed, IO_VALUE.LOW);
}
}
//报警时绿灯和黄灯灭
if (isNeedAlarmLed)
{
if (IOManager.IOValue(IO_Type.AutoRun_HddLed).Equals(IO_VALUE.HIGH))
{
IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
}
if (IOManager.IOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
{
IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
}
if (UseBuzzer && IOManager.IOValue(IO_Type.Alarm_Buzzer).Equals(IO_VALUE.LOW))
{
IOManager.IOMove(IO_Type.Alarm_Buzzer, IO_VALUE.HIGH);
}
return;
}
if (!UseBuzzer)
{
IOManager.IOMove(IO_Type.Alarm_Buzzer, IO_VALUE.LOW);
}
//绿灯闪
if ((MoveInfo.MoveType.Equals(MoveType.InStore) || MoveInfo.MoveType.Equals(MoveType.OutStore)
|| runStatus.Equals(StoreRunStatus.HomeMoving) || runStatus.Equals(StoreRunStatus.Reset))
&& IOManager.IOValue(IO_Type.AutoRun_HddLed).Equals(IO_VALUE.HIGH))
{
IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.LOW);
}
else
{
//绿灯亮
IOManager.IOMove(IO_Type.AutoRun_HddLed, IO_VALUE.HIGH);
}
//黄灯
if (MoveInfo.MoveType.Equals(MoveType.InStore) || MoveInfo.MoveType.Equals(MoveType.OutStore) )
{
if (IOManager.IOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
{
IOManager.IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
}
else
{
IOManager.IOMove(IO_Type.RunSign_HddLed, IO_VALUE.HIGH);
}
}
else
{
if (IOManager.IOValue(IO_Type.RunSign_HddLed).Equals(IO_VALUE.HIGH))
{
IOManager.IOMove(IO_Type.RunSign_HddLed, IO_VALUE.LOW);
}
}
}
catch (Exception ex)
{
LogUtil.error(Name + "灯处理定时器出错:" + ex.ToString());
}
}
#endregion
private void AxisSuddenStop(ConfigMoveAxis axis)
{
ACServerManager.SuddenStop(axis.DeviceName, axis.GetAxisValue());
}
private static void ACServerManager_LogEvent(InfoType type, string msg)
{
if (type.Equals(InfoType.Error))
{
LogUtil.error(msg);
}
else if (type.Equals(InfoType.Info))
{
LogUtil.info(msg);
}
else
{
LogUtil.debug(msg);
}
}
public void CylinderMove(StoreMoveInfo moveInfo, string IoLowType, string IoHighType)
{
try
{
if (moveInfo != null)
{
moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IoLowType, IO_VALUE.LOW));
moveInfo.WaitList.Add(WaitResultInfo.WaitIO(IoHighType, IO_VALUE.HIGH));
}
IOManager.IOMove(IoLowType, IO_VALUE.LOW);
IOManager.IOMove(IoHighType, IO_VALUE.HIGH);
}
catch (Exception ex)
{
LogUtil.error(Name + "CylinderMove [" + IoLowType + "] [" + IoHighType + "] 出错:" + ex.ToString());
}
}
public virtual string GetMoveStr()
{
string msg = "";
msg += "" + runStatus +" _ "+ storeStatus+ " _ "+ alarmType+"\n";
msg += MoveInfo.MoveType + " _ "+MoveInfo.MoveStep + "\n";
msg += currTempStr;
return msg;
}
}
}