BoxBean.cs
54.2 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
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
using log4net.Repository.Hierarchy;
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 BoxBean : KTK_Store
{
public static bool IsRun = false;
public string CID = "";
public BoxConfig Config;
public string lastPosId = "";
public StoreStatus lastPosIdStatus = StoreStatus.StoreOnline;
public List<ConfigMoveAxis> moveAxisList = new List<ConfigMoveAxis>();
private Dictionary<string, AxisAlarmInfo> AxisAlarmCodeMap = new Dictionary<string, AxisAlarmInfo>();
private bool UseCompress_Axis = true;
public HumitureBean humBean = null;
public LineConnect lineConnect = null;
private System.Timers.Timer serverConnectTimer = new System.Timers.Timer();
private System.Timers.Timer IoCheckTimer = new System.Timers.Timer();
private System.Timers.Timer readDITimer = new System.Timers.Timer();
public BoxBean(BoxConfig 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 = 300;
IoCheckTimer.AutoReset = true;
IoCheckTimer.Enabled = false;
IoCheckTimer.Elapsed += IoCheckTimer_Elapsed;
readDITimer = new System.Timers.Timer();
readDITimer.Interval = 20;
readDITimer.AutoReset = true;
readDITimer.Enabled = false;
readDITimer.Elapsed += ReadDITimer_Elapsed;
this.DeviceID = config.DeviceID;
this.baseConfig = config;
this.Config = config;
this.CID = config.CID;
//添加调试
IsDebug = config.ISDebug.Equals(1);
UseCompress_Axis = true;
Name = ("左侧BOX_" + config.GetStoreId() + " ").ToUpper();
if (config.DeviceID.Equals(2))
{
Name = ("右侧BOX_" + config.GetStoreId() + " ").ToUpper();
}
moveAxisList = new List<ConfigMoveAxis>();
MoveAxisConfig();
List<ACStorePosition> positionList = CSVPositionReader<ACStorePosition>.getPositionList();
PositionNumList = new List<string>();
foreach (ACStorePosition position in positionList)
{
bool result = ACStorePosition.CheckPosition(position, Config);
if (result && position.StoreId.Equals(config.GetStoreId()))
{
PositionNumList.Add(position.PositionNum);
}
}
humBean = new HumitureBean(config.Humiture_Port, Name);
lineConnect = new LineConnect(config.GetStoreId(),config.CID);
mainTimer.Enabled = false;
}
public void MoveAxisConfig()
{
moveAxisList = new List<ConfigMoveAxis>();
moveAxisList.Add(Config.Middle_Axis);
moveAxisList.Add(Config.UpDown_Axis);
moveAxisList.Add(Config.InOut_Axis);
this.AxisAlarmCodeMap = new Dictionary<string, AxisAlarmInfo>();
this.AxisAlarmCodeMap.Add(Config.UpDown_Axis.GetNameStr(), new AxisAlarmInfo());
this.AxisAlarmCodeMap.Add(Config.InOut_Axis.GetNameStr(), new AxisAlarmInfo());
this.AxisAlarmCodeMap.Add(this.Config.Middle_Axis.GetNameStr(), new AxisAlarmInfo());
moveAxisList.Add(Config.Comp_Axis);
this.AxisAlarmCodeMap.Add(this.Config.Comp_Axis.GetNameStr(), new AxisAlarmInfo());
}
public override bool StartRun()
{
autoNext = false;
mainTimer.Enabled = false;
alarmType = StoreAlarmType.None;
//急停按钮和气压检测需要一起判断
IO_VALUE suddenBtn = IOValue(IO_Type.SuddenStop_BTN);
IO_VALUE airCheck = IOValue(IO_Type.Airpressure_Check);
airCheck = IO_VALUE.HIGH;
if (suddenBtn.Equals(IO_VALUE.HIGH) && (airCheck.Equals(IO_VALUE.HIGH)))
{
lastAirCloseTime = DateTime.Now;
if (!OpenAllAxis(true))
{
return false;
}
LogUtil.info(Name + "开始启动,启动时间:" + StartTime.ToString());
//TODO 启动时先所有轴远点返回,测试暂时关闭
storeRunStatus = StoreRunStatus.HomeMoving;
storeStatus = StoreStatus.ResetMove;
//启动温湿度服务器
HumitureController.Init(Config.Humiture_Port);
lineConnect.StartConnect();
ReturnHome();
StartTime = DateTime.Now;
InProcess = false;
mainTimer.Enabled = true;
IoCheckTimer.Enabled = true;
serverConnectTimer.Enabled = true;
IsRun = true;
return true;
}
else
{
if (suddenBtn.Equals(IO_VALUE.LOW))
{
SetWarnMsg("启动失败:急停未开");
LogUtil.error(" (" + Name + ")启动出现错误:急停没开 !启动失败!");
}
else
{
SetWarnMsg("启动失败:没有气压信号");
LogUtil.error(" (" + Name + ")启动出现错误:没有气压信号 !启动失败!");
}
return false;
}
}
#region 原点返回和复位处理
private void ReturnHome()
{
isNoAirCheck = false;
isInSuddenDown = false;
WarnMsg = "";
CurrInOutACount = 0;
CurrInOutCount = 0;
storeRunStatus = StoreRunStatus.HomeMoving;
MoveInfo.NewMove(StoreMoveType.ReturnHome);
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutBack);
ACAxisHomeMove(Config.InOut_Axis);
LogUtil.info(Name + "开始原点返回,先把进出轴回原点");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
}
public void MoveToP1()
{
//压紧轴回原点,叉子回到P1,关闭门旋转轴和升降轴回到P1
MoveInfo.NewMove(StoreMoveType.StoreReset);
MoveInfo.NextMoveStep(StoreMoveStep.BOX_M_H_TOP1_InOutToP1);
LogUtil.info(Name + "到待机状态,进出轴到P1,判断叉子没有料盘");
ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed);
}
public override void Reset(bool isNeedClearAuto = true)
{
CurrInOutCount = 0;
CurrInOutACount = 0;
//复位之前先停止运行
if (isNeedClearAuto)
{
autoNext = false;
}
AxisManager.instance.SuddenStop(Config.Middle_Axis.DeviceName, Config.Middle_Axis.GetAxisValue());
AxisManager.instance.SuddenStop(Config.UpDown_Axis.DeviceName, Config.UpDown_Axis.GetAxisValue());
AxisManager.instance.SuddenStop(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue());
AxisManager.instance.SuddenStop(Config.Comp_Axis.DeviceName, Config.Comp_Axis.GetAxisValue());
isInSuddenDown = false;
isNoAirCheck = false;
alarmType = StoreAlarmType.None;
storeRunStatus = StoreRunStatus.Reset;
storeStatus = StoreStatus.ResetMove;
MoveInfo.NewMove(StoreMoveType.StoreReset);
WarnMsg = "";
if (!OpenAllAxis(true))
{
LogUtil.info(Name + "复位时打开轴失败,需要再次复位,直接报警停止复位");
return;
}
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutBack);
LogUtil.info(Name + "复位中,进出轴开始原点返回");
ACAxisHomeMove(Config.InOut_Axis);
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
isInPro = false;
}
protected override void ResetProcess()
{
if (MoveInfo.IsInWait)
{
CheckWait();
}
if (MoveInfo.IsInWait)
{
return;
}
switch (MoveInfo.MoveStep)
{
case StoreMoveStep.BOX_H_InOutMove:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutBack);
ACAxisHomeMove(Config.InOut_Axis);
LogUtil.info(Name + "" + MoveInfo.MoveType + ":进出轴开始原点返回");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
break;
case StoreMoveStep.BOX_H_InOutBack:
Thread.Sleep(200);
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_InOutToP1);
LogUtil.info(Name + "" + MoveInfo.MoveType + ":进出轴到待机点P1["+ Config.InOutAxis_P1_Position + "],关闭舱门");
ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed);
CloseDoor();
break;
case StoreMoveStep.BOX_H_InOutToP1:
//如果此时轴三还在报警,需要提示错误并等待
if (AxisManager.instance.GetAlarmStatus(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue()) > 0)
{
if (AxisManager.instance.GetAlarmStatus(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue()) > 0)
{
WarnMsg = Name + "" + MoveInfo.MoveType + "进出轴报警!复位失败,请检查!";
LogUtil.error(Name + "" + MoveInfo.MoveType + "进出轴报警!复位失败,请检查!");
}
}
//复位和回原点要等轴3进出轴ORG亮了以后才能返回其他轴
LogUtil.info(Name + "" + MoveInfo.MoveType + ": 压紧轴,旋转轴,上下轴开始 原点返回");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_OtherAxisBack);
MoveInfo.TimeOutSeconds = 100;
if (UseCompress_Axis)
{
ACAxisHomeMove(Config.Comp_Axis);
}
ACAxisHomeMove(Config.Middle_Axis);
ACAxisHomeMove(Config.UpDown_Axis);
break;
case StoreMoveStep.BOX_H_OtherAxisBack:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_H_MiddleAxisToP1);
LogUtil.info(Name + "" + MoveInfo.MoveType + ":旋转轴运动到P1[" + Config.MiddleAxis_P1_Position + "],上下轴走到P1[" + Config.UpDownAxis_DoorOPosition_P1 + "],压紧轴到P1[" + Config.CompressAxis_P1_Position + "]");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1_Position, Config.MiddleAxis_P1_Speed);
ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_DoorOPosition_P1, Config.UpDownAxis_P1_Speed);
ComMoveToPosition(Config.CompressAxis_P1_Position, Config.CompAxis_P1_Speed);
break;
case StoreMoveStep.BOX_H_MiddleAxisToP1:
LogUtil.info(Name + "" + MoveInfo.MoveType + "完成");
storeRunStatus = StoreRunStatus.Runing;
MoveInfo.EndMove();
storeStatus = StoreStatus.StoreOnline;
if (alarmType.Equals(StoreAlarmType.None))
{
WarnMsg = "";
}
break;
case StoreMoveStep.BOX_M_H_TOP1_InOutToP1:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_M_H_TOP1_CompressHome);
LogUtil.info(Name + "到待机状态,压紧轴回原点,关闭舱门");
if (UseCompress_Axis)
{
ACAxisHomeMove(Config.Comp_Axis);
}
//关闭舱门
CloseDoor();
break;
case StoreMoveStep.BOX_M_H_TOP1_CompressHome:
MoveInfo.NextMoveStep(StoreMoveStep.BOX_M_H_TOP1_OtherAxisToP1);
LogUtil.info(Name + "" + MoveInfo.MoveType + ":旋转轴运动到P1[" + Config.MiddleAxis_P1_Position + "],上下轴走到P1[" + Config.UpDownAxis_DoorOPosition_P1 + "],压紧轴到P1[" + Config.CompressAxis_P1_Position + "]");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
ACAxisMove(Config.Middle_Axis, Config.MiddleAxis_P1_Position, Config.MiddleAxis_P1_Speed);
ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_DoorOPosition_P1, Config.UpDownAxis_P1_Speed);
ComMoveToPosition(Config.CompressAxis_P1_Position, Config.CompAxis_P1_Speed);
break;
case StoreMoveStep.BOX_M_H_TOP1_OtherAxisToP1:
LogUtil.info(Name + "到待机状态完成");
MoveInfo.EndMove();
storeStatus = StoreStatus.StoreOnline;
storeRunStatus = StoreRunStatus.Runing;
if (alarmType.Equals(StoreAlarmType.None))
{
WarnMsg = "";
}
break;
default: break;
}
}
#endregion
#region 门开关,伺服开关操作
private void ComMoveToPosition(int targetPosition, int targetSpeed)
{
if (UseCompress_Axis)
{
ACAxisMove(Config.Comp_Axis, targetPosition, targetSpeed);
}
}
private bool DoorIsOpen()
{
if (IOValue(IO_Type.Door_Down).Equals(IO_VALUE.LOW) && IOValue(IO_Type.Door_Up).Equals(IO_VALUE.HIGH))
{
return true;
}
return false;
}
public void OpenDoor(bool IsWait = true)
{
Thread.Sleep(60);
IOMove(IO_Type.Door_Down, IO_VALUE.LOW);
IOMove(IO_Type.Door_Up, IO_VALUE.HIGH);
if (IsWait)
{
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Door_Down, IO_VALUE.LOW));
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Door_Up, IO_VALUE.HIGH));
}
}
public void CloseDoor(bool IsWait = true)
{
IOMove(IO_Type.Door_Down, IO_VALUE.HIGH);
IOMove(IO_Type.Door_Up, IO_VALUE.LOW);
if (IsWait)
{
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Door_Down, IO_VALUE.HIGH));
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Door_Up, IO_VALUE.LOW));
}
}
public bool OpenAllAxis(bool isCheck)
{
foreach (ConfigMoveAxis moveAxis in moveAxisList)
{
string portName = moveAxis.DeviceName;
short slvAddr = moveAxis.GetAxisValue();
AxisManager.instance.AlarmClear(portName, slvAddr);
Thread.Sleep(50);
AxisManager.instance.ServoOn(portName, slvAddr);
}
Thread.Sleep(500);
//打开所有轴
if (isCheck)
{
if (!CheckAndOpenAxis())
{
return false;
}
}
return true;
}
private bool CheckAndOpenAxis()
{
//判断轴是否正常
foreach (ConfigMoveAxis axis in moveAxisList)
{
if (AxisManager.instance.IsServeoOn(axis.DeviceName, axis.GetAxisValue()))
{
LogUtil.info(Name + "成功打开轴:" + axis.Explain);
}
else
{
//清理报警,再重新打开一次
LogUtil.info(Name + "第一次打开轴" + axis.Explain + "失败,先清理一下报警,再重新打开一次");
AxisManager.instance.AlarmClear(axis.DeviceName, axis.GetAxisValue());
System.Threading.Thread.Sleep(1200);
AxisManager.instance.ServoOn(axis.DeviceName, axis.GetAxisValue());
System.Threading.Thread.Sleep(100);
if (AxisManager.instance.IsServeoOn(axis.DeviceName, axis.GetAxisValue()))
{
LogUtil.info(Name + "清理报警后重新打卡轴成功:" + axis.Explain);
}
else
{
AxisManager.instance.ServoOff(axis.DeviceName, axis.GetAxisValue());
int alarmCode = GetAlarmCodeByAxis(axis);
WarnMsg = Name + "打开轴" + axis.Explain + "失败 ";
LogUtil.info(Name + WarnMsg);
Alarm(StoreAlarmType.AxisAlarm, GetAlarmCodeByAxis(axis).ToString(), WarnMsg, MoveInfo.MoveType);
return false;
}
}
}
return true;
}
public void CloseAllAxis()
{
LogUtil.info(Name + "关闭所有轴");
foreach (ConfigMoveAxis axis in moveAxisList)
{
AxisManager.instance.ServoOff(axis.DeviceName, axis.GetAxisValue());
}
}
private int GetAlarmCodeByAxis(ConfigMoveAxis axis)
{
int alarmCode = LineAlarm.InOutAxisAlarm;
int axisType = axis.GetAxisValue() % 4;
if (axisType == 1)
{
alarmCode = LineAlarm.MiddleAxisAlarm;
}
else if (axisType == 2)
{
alarmCode = LineAlarm.UpDownAxisAlarm;
}
else if (axisType == 3)
{
alarmCode = LineAlarm.InOutAxisAlarm;
}
else
{
alarmCode = LineAlarm.CompressAxisAlarm;
}
return alarmCode;
}
#endregion
public override void StopRun()
{
WarnMsg = "";
autoNext = false;
IoCheckTimer.Enabled = false;
serverConnectTimer.Enabled = false;
StopMove();
storeRunStatus = StoreRunStatus.Wait;
mainTimer.Enabled = false;
TimeSpan span = DateTime.Now - StartTime;
IsRun = false;
lineConnect.StopConnect();
IOManager.instance.CloseAllDO();
LogUtil.info(Name + ",停止运行,总运行时间:" + span.ToString());
}
public override void Alarm(StoreAlarmType alarmType, string alarmDetial, string alarmMsg, StoreMoveType 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 + "轴报警,关闭刹车,停止运动,关闭轴,打开报警灯");
//IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
StopMove();
}
else if (alarmType == StoreAlarmType.SuddenStop)
{
isInSuddenDown = true;
LogUtil.error(Name + "收到急停信号,关闭刹车,停止运动,关闭轴,打开报警灯 ");
//IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
StopMove();
storeStatus = StoreStatus.SuddenStop;
}
else if (alarmType.Equals(StoreAlarmType.NoAirCheck))
{
isNoAirCheck = true;
LogUtil.error(Name + " 未检测到气压信号 ,打开刹车,停止运动,关闭轴,打开报警灯 ");
//IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
StopMove();
storeStatus = StoreStatus.SuddenStop;
}
}
#region 急停,复位,气压检测
private void IoCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//return;
//判断急停
if (storeRunStatus >= StoreRunStatus.HomeMoving)
{
if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
if (isInSuddenDown.Equals(false))
{
LogUtil.error(Name + "收到急停信号,等待100后再次验证急停");
Thread.Sleep(100);
if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
isInSuddenDown = true;
LogUtil.error(Name + "收到急停信号,报警急停");
//WarnMsg = Name + "收到急停信号,报警急停";
SetWarnMsg( "收到急停信号,报警急停");
//报警时会关闭所有轴
Alarm(StoreAlarmType.SuddenStop, "1", WarnMsg, StoreMoveType.None);
}
}
}
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("收到复位信号,当前无报警,且空闲中,只回到待机点");
MoveToP1();
}
else
{
LogUtil.info("收到复位信号,当前无报警, 在" + MoveInfo.MoveType + "处理中,不处理复位");
}
}
else
{
//收到复位信号
LogUtil.info("收到复位信号,自动复位");
WarnMsg = "收到复位信号,自动复位";
Reset();
}
}
else
{
AirCheckProcess();
}
}
}
}
private IO_VALUE preAirValue = IO_VALUE.HIGH;
private void AirCheckProcess()
{
IO_VALUE currAirValue = IOValue(IO_Type.Airpressure_Check);
if (isInSuddenDown|| isNoAirCheck)
{
return;
}
if (currAirValue.Equals(IO_VALUE.LOW))
{
//判断是否持续了3秒
if (preAirValue.Equals(IO_VALUE.LOW))
{
TimeSpan span = DateTime.Now - lastAirCloseTime;
if (span.TotalSeconds > StoreManager.Config.AirCheckSeconds)
{
SetWarnMsg( "未检测到气压信号");
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;
}
#endregion
private bool InProcess = false;
private bool IsChongfu = false;
private Stopwatch stopwatch = new Stopwatch();
private Stopwatch doorCheckWatch = new Stopwatch();
protected override void timersTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (InProcess)
{
if (stopwatch.Elapsed.TotalMinutes < 1)
{
return;
}
else
{
LogUtil.error("主定时器:InProcess已等待" + stopwatch.Elapsed.ToString() + "重新处理");
IsChongfu = true;
}
}
try
{
InProcess = true;
stopwatch.Restart();
TimerProcess();
}
catch (Exception ex)
{
LogUtil.error(Name + "定时处理出错:" + ex.ToString());
}
IsChongfu = false;
InProcess = false;
}
private void ShowTimeLog(string info)
{
if (IsChongfu)
{
LogUtil.info("【" + info + "】 处理完成,耗时:" + stopwatch.Elapsed.ToString());
}
}
private void ReadDITimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (MoveInfo.MoveStep.Equals(StoreMoveStep.SC_03_MoveToHBag) && IOValue(IO_Type.CheckPos).Equals(IO_VALUE.HIGH))
{
reelIsExist = true;
}
}
public void TimerProcess()
{
try
{
if (IOValue(IO_Type.TrayCheck_Door).Equals(IO_VALUE.HIGH))
{
StoreManager.checkWatch(doorCheckWatch, 1000, false);
}
else
{
doorCheckWatch.Stop();
}
if (MoveInfo.MoveType != StoreMoveType.None)
{
BusyMoveProcess();
ShowTimeLog("BusyMoveProcess");
}
else if (storeRunStatus.Equals(StoreRunStatus.Runing))
{
ShowTimeLog("判断是否需要出入库");
AutoResetProcess();
ShowTimeLog("AutoResetProcess");
IOTimeOutProcess();
ShowTimeLog("IOTimeOutProcess");
}
//检查运动轴报警
if (storeRunStatus > StoreRunStatus.Wait && (!isInSuddenDown) && (!isNoAirCheck))
{
CheckAxisAlarm();
ShowTimeLog("轴报警检测完成");
}
}
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)
{
return;
}
if (isInSuddenDown || isNoAirCheck)
{
return;
}
//if (WarnMsg.Contains("等待料仓门口检测到料盘"))
//{
// 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());
}
}
/// <summary>
/// 超过配置次数时需要复位
/// </summary>
private void AutoResetProcess()
{
try
{
bool noInStore = lineConnect.WaitInStoreList.Count <= 0;
if (CurrInOutACount >= this.Config.Box_ResetACount && noInStore)
{
if (storeRunStatus < StoreRunStatus.Runing || MoveInfo.MoveType == StoreMoveType.InStore || MoveInfo.MoveType == StoreMoveType.OutStore)
{
LogUtil.info(Name + "已经累计出入库" + CurrInOutACount + "次,当时当前正在忙碌中暂不复位");
}
else
{
LogUtil.info(Name + "已经累计出入库" + CurrInOutACount + "次,需要复位一下");
Reset();
}
}
else if (CurrInOutCount >= this.Config.Box_ResetMCount && noInStore)
{
if (storeRunStatus < StoreRunStatus.Runing || MoveInfo.MoveType == StoreMoveType.InStore || MoveInfo.MoveType == StoreMoveType.OutStore)
{
LogUtil.info(Name + "已经累计出入库" + CurrInOutCount + "次,当时当前正在忙碌中暂不复位旋转轴");
}
else
{
LogUtil.info(Name + "已经累计出入库" + CurrInOutCount + "次,需要复位一下旋转轴");
}
}
else if (lineConnect.CanStartOut() || IsDebug)
{
InOutPosInfo currInOutFixture = null;
lock (waitOutListLock)
{
if (waitOutStoreList.Count > 0 && CanStarInOut())
{
currInOutFixture = waitOutStoreList[0];
waitOutStoreList.RemoveAt(0);
}
}
if (currInOutFixture != null)
{ //出库
LogUtil.info(Name + "开始执行排队中的出库【" + currInOutFixture.ToStr() + "】");
bool result = StartOutStoreMove(new InOutParam(currInOutFixture));
//bool result = StartOutStoreMove(new InOutParam("", currInOutFixture.PosId, currInOutFixture.plateH, currInOutFixture.plateW));
if (!result)
{
LogUtil.info(Name + " 执行排队中的出库【" + currInOutFixture.ToStr() + "】失败,重新加入等待队列");
AddWaitOutInfo(currInOutFixture);
}
}
}
}
catch (Exception ex)
{
LogUtil.error("处理出入库排队列表出错:" + ex.ToString());
}
}
private DateTime checkAlarmTime = DateTime.Now;
public bool CheckAxisAlarm()
{
if (alarmType.Equals(StoreAlarmType.AxisAlarm) || alarmType.Equals(StoreAlarmType.AxisMoveError))
{
return true;
}
TimeSpan span = DateTime.Now - checkAlarmTime;
//1秒钟检测一次轴报警
if (span.TotalSeconds < 1)
{
return false;
}
checkAlarmTime = DateTime.Now;
bool isInAlarm = false;
foreach (ConfigMoveAxis axisInfo in moveAxisList)
{
short axis = axisInfo.GetAxisValue();
string deviceName = axisInfo.GetNameStr();
AxisAlarmInfo info = AxisAlarmCodeMap[deviceName];
int alarmIo = AxisManager.instance.GetAlarmStatus(deviceName, axis);
if (alarmIo == 1)
{
WarnMsg = Name + " 运动轴" + axisInfo.Explain + "报警";
info.AlarmIoValue = alarmIo;
Alarm(StoreAlarmType.AxisAlarm, GetAlarmCodeByAxis(axisInfo).ToString(), WarnMsg, StoreMoveType.None);
isInAlarm = true;
}
else
{
if (!info.AlarmIoValue.Equals(alarmIo))
{
LogUtil.error(Name + " 运动轴 " + axisInfo.Explain + ",报警已解除!");
info.AlarmIoValue = alarmIo;
}
}
AxisAlarmCodeMap[deviceName] = info;
}
//判断报警状态
return isInAlarm;
}
public override void StopMove()
{
MoveInfo.EndMove();
//IOMove(IO_Type.Axis_Brake, IO_VALUE.LOW);
//运动版停止
AxisManager.instance.SuddenStop(Config.Middle_Axis.DeviceName, Config.Middle_Axis.GetAxisValue());
AxisManager.instance.SuddenStop(Config.UpDown_Axis.DeviceName, Config.UpDown_Axis.GetAxisValue());
AxisManager.instance.SuddenStop(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue());
AxisManager.instance.SuddenStop(Config.Comp_Axis.DeviceName, Config.Comp_Axis.GetAxisValue());
Thread.Sleep(300);
CloseAllAxis();
LogUtil.info(Name + "StopMove");
IOMove(IO_Type.Door_Down, IO_VALUE.LOW);
IOMove(IO_Type.Door_Up, IO_VALUE.LOW);
isInPro = false;
}
public bool CanStarInOut()
{
if (isInSuddenDown || isNoAirCheck ||
(!storeRunStatus.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 int StrToInt(string str)
{
try
{
return Convert.ToInt32(str.Trim());
}
catch (Exception ex)
{
LogUtil.error(Name + "转换[" + str + "]出错:" + ex.ToString());
}
return 0;
}
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:料盘高度,
string posId = data[ParamDefine.posId];
string plateWStr = data[ParamDefine.plateW];
string plateHStr = data[ParamDefine.plateH];
int plateW = StrToInt(plateWStr);
int plateH = StrToInt(plateHStr);
InOutPosInfo inoutInfo = new InOutPosInfo(message, posId, plateH, plateW);
//根据发送的posId获取位置列表
ACStorePosition position = CSVPositionReader<ACStorePosition>.GetPositon(posId);
if (position == null)
{ //出入库没有找到服务器发送的库位,需要打印日志方便查询原因
WarnMsg = "入库未找到库位:【" + inoutInfo.ToStr() + "】 ";
LogUtil.error("收到服务器入库命令:入库未找到库位:【" + inoutInfo.ToStr() + "】");
LogUtil.info("收到服务器入库命令:入库未找到库位:【" + inoutInfo.ToStr() + "】");
return;
}
//TODO:判断BOX是否处于可以入库状态,如果调试或急停中,需要返回给服务器;
if (CanStarInOut())
{
InOutParam param = new InOutParam(inoutInfo);
StartInStoreMove(param);
//如果当前正在出入库中,需要记录下来,等待空闲时执行
LogUtil.info(Name + " 收到服务器入库命令:【" + inoutInfo.ToStr() + "】开始入库!");
}
else
{
LogUtil.info(Name + " 收到服务器入库命令:【" + inoutInfo.ToStr() + "】 正在忙碌中,无法入库!");
}
}
}
public bool ReviceLineCheckInStoreCMD(string posId, int plateH, int plateW, string message, string rfid)
{
string logName = "入库库位验证【 " + message + "】【" + posId + "】:";
try
{
if (storeRunStatus.Equals(StoreRunStatus.Wait))
{
LogUtil.info(logName + " 设备未启动,验证失败");
return false;
}
//发送扫码内容到服务器进行入库操作
Operation operation = getLineBoxStatus();
operation.op = 1;
operation.data = new Dictionary<string, string>() { { "code", message }, { "boxId", DeviceID.ToString() }, { "rfid", rfid } };
operation.data.Add("inPos", posId);
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
for (int i = 1; i <= 3; i++)
{
bool timeOut = false;
Operation resultOperation = HttpHelper.PostOP(StoreManager.GetPostApi(server), operation, out timeOut);
if (timeOut)
{
LogUtil.info(logName + " 第" + i + "次发送超时 ");
continue;
}
if (resultOperation == null)
{
// CodeMsg = "二维码【" + message + "】没有收到服务器反馈";
LogUtil.info(logName + " 没有收到服务器反馈 ");
}
else if (!string.IsNullOrEmpty(resultOperation.msg))
{
//如果有提示消息,直接显示提示
LogUtil.info(logName + "服务器反馈 :" + resultOperation.msg);
}
else if (resultOperation.op.Equals(1))
{
LogUtil.info(logName + " 成功");
return true;
}
break;
}
}
catch (Exception ex)
{
LogUtil.info(logName + " 出错:" + ex.ToString());
}
return false;
}
public void ReviceLineInStoreCMD(string posId, int plateH, int plateW, string message, string rfid)
{
string logName = "流水线入库命令【 " + message + "】【" + posId + "】:";
if (!lineConnect.WaitInStoreList.Contains(posId))
{
LogUtil.error(logName + "库位未验证通过,重新验证库位");
bool result = ReviceLineCheckInStoreCMD(posId, plateH, plateW, message, rfid);
if (!result)
{
return;
}
}
else
{
lineConnect.WaitInStoreList.Remove(posId);
}
//根据发送的posId获取位置列表
ACStorePosition position = CSVPositionReader<ACStorePosition>.GetPositon(posId);
if (position == null)
{ //出入库没有找到服务器发送的库位,需要打印日志方便查询原因
WarnMsg = "入库未找到库位:二维码【" + message + "】库位【" + posId + "】 ";
LogUtil.error(logName + "未找到库位");
return;
}
//TODO:判断BOX是否处于可以入库状态,如果调试或急停中,需要返回给服务器;
if (CanStarInOut())
{
InOutPosInfo inout = new InOutPosInfo(message, posId, plateH, plateW);
inout.rfid = rfid;
InOutParam param = new InOutParam(inout);
LogUtil.info(logName + " 开始入库!");
StartInStoreMove(param);
//如果当前正在出入库中,需要记录下来,等待空闲时执行
}
else
{
LogUtil.info(logName + " 正在忙碌中,无法入库!");
}
}
#endregion
#region 与服务器通信定时器,每1秒向服务器通知一次状态,同时执行出库操作
private string CodeMsg = "";
private bool isInProcess = false;
private DateTime lastConTime = DateTime.Now;
public void server_connect_timer_Tick(object sender, EventArgs e)
{
if (isInProcess)
{
TimeSpan span = DateTime.Now - lastConTime;
if (span.TotalSeconds < 60)
{
return;
}
}
isInProcess = true;
lastConTime = DateTime.Now;
try
{
if (lineConnect.IsConnect())
{
int hasTray = (int)IOValue(IO_Type.TrayCheck_Door);
int ss = (int)storeStatus;
if (IsDebug)
{
ss = (int)StoreStatus.Debugging;
}
StoreSendBean store = lineConnect.GetBean( (int)ss, (int)storeRunStatus, hasTray, (int)alarmType );
lineConnect.SendHeart(store);
}
if (StoreManager.IsConnectServer)
{
try
{
SendLineStatus();
}
catch (Exception ex)
{
LogUtil.error("定时给服务器发送消息出错:" + ex.ToString());
}
}
humBean.HumidityProcess(this);
}
catch (Exception ex)
{
LogUtil.error("server_connect_timer_Tick出错:" + ex.ToString());
}
finally
{
isInProcess = false;
}
}
public 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;
}
else if (IsRun)
{
lineOperation.status = (int)StoreStatus.StoreOnline;
}
lineOperation.status = (int)StoreStatus.StoreOnline;
BoxStatus boxStatus = new BoxStatus();
boxStatus.boxId = 1;
boxStatus.msg = WarnMsg;
lineOperation.msg = WarnMsg;
if (WarnMsg.Equals(""))
{
boxStatus.msg = CodeMsg;
lineOperation.msg = CodeMsg;
}
if (CodeMsg.Equals(""))
{
if (storeRunStatus.Equals(StoreRunStatus.Runing) && IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
{
boxStatus.msg = "叉子料盘检测有料,请检查";
lineOperation.msg = "叉子料盘检测有料,请检查";
}
}
CodeMsg = "";
//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 = "";
}
//如果在空闲中,且有入库未完成,直接发送入库执行中
if (boxStatus.status.Equals((int)StoreStatus.StoreOnline))
{
List<string> list = new List<string>(lineConnect.WaitInStoreList);
if (list.Count > 0 && (lineConnect.CanStartOut().Equals(false)))
{
boxStatus.status = (int)StoreStatus.InStoreExecute;
}
}
//温湿度
//ASTemperateParam param = HumitureServer.GetTemperateParam(Config.Temperate_Serveraddress);
//HumitureParam param = HumitureController.LastData;
if (humBean != null)
{
boxStatus.humidity = humBean.LastData.Humidity.ToString();
boxStatus.temperature = humBean.LastData.Temperate.ToString();
}
lineOperation.boxStatus.Add(1, boxStatus);
if (!alarmType.Equals(StoreAlarmType.None))
{
lineOperation.alarmList.Add(alarmInfo);
}
return lineOperation;
}
public void SendLineStatus()
{
DateTime time = DateTime.Now;
//构建发送给服务器的对象
Operation lineOperation = getLineBoxStatus();
//如果还没湿度范围,先获取
if (humBean.NeedGetTem())
{
lineOperation.op = 5;
LogUtil.error(Name + "没有湿度预警范围,需要从服务器获取,发送OP=" + lineOperation.op, DeviceID + 105);
}
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
bool isTimeout = false;
Operation resultOperation = HttpHelper.PostOP(StoreManager.GetPostApi(server), lineOperation, out isTimeout);
//发送状态信息到服务器
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))
{
humBean.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 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))
{
char splitChar = '|';
string[] posIdArray = data[ParamDefine.posId].Split(splitChar);
string[] plateWArray = data[ParamDefine.plateW].Split(splitChar);
string[] plateHArray = data[ParamDefine.plateH].Split(splitChar);
bool urgentReel = FormUtil.GetBoolData(data, ParamDefine.urgentReel);
bool cutReel = FormUtil.GetBoolData(data, ParamDefine.cutReel);
bool smallReel = FormUtil.GetBoolData(data, ParamDefine.smallReel);
string rfid = data.ContainsKey(ParamDefine.rfid) ? data[ParamDefine.rfid] : "";
int rfidLoc = FormUtil.GetIntData(data, ParamDefine.rfidLoc);
string barcode = data.ContainsKey(ParamDefine.barcode) ? data[ParamDefine.barcode] : "";
//urgentReel: true 表示紧急料,需要出到料串上
//cutReel: true 表示分盘料,需要出到料串上
//smallReel: true 小料(7x8),放置到小料架上
//rfid: 分配的料架RFID
//rfidLoc: 料架的架位,值为 - 1时,可以自由分配皮带线, 小料时,架位为1 - 46优先走1 / 2号皮带线,47 - 92优先走3 / 4号皮带线, 70,71,72时只能分配到3 / 4号皮带线; 大料时,架位1 - 6优先走1 / 2号皮带线, 7 - 12优先走3 / 4号皮带线
string dataStr = JsonHelper.SerializeObject(data);
LogUtil.info("收到服务器出库消息:【" + dataStr + "】");
int index = -1;
foreach (string posId in posIdArray)
{
index++;
string plateWStr = plateWArray[index];
string plateHStr = plateHArray[index];
int plateW = StrToInt(plateWStr);
int plateH = StrToInt(plateHStr);
InOutPosInfo intouInfo = new InOutPosInfo(barcode, posId, plateW, plateH, urgentReel, cutReel, smallReel, rfid, rfidLoc);
//根据发送的posId获取位置列表
ACStorePosition position = CSVPositionReader<ACStorePosition>.GetPositon(posId);
if (position == null)
{
//出入库没有找到服务器发送的库位,需要打印日志方便查询原因
WarnMsg = Name + "未找到库位:【" + intouInfo.ToStr() + "】";
LogUtil.error(WarnMsg);
continue;
}
try
{
//判断是否接收过此库位的出库信息
if (MoveInfo.MoveType.Equals(StoreMoveType.OutStore) && MoveInfo.MoveParam.PosInfo.PosId.Equals(posId))
{
LogUtil.info(Name + " 出库命令【" + intouInfo.ToStr() + "】重复,正在【" + posId + "】出库中");
continue;
}
else
{
//判断排队列表中是否已存在
List<InOutPosInfo> reviceList = new List<InOutPosInfo>(waitOutStoreList);
reviceList = (from m in reviceList where m.PosId.Equals(posId) select m).ToList<InOutPosInfo>();
if (reviceList.Count > 0)
{
LogUtil.debug(Name + " 出库命令【" + intouInfo.ToStr() + "】重复,排队列表中已存在【" + reviceList[0].ToStr() + "】");
continue;
}
}
}
catch (Exception ex)
{
LogUtil.error("验证出库【" + intouInfo.ToStr() + "】是否重复出错:" + ex.ToString());
}
if (CanStarInOut() && (lineConnect.CanStartOut() || IsDebug))
{
bool result = StartOutStoreMove(new InOutParam(intouInfo));
if (!result)
{
LogUtil.info(Name + " 执行出库【" + intouInfo.ToStr() + "】失败,加入等待队列");
AddWaitOutInfo(intouInfo);
}
}
else
{
LogUtil.error("执行出库【" + intouInfo.ToStr() + "】失败,当前在忙碌中,加入等待队列");
AddWaitOutInfo(intouInfo);
}
}
TimeSpan span = DateTime.Now - time;
if (span.TotalMilliseconds > 10)
{
LogUtil.info(Name + "执行TimerProcess 共处理了【" + span.TotalMilliseconds + "】毫秒");
}
}
}
#endregion
public string GetWarnMsg()
{
string msg = WarnMsg;
return msg;
}
}
}