SServerManager.cs
51.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
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
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class SServerManager
{
//http://localhost/myproject/service/store/emptyPosForPutin
private static string Addr_PosForPutin = "/service/store/emptyPosForPutin";
/// <summary>
/// 1 皮带线扫码后调用,用于获取尺寸后升起气缸
/// 地址: /rest/api/qisda/device/getSize
/// </summary>
private static string Addr_getSize = "/rest/api/qisda/device/getSize";
/// <summary>
/// 2 料盘流转位置信息更新
/// 地址: /rest/api/qisda/device/updateLocInfo
/// </summary>
private static string Addr_updateLocInfo = "/rest/api/qisda/device/updateLocInfo";
/// <summary>
/// 3 放入料架(A,B,C,D)后调用,根据返回值决定当前料架是否放满,以及后续是否还有任务
// 地址: /rest/api/qisda/device/putShelfFinished
/// </summary>
private static string Addr_putShelfFinished = "/rest/api/qisda/device/putShelfFinished";
private static string GetAddr(string addr, Dictionary<string, string> paramsMap)
{
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
if (server.EndsWith("/"))
{
server = server.Substring(0, server.Length - 1);
}
string path = server + addr.Trim() + "?";
foreach (string paramName in paramsMap.Keys)
{
string par = System.Web.HttpUtility.UrlEncode(paramsMap[paramName], System.Text.Encoding.UTF8);
path += paramName + "=" + par + "&";
}
path = path.Substring(0, path.Length - 1);
return path;
}
//## 100 循环获取库位。服务器超时:循环获取库位
private static string spiltStr = "##";
public static string CodeReceived(string deviceName, int trayNum, List<string> codeList, int height, int width, string rfid, int feedEquipId)
{
string msg = "";
try
{
string codeStr = "";
List<string> list = new List<string>();
foreach (string str in codeList)
{
if (list.Contains(str.Trim()) || String.IsNullOrEmpty(str.Trim()))
{
continue;
}
list.Add(str.Trim());
string code = "=" + width + "x" + height + "=" + str.Trim();
codeStr = codeStr + code + spiltStr;
}
codeStr = CodeManager.ReplaceCode(codeStr);
//http://localhost/myproject/service/store/emptyPosForPutin
// 参数:cids: 多个 cid
//code: 条码内容
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("cids", LineServer.GetAllCID(feedEquipId));
paramMap.Add("code", codeStr);
paramMap.Add("trayRfid", trayNum.ToString());
paramMap.Add(ParamDefine.rfid, rfid);
string server = GetAddr(Addr_PosForPutin, paramMap);
//string server = GetAddr(Addr_PosForPutin) + "?cids=" + LineServer.GetAllCID() + "&code=%3D" + codeStr;
DateTime startTime = DateTime.Now;
LogUtil.info(deviceName + "托盘【" + trayNum + "】 条码【 " + codeStr + "】料串【" + rfid + "】,获取入库库位:");
string resultStr = HttpHelper.Post(server, "", 10000);
LogUtil.info(deviceName + "CodeReceived " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
//{"result":"0","msg":"","pos":"11#AC1_18_4_28","barcode":"R506072019102200414","cid":"line-ac-11"}
LineOperation serverResult = JsonHelper.DeserializeJsonToObject<LineOperation>(resultStr);
if (serverResult == null)
{
msg = deviceName + " 【" + codeStr + "】结果:没有收到服务器反馈,调用 cancelPutInTask ";
cancelPutInTask(deviceName, codeStr, false);
return msg;
}
else if ((!string.IsNullOrEmpty(serverResult.msg)) || serverResult.result.Equals(0).Equals(false))
{
return msg = deviceName + " 【" + codeStr + "】结果:" + serverResult.msg;
}
if (!serverResult.pos.Equals(""))
{
// 仓位命名: 4D01020304
//第1和第2位表示楼层(4D)
//第3和第4位表示料仓(01) 01 - 18为流水线料仓, 19 - 24为包装料仓
//第5和第6位表示列(02)
//第7和第8位表示行(03)
//第9和第10位表示隔板位置(04)
//例如: 4D12010124 表示4楼12号料仓第1列第1行架子上的第24个隔板位置
//4D19050208 表示4楼19号料仓(包装料仓)第5列第2行架子上的第8个隔板位置
string posId = serverResult.pos;
int plateW = width;
int plateH = height;
int storeId = InOutParam.GetPosStoreId(posId);
string wareNum = serverResult.barcode;
//根据库位号查找移栽
MoveEquip moveEquip = LineManager.Line.GetMoveByDId(storeId);
// 判断PosID是否已经在入库或者在排队列表中,如果已经存在,加入列表失败
InOutParam param = new InOutParam(trayNum, wareNum, posId, plateH, plateW);
param.rfid = rfid;
if (LineManager.Line.IsReviceInPosId(moveEquip, posId))
{
//LineManager.Line.SetWarnMsg("入库库位重复: " + param.ToStr() + " ,入库失败!");
//moveEquip.SetWarnMsg("入库库位重复: " + param.ToStr() + "");
return msg = deviceName + ("收到服务器入库命令 " + "入库库位重复: " + param.ToStr() + " ,入库失败!");
}
LogUtil.info(deviceName + "收到入库命令: " + param.ToStr() + " ,更新盘空满信息,托盘号【" + trayNum + "】,有料," + ReelType.InStore + "");
TrayManager.UpdateTrayInfo(trayNum, true, ReelType.InStore, new InOutParam(trayNum, wareNum, posId, plateH, plateW, false));
//TODO:判断BOX是否处于可以入库状态,如果调试或急停中,需要返回给服务器;
if (LineServer.BoxCanInStore(storeId))
{
LineServer.CheckInStorePos(storeId, param);
}
else
{
//等待3秒后重发验证
Task.Factory.StartNew(delegate
{
LogUtil.error(moveEquip.Name + " 入库命令: " + param.ToStr() + " 给料仓发送验证失败,等待3秒后重发 ");
Thread.Sleep(3000);
LineServer.CheckInStorePos(storeId, param);
});
}
lock (moveEquip.waitInListLock)
{
//如果当前正在出入库中,需要记录下来,等待空闲时执行
LogUtil.info(moveEquip.Name + " 入库命令: " + param.ToStr() + "加入等待列表中!");
moveEquip.waitInStoreList.Add(param);
}
}
}
catch (Exception ex)
{
LogUtil.error(deviceName + " ", ex);
}
return "";
}
public static string ProcessCodeList(List<string> codeList)
{
string codeStr = "";
List<string> list = new List<string>();
foreach (string str in codeList)
{
if (list.Contains(str.Trim()) || String.IsNullOrEmpty(str.Trim()))
{
continue;
}
codeStr = codeStr + str.Trim() + spiltStr;
}
return codeStr;
}
public static string GetTraySize(string deviceName, int robotIndex, string codeStr, out int outSize)
{
outSize = 0;
string msg = "";
try
{
if (String.IsNullOrEmpty(codeStr))
{
return msg = deviceName + "未扫到条码";
}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("robotIndex", robotIndex.ToString());// 参数: robotIndex = 机器人编号,IP为51的机器人为1, 52的机器人为2, 53的机器人为3
paramMap.Add("barcode", codeStr);// barcode = 扫到的条码
string server = GetAddr(Addr_getSize, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.info("GetTraySize " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
//返回: { "code": 0, "msg":"ok", data: 7}
ServerData serverResult = JsonHelper.DeserializeJsonToObject<ServerData>(resultStr);
if (serverResult == null)
{
return msg = deviceName + " 【" + robotIndex + "】 条码【 " + codeStr + "】没有收到服务器反馈";
}
else if (serverResult.code.Equals(0).Equals(false))
{
// code: 0为正常,其他为异常,
// msg:消息,
return msg = deviceName + " 【" + robotIndex + "】 条码【 " + codeStr + "】返回:" + "[" + serverResult.code + "]" + serverResult.msg;
}
if (!serverResult.data.Equals(""))
{
// data:料盘直径,= 7时升起气缸
outSize = Convert.ToInt32(serverResult.data);
LogUtil.info(deviceName + "【" + robotIndex + "】 条码【 " + codeStr + "】,获得尺寸:" + outSize);
}
}
catch (Exception ex)
{
LogUtil.error(deviceName + " ", ex);
}
return "";
}
public static string UpdateTrayLoc(string deviceName, string barcode, string status, string locInfo)
{
string msg = "";
try
{
if (String.IsNullOrEmpty(barcode))
{
return msg;
}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("barcode", barcode);//barcode = 料盘的条码
paramMap.Add("status", status); // status = 状态信息, 移栽 = MOVING, 流水线 = INLINE, 皮带线 = INBELT
paramMap.Add("locInfo", locInfo); // locInfo = 位置信息,移栽时为移栽编号,流水线时为托盘号,皮带线时为皮带线编号,机器人时为机器人编号
string server = GetAddr(Addr_updateLocInfo, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.info("UpdateTrayLoc " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
// 返回: { "code": 0, "msg":"ok", "data":""}
ServerData serverResult = JsonHelper.DeserializeJsonToObject<ServerData>(resultStr);
if (serverResult == null)
{
msg = deviceName + "UpdateTrayLoc【 " + barcode + "】【" + status + "】【" + locInfo + "】没有收到服务器反馈";
}
else if (serverResult.code.Equals(0).Equals(false))
{
// code: 0为正常,其他为异常, msg: 消息, data: 为空
msg = deviceName + " UpdateTrayLoc【 " + barcode + "】【" + status + "】【" + locInfo + "】 :" + "[" + serverResult.code + "]" + serverResult.msg;
}
if (!msg.Equals(""))
{
LogUtil.error(msg);
}
}
catch (Exception ex)
{
LogUtil.error(deviceName + " ", ex);
}
return msg;
}
private static string Addr_clearPutInRfid = "/service/store/qisda/clearPutInRfid";
public static string clearPutInRfid(string deviceName, string rfid)
{
string msg = "";
try
{
if (String.IsNullOrEmpty(rfid))
{
return msg;
}
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("rfid", rfid);//rfid
string server = GetAddr(Addr_clearPutInRfid, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.info(deviceName + "clearPutInRfid " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
}
catch (Exception ex)
{
LogUtil.error(deviceName + " " + ex.ToString());
}
return msg;
}
//皮带线获取尺寸后,料盘到达机器人取料位置进调用,如果未扫到码,或者没等到取料位置信号亮,可以不用调用
//> 地址:
//>>/rest/api/qisda/device/arriveRobotLocation
//>
//> 参数:
//>> - robotIndex=机器人编号,IP为51的机器人为1, 52的机器人为2, 53的机器人为3
//>
//> 返回:
//>>``
private static string Addr_arriveRobotLocation = "/rest/api/qisda/device/arriveRobotLocation";
public static string arriveRobotLocation(string deviceName, int robotIndex, string barcode)
{
string msg = "";
try
{
if (robotIndex <= 0)
{
return "robotIndex=" + robotIndex;
}
DateTime startTime = DateTime.Now;
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("robotIndex", robotIndex.ToString());//rfid
paramMap.Add("barcode", barcode);
string server = GetAddr(Addr_arriveRobotLocation, paramMap);
string resultStr = HttpHelper.Post(server, "");
LogUtil.info(deviceName + "arriveRobotLocation " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
}
catch (Exception ex)
{
msg = deviceName + " " + ex.ToString();
LogUtil.error(deviceName + " " + ex.ToString());
}
return msg;
}
// 分盘料/紧急料放上料串或料架时调用 /rest/api/qisda/device/afterPutCut
private static string Addr_afterPutCut = "/rest/api/qisda/device/afterPutCut";
public static string afterPutCut(string deviceName, string rfid, string barcode, string cid, int rfidLoc, out TaskData afterData)
{
afterData = null;
string msg = "";
try
{
//参数:
//cid: 料仓cid,流水线可传入空
//barcode : 条码
//rfid : RFID
//rfidLoc: 料架位置,流水线可传-1
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("barcode", barcode); // 参数: barcode=料盘的条码
paramMap.Add("rfid", rfid); // rfid = 料架的RFID信息
paramMap.Add("rfidLoc", rfidLoc.ToString()); // rfidLoc=料架的架位信息
paramMap.Add("cid", cid); // 料仓cid,流水线可传入空
string server = GetAddr(Addr_afterPutCut, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
if (barcode != "")
{
LogUtil.info(deviceName + "afterPutCut " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
}
else
{
LogUtil.debug(deviceName + "afterPutCut " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
}
//> 返回:
//>>` {"code": 0, "msg":"ok", "data":{"cutPackageTask":"0","urgentPackageTask":"20","cutTask":"21","urgentTask":"22"}} `
//>>
//>> - code: 0为正常,其他为异常,
//>> - msg:消息,
//>> - data:为包装料仓的空闲仓位数(key为与客户端一致的料仓标识, value为空闲仓位)
//>> - cutPackageTask: 表示当前包装仓的分盘任务数
//>> - urgentPackageTask: 表示当前包装仓的紧急料任务数
//>> - cutTask: 表示流水线分盘任务数
//>> - urgentTask: 表示流水线紧急料任务数
AfterPutData serverResult = JsonHelper.DeserializeJsonToObject<AfterPutData>(resultStr);
if (serverResult == null)
{
return msg = deviceName + "afterPutCut【 " + barcode + "】【" + rfid + "】【" + rfidLoc + "】没有收到服务器反馈";
}
else if (serverResult.code.Equals(0).Equals(false))
{
return msg = deviceName + " afterPutCut【 " + barcode + "】【" + rfid + "】【" + rfidLoc + "】 :" + serverResult.msg;
}
afterData = serverResult.data;
return "";
}
catch (Exception ex)
{
LogUtil.error(deviceName + " " + ex.ToString());
}
return msg;
}
// 分盘料/紧急料启动时获取料架的虚拟RFID调用 地址: /rest/api/qisda/device/findTempRfid
private static string Addr_findTempRfid = "/rest/api/qisda/device/findTempRfid";
public static string findTempRfid(string deviceName, string rfid, out string tempRfid)
{
tempRfid = "";
string msg = "";
try
{
// 参数: rfid: RFID
// 返回: "code": 0, "msg":"ok", "data":{ "tempRfid":""}
// code: 0为正常,其他为异常,
//msg: 消息,
//data: tempRfid: 表示当前料架(料串)对应的虚拟RFID
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("rfid", rfid); // rfid: RFID
string server = GetAddr(Addr_findTempRfid, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.info(deviceName + "findTempRfid " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
RfidData data = JsonHelper.DeserializeJsonToObject<RfidData>(resultStr);
if (data == null)
{
return msg = deviceName + " findTempRfid【 " + rfid + "】 没有收到服务器反馈";
}
else if (data.code.Equals(0).Equals(false))
{
return msg = deviceName + " findTempRfid【 " + rfid + "】 :" + data.msg;
}
if (data.data != null && data.data.ContainsKey("tempRfid"))
{
tempRfid = data.data["tempRfid"];
}
return "";
}
catch (Exception ex)
{
LogUtil.error(deviceName + " " + ex.ToString());
}
return msg;
}
// 取消任务地址: /cancelPutInTask //参数: barcode
private static string Addr_cancelPutInTask = "/rest/api/qisda/device/cancelPutInTask";
public static string cancelPutInTask(string deviceName, string barcode, bool disablePos)
{
string msg = "";
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("barcode", barcode);
paramMap.Add("disablePos", disablePos.ToString());
string server = GetAddr(Addr_cancelPutInTask, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.info(deviceName + "cancelPutInTask " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
RfidData data = JsonHelper.DeserializeJsonToObject<RfidData>(resultStr);
if (data == null)
{
return msg = deviceName + " cancelPutInTask【 " + barcode + "," + disablePos + "】 没有收到服务器反馈";
}
else if (data.code.Equals(0).Equals(false))
{
return msg = deviceName + " cancelPutInTask【 " + barcode + "," + disablePos + "】 :" + data.msg;
}
return "";
}
catch (Exception ex)
{
LogUtil.error(deviceName + " " + ex.ToString());
}
return msg;
}
public static GetPosResult GetPosId(string deviceName, List<string> codeList, int height, int width, string rfid, int feedEquipId)
{
GetPosResult result = new GetPosResult();
try
{
string codeStr = "";
List<string> list = new List<string>();
foreach (string str in codeList)
{
if (list.Contains(str.Trim()) || String.IsNullOrEmpty(str.Trim()))
{
continue;
}
list.Add(str.Trim());
string code = "=" + width + "x" + height + "=" + str.Trim();
codeStr = codeStr + code + spiltStr;
}
codeStr = CodeManager.ReplaceCode(codeStr);
//http://localhost/myproject/service/store/emptyPosForPutin
// 参数:cids: 多个 cid
//code: 条码内容
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("cids", LineServer.GetAllCID(feedEquipId));
paramMap.Add("code", codeStr);
paramMap.Add(ParamDefine.rfid, rfid);
string server = GetAddr(Addr_PosForPutin, paramMap);
DateTime startTime = DateTime.Now;
LogUtil.info(deviceName + "【" + rfid + "】【 " + codeStr + "】 ,获取入库库位:");
string resultStr = HttpHelper.Post(server, "", Encoding.UTF8, 10000, out result.IsTimeOut);
LogUtil.info(deviceName + "CodeReceived " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
if (result.IsTimeOut)
{
return result;
}
//{"result":"0","msg":"","pos":"11#AC1_18_4_28","barcode":"R506072019102200414","cid":"line-ac-11"}
LineOperation serverResult = JsonHelper.DeserializeJsonToObject<LineOperation>(resultStr);
if (serverResult == null)
{
result.Msg = deviceName + " 【" + codeStr + "】结果:没有收到服务器反馈,调用 cancelPutInTask ";
cancelPutInTask(deviceName, codeStr, false);
result.Param = new InOutParam(0, codeStr, "", height, width, true);
result.Param.rfid = rfid;
result.Param.InStoreNg = true;
result.Param.NgMsg = "没有收到服务器反馈";
return result;
}
else if ((!string.IsNullOrEmpty(serverResult.msg)) || serverResult.result.Equals(0).Equals(false))
{
result.Result = serverResult.result;
result.Msg = serverResult.msg;
//result.Msg = deviceName + " 【" + codeStr + "】结果:" + serverResult.msg;
result.Param = new InOutParam(0, codeStr, "", height, width, true);
result.Param.rfid = rfid;
result.Param.InStoreNg = true;
result.Param.NgMsg = "" + serverResult.msg;
return result;
}
result.Result = serverResult.result;
if (!serverResult.pos.Equals(""))
{
// 仓位命名: 4D01020304
//第1和第2位表示楼层(4D)
//第3和第4位表示料仓(01) 01 - 18为流水线料仓, 19 - 24为包装料仓
//第5和第6位表示列(02)
//第7和第8位表示行(03)
//第9和第10位表示隔板位置(04)
//例如: 4D12010124 表示4楼12号料仓第1列第1行架子上的第24个隔板位置
//4D19050208 表示4楼19号料仓(包装料仓)第5列第2行架子上的第8个隔板位置
string posId = serverResult.pos;
//根据库位号查找移栽
// 判断PosID是否已经在入库或者在排队列表中,如果已经存在,加入列表失败
result.Param = new InOutParam(0, serverResult.barcode, posId, height, width);
result.Param.rfid = rfid;
int storeId = result.Param.GetStoreId();
MoveEquip moveEquip = LineManager.Line.GetMoveByDId(storeId);
if (moveEquip != null)
{
if (LineManager.Line.IsReviceInPosId(moveEquip, posId))
{
result.Param.InStoreNg = true;
result.Param.NgMsg = "入库库位重复";
result.Msg = deviceName + ("收到服务器入库命令 " + "入库库位重复: " + result.Param.ToStr() + " ,入库失败!");
return result;
}
LogUtil.info(deviceName + "收到入库命令: " + result.Param.ToStr() + " ");
}
else
{
result.Param.InStoreNg = true;
result.Param.NgMsg = "未找到料仓[" + storeId + "]";
result.Msg = deviceName + ("收到服务器入库命令 " + "未找到料仓[" + storeId + "]: " + result.Param.ToStr() + " ,入库失败!");
return result;
}
}
}
catch (Exception ex)
{
LogUtil.error(deviceName + " ", ex);
}
return result;
}
public static void SendPosToStoreCheck(string deviceName, InOutParam param)
{
if (param == null || param.InStoreNg)
{
return;
}
int storeId = param.GetStoreId();
MoveEquip moveEquip = LineManager.Line.GetMoveByDId(storeId);
if (LineServer.BoxCanInStore(storeId))
{
LineServer.CheckInStorePos(storeId, param);
}
else
{
//等待3秒后重发验证
Task.Factory.StartNew(delegate
{
LogUtil.error(deviceName + "[" + moveEquip.Name + " ]入库命令: " + param.ToStr() + " 给料仓发送验证失败,等待3秒后重发 ");
Thread.Sleep(3000);
LineServer.CheckInStorePos(storeId, param);
});
}
lock (moveEquip.waitInListLock)
{
//如果当前正在出入库中,需要记录下来,等待空闲时执行
LogUtil.info(deviceName + "[" + moveEquip.Name + " ]入库命令: " + param.ToStr() + "加入等待列表中!");
InOutParam inOutParam = moveEquip.waitInStoreList.Find(s => param.PosId.Equals(s.PosId));
if (inOutParam != null)
{
moveEquip.waitInStoreList.Remove(inOutParam);
}
moveEquip.waitInStoreList.Add(param);
}
}
//14.异常看板
// > 地址:
//>>/ rest / api / qisda / device / updateDeviceAlarmMsg
// >
// > 参数:
//>> deviceAlarmList : 异常列表Json字符串 `[{"name":"移栽5", "msgKey":"line.move5.timeOut", "msgValue":"运动超时"},{"name":"移栽4", "msgKey":"line.move4.timeOut", "msgValue":"误差过大"}]`
//>>>name : 异常位置名称
//>>>msgKey : 异常信息唯一标识
//>>>msgValue : 异常信息
//>
//> 返回:
//>>` {"code":0,"msg":"ok","data":""}`
//>>
//>> - code: 0为正常,其他为异常,
// >> - msg:消息,
// >> - data:
private static string Addr_updateDeviceAlarmMsg = "/rest/api/qisda/device/updateDeviceAlarmMsg";
public static string updateDeviceAlarmMsg(List<AlarmMsg> msgList)
{
string msg = "";
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
string msgListStr = JsonHelper.SerializeObject(msgList);
paramMap.Add("deviceAlarmList", msgListStr);
string server = GetAddr(Addr_updateDeviceAlarmMsg, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "", 5000);
LogUtil.debug("updateDeviceAlarmMsg " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
RfidData data = JsonHelper.DeserializeJsonToObject<RfidData>(resultStr);
if (data == null)
{
return msg = " updateDeviceAlarmMsg 没有收到服务器反馈";
}
else if (data.code.Equals(0).Equals(false))
{
return msg = " updateDeviceAlarmMsg 【" + server + "】【" + resultStr + "】" + data.msg;
}
return "";
}
catch (Exception ex)
{
LogUtil.error(" updateDeviceAlarmMsg Error: " + ex.ToString());
}
return msg;
}
// 流水线料盘移动到皮带线时进行判断: 地址: /rest/api/qisda/device/canReelToBelt 参数:barcode: 料盘条码
private static string Addr_canReelToBelt = "/rest/api/qisda/device/canReelToBelt";
public static bool canReelToBelt(string deviceName, string barcode)
{
// 返回: // { "code":0,"msg":"ok","data":true}
// code: 0为正常,其他为异常,(未传参数, 未找到有效条码, 多个有效条码)
// msg:消息,
//data: true 可以放上皮带线 false 继续留在环形线。默认直接放到皮带线
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("barcode", barcode);
string server = GetAddr(Addr_canReelToBelt, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.debug($"{deviceName}canReelToBelt {FormUtil.GetSpanStr(DateTime.Now - startTime)} 【{server}】【{resultStr}】");
ReturnData data = JsonHelper.DeserializeJsonToObject<ReturnData>(resultStr);
if (data != null)
{
bool result = Convert.ToBoolean(data.data);
if (data.code.Equals(0))
{
if (!result)
{
LogUtil.error($"{deviceName}canReelToBelt【 {barcode}】 返回失败 :【{resultStr}】{data.msg}={data.msg}");
}
return result;
}
else if (!data.code.Equals(0))
{
LogUtil.error($"{deviceName}canReelToBelt【 {barcode}】 返回错误 :【{resultStr}】{data.msg}={data.msg}");
}
}
else
{
LogUtil.error($"{deviceName}canReelToBelt 未收到服务器反馈 {FormUtil.GetSpanStr(DateTime.Now - startTime)} 【{server}】【{resultStr}】");
}
}
catch (Exception ex)
{
LogUtil.error(deviceName + " " + ex.ToString());
}
return false;
}
public static bool IgnoreServerStop = false;
private static string Addr_putInEnable = "/rest/api/qisda/device/putInEnable";
/// <summary>
/// 流水线抓取料盘前获取是否可以继续抓取料盘
/// </summary>
/// <param name="deviceName"></param>
/// <returns></returns>
public static bool putInEnable(string deviceName)
{
if (IgnoreServerStop) return true;
// 返回: // { "code":0,"msg":"ok","data":{"putInEnable":true}}
// code: 0为正常,其他为异常
// msg:消息,
//putInEnable: false 时不允许抓取下一盘,true时允许抓取
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
//paramMap.Add("barcode", barcode);
string server = GetAddr(Addr_putInEnable, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.debug($"{deviceName}putInEnable {FormUtil.GetSpanStr(DateTime.Now - startTime)} 【{server}】【{resultStr}】");
ReturnData1 data = JsonHelper.DeserializeJsonToObject<ReturnData1>(resultStr);
if (data != null)
{
bool result = data.data.putInEnable;
if (data.code.Equals(0))
{
return result;
}
else if (!data.code.Equals(0))
{
LogUtil.error($"{deviceName} putInEnable 返回错误 :{data.msg}={data.msg}");
}
}
}
catch (Exception ex)
{
LogUtil.error(deviceName + " " + ex.ToString());
}
return false;
}
private static string Addr_stopRun = "/rest/api/qisda/device/stopRun";
/// <summary>
/// 流水线停止运行
/// </summary>
/// <param name="deviceName"></param>
/// <returns>true:停止运行</returns>
public static bool stopRun(string deviceName)
{
if (IgnoreServerStop) return false;
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
//paramMap.Add("barcode", barcode);
string server = GetAddr(Addr_stopRun, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.debug($"{deviceName}stopRun {FormUtil.GetSpanStr(DateTime.Now - startTime)} 【{server}】【{resultStr}】");
ReturnData2 data = JsonHelper.DeserializeJsonToObject<ReturnData2>(resultStr);
if (data != null)
{
bool result = data.data.stopOut;
if (data.code.Equals(0))
{
return result && data.data.unfinishedTask < 1;
}
else if (!data.code.Equals(0))
{
LogUtil.error($"{deviceName} stopRun 返回错误 :{data.msg}={data.msg}");
}
}
}
catch (Exception ex)
{
LogUtil.error(deviceName + " " + ex.ToString());
}
return false;
}
private static string Addr_getTaskInfo = "/rest/api/qisda/device/getTaskInfo";
/// <summary>
/// 获取托盘任务信息
/// </summary>
/// <param name="barcode"></param>
/// <returns>
/// result:
/// 0,ok
/// -1,异常,需要屏蔽
/// 100,异常,需要抓到NG区
/// </returns>
public static (int, taskInfo) getTaskInfo(string barcode)
{
int result = 0;
taskInfo task = new taskInfo();
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("barcode", barcode);
string server = GetAddr(Addr_getTaskInfo, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.info($"getTaskInfo {FormUtil.GetSpanStr(DateTime.Now - startTime)} 【{barcode}】【{server}】【{resultStr}】");
ReturnData3 data = JsonHelper.DeserializeJsonToObject<ReturnData3>(resultStr);
if (data != null)
{
if (data.code.Equals(0))
{
return (0, data.data);
}
else if (data.code.Equals(-1))
{
return (-1, data.data);
}
else if (data.code.Equals(100))
{
if (data.data.plateH > 0 && data.data.plateW > 0)
{
return (100, data.data);
}
else
{
return (-1, data.data);
}
}
else
{
return (-1, data.data);
}
}
}
catch (Exception ex)
{
LogUtil.error("getTaskInfo " + ex.ToString());
}
return (result, task);
}
/// <summary>
///上料机构获取料盘高度
/// </summary>
private static string Addr_getReelHeight = "/rest/api/qisda/device/getReelSize";
public static string GetReelSize(string deviceName, string barcode, out int outWidth, out int outHeight)
{
outWidth = 0;
outHeight = 0;
string msg = "";
try
{
if (String.IsNullOrEmpty(barcode))
{
return msg = deviceName + "未扫到条码";
}
///rest/api/qisda/device/getReelSize
//传入参数: barcode
//返回: {code:0, msg:"",data:{"barcode":"ABC","plateW": 7,"plateH":8}}
//code= 0 表示正常,其他为异常
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("barcode", barcode);// barcode = 扫到的条码
string server = GetAddr(Addr_getReelHeight, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.info("GetReelSize " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
//返回: { "code": 0, "msg":"ok", data: 7}
ReturnData4 serverResult = JsonHelper.DeserializeJsonToObject<ReturnData4>(resultStr);
if (serverResult == null)
{
return msg = deviceName + " GetReelSize 条码【 " + barcode + "】没有收到服务器反馈";
}
else if (serverResult.code.Equals(0).Equals(false))
{
return msg = deviceName + " GetReelSize 条码【 " + barcode + "】返回:" + "[" + serverResult.code + "]" + serverResult.msg;
}
if (serverResult.data == null)
{
return msg = deviceName + " GetReelSize 条码【 " + barcode + "】未解析到尺寸信息";
}
else
{
// data:料盘直径,= 7时升起气缸
outWidth = serverResult.data.plateW;
outHeight = serverResult.data.plateH;
LogUtil.info(deviceName + "GetReelSize 条码【 " + barcode + "】,获得尺寸:" + outWidth + "X" + outHeight);
return "";
}
}
catch (Exception ex)
{
LogUtil.error(deviceName + " ", ex);
return "GetReelSize 条码【 " + barcode + "】出错:" + ex.ToString();
}
}
//http://localhost:8080/rest/api/qisda/device/updateDisabledTray?disabledTray=E23,E25
private static string Addr_updateDisabledTray = "/rest/api/qisda/device/updateDisabledTray";
public static void disabledTray(List<TrayDisableInfo> trayDisList)
{
try
{
string disabledTray = "";
if (trayDisList == null || trayDisList.Count <= 0)
{
return;
}
foreach (TrayDisableInfo dis in trayDisList)
{
if (String.IsNullOrEmpty(disabledTray))
{
disabledTray += "E" + dis.TrayCode+"="+dis.DeviceId;
}
else
{
disabledTray += ",E" + dis.TrayCode + "=" + dis.DeviceId;
}
}
try
{
//code= 0 表示正常,其他为异常
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("disabledTray", disabledTray);// disabledTray = 禁用托盘
string server = GetAddr(Addr_updateDisabledTray, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Get(server);
LogUtil.debug("disabledTray " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
}
catch (Exception ex)
{
LogUtil.error("disabledTray = " + disabledTray + " 出错", ex);
}
}
catch (Exception ex)
{
LogUtil.error("disabledTray 出错", ex);
}
}
///rest/api/qisda/device/updateTray?trayId=xxx
private static string Addr_updateTray = "/rest/api/qisda/device/updateTray";
public static void updateTray(int trayNum)
{
Task.Factory.StartNew(delegate
{
try
{
//code= 0 表示正常,其他为异常
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("trayId", "E" + trayNum);//
string server = GetAddr(Addr_updateTray, paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Get(server);
LogUtil.debug("updateTray [" + trayNum + "] " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
}
catch (Exception ex)
{
LogUtil.error("updateTray [" + trayNum + "] 出错", ex);
}
});
}
}
public class ReturnData
{
// { "code":0,"msg":"ok","data":true}
public int code { get; set; }
public string msg { get; set; }
public object data { get; set; }
}
public class ReturnData1
{
// { "code":0,"msg":"ok","data":true}
public int code { get; set; }
public string msg { get; set; }
public PutInEnable data { get; set; }
}
public class PutInEnable
{
public bool putInEnable { get; set; }
}
public class ReturnData2
{
// { "code":0,"msg":"ok","data":true}
public int code { get; set; }
public string msg { get; set; }
public StopRun data { get; set; }
}
public class StopRun
{
public int unfinishedTask { get; set; }
public bool stopOut { get; set; }
}
public class ReturnData3
{
// { "code":0,"msg":"ok","data":true}
public int code { get; set; }
public string msg { get; set; }
public taskInfo data { get; set; }
}
//返回: {code:0, msg:"",data:{"barcode":"ABC","plateW": 7,"plateH":8}}
public class ReturnData4
{
// { "code":0,"msg":"ok","data":true}
public int code { get; set; }
public string msg { get; set; }
public reelInfo data { get; set; }
}
public class reelInfo
{
/// <summary>
/// 解析后的条码
/// </summary>
public string barcode { get; set; }
/// <summary>
/// 料盘尺寸
/// </summary>
public int plateW { get; set; }
/// <summary>
/// 料盘厚度
/// </summary>
public int plateH { get; set; }
}
public class taskInfo
{
/// <summary>
/// 是否是出入库任务
/// true:入库任务
/// false:出库任务
/// </summary>
public bool isPutInTask { get; set; }
/// <summary>
/// 解析后的条码
/// </summary>
public string barcode { get; set; }
/// <summary>
/// 库位
/// </summary>
public string posId { get; set; }
/// <summary>
/// 料盘尺寸
/// </summary>
public int plateW { get; set; }
/// <summary>
/// 料盘厚度
/// </summary>
public int plateH { get; set; }
/// <summary>
/// 是否为单独出库
/// </summary>
public bool singleOut { get; set; }
/// <summary>
/// 是否是分盘料
/// </summary>
public bool cutReel { get; set; }
/// <summary>
/// 是否是小料盘
/// </summary>
public bool smallReel { get; set; }
/// <summary>
/// 紧急料
/// </summary>
public bool urgentReel { get; set; }
/// <summary>
/// 分配的料架RFID
/// </summary>
public string rfid { get; set; }
/// <summary>
/// 分配的位置信息
/// </summary>
public int rfidLoc { get; set; }
}
public class AlarmMsg
{
//>>>name : 异常位置名称
public string name = "";
//>>>msgKey : 异常信息唯一标识
public string msgKey = "";
//>>>msgValue : 异常信息
public string msgValue = "";
public AlarmMsg(string n, string key, string value)
{
this.name = n;
this.msgKey = key;
this.msgValue = value;
}
}
public class GetPosResult
{
public string Msg = "";
/// <summary>
/// 99:暂时不能入库,需要重新获取库位。100:服务器需要更新,需要重新获取库位
/// </summary>
public int Result = 0;
/// <summary>
/// 获取超时,需要重新获取库位
/// </summary>
public bool IsTimeOut = false;
public InOutParam Param = null;
}
public class RfidData
{
//{"code":0,"msg":"ok","data":"7"}
public int code { get; set; }
public string msg { get; set; }
public Dictionary<string, string> data { get; set; }
}
public class LocStatus
{
/// <summary>
/// 料盘位置:移栽 = MOVING
/// </summary>
public static string MOVING = "MOVING";
/// <summary>
/// 料盘位置:流水线 = INLINE
/// </summary>
public static string INLINE = "INLINE";
/// <summary>
/// 料盘位置:皮带线 = INBELT
/// </summary>
public static string INBELT = "INBELT";
}
public class ServerData
{
//{"code":0,"msg":"ok","data":"7"}
public int code { get; set; }
public string msg { get; set; }
public string data { get; set; }
}
public class AfterPutData
{
//>>` {"code": 0, "msg":"ok", "data":{"cutPackageTask":"0","urgentPackageTask":"20","cutTask":"21","urgentTask":"22"}} `
//>>
//>> - code: 0为正常,其他为异常,
//>> - msg:消息,
//>> - data:为包装料仓的空闲仓位数(key为与客户端一致的料仓标识, value为空闲仓位)
//>> - cutPackageTask: 表示当前包装仓的分盘任务数
//>> - urgentPackageTask: 表示当前包装仓的紧急料任务数
//>> - cutTask: 表示流水线分盘任务数
//>> - urgentTask: 表示流水线紧急料任务数
public int code { get; set; }
public string msg { get; set; }
public TaskData data { get; set; }
}
public class TaskData
{
/// <summary>
/// urgentPackageTask: 表示当前包装仓的紧急料任务数
/// </summary>
public int urgentPackageTask { get; set; }
/// <summary>
/// cutPackageTask: 表示当前包装仓的分盘任务数
/// </summary>
public int cutPackageTask { get; set; }
/// <summary>
/// cutTask: 表示流水线分盘任务数
/// </summary>
public int cutTask { get; set; }
/// <summary>
/// urgentTask: 表示流水线紧急料任务数
/// </summary>
public int urgentTask { get; set; }
public string ToStr()
{
return "[分盘料=" + cutTask + "][紧急料=" + urgentTask + "]";
}
}
}