ServerCommunication.cs
35.7 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
using Newtonsoft.Json;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DeviceLibrary
{
public class ServerCommunication
{
volatile StoreStatus _storeStatus = StoreStatus.Debugging;
public StoreStatus storeStatus
{
get => _storeStatus;
set
{
if (_storeStatus != value)
LogUtil.info($"set storeStatus to {value}");
_storeStatus = value;
}
}
static string server = Setting_Init.Device_Server_Address;
static string CID = Setting_Init.Device_CID;
int StoreID = 1;
string StoreName = "";
string WarnMsg = "";
private System.Timers.Timer serverConnectTimer = new System.Timers.Timer();
public bool selfAudit = false;
public bool selfAuditException = false;
object serverclock = new object();
public ServerCommunication()
{
serverConnectTimer.Interval = 1000;
serverConnectTimer.AutoReset = true;
serverConnectTimer.Enabled = true;
serverConnectTimer.Elapsed += ServerConnectTimer_Elapsed;
GC.KeepAlive(serverConnectTimer);
LogUtil.info($"server:{server},cid:{CID}");
}
private void ServerConnectTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
//if (!Monitor.TryEnter(serverConnectTimer))
//{
// LogUtil.error("ServerConnectTimer_Elapsed locked");
// lockerrtime++;
// if (lockerrtime > 3)
// {
// lockerrtime = 0;
// Monitor.Exit(serverConnectTimer);
// }
// return;
//}
try
{
if (!RobotManage.isRunning)
ProcessMsg(Msg.msg);
SendLineStatus();
}
catch (Exception ex)
{
LogUtil.info($"ServerConnectTimer_Elapsed:{ex}");
}
finally
{
//Monitor.Exit(serverConnectTimer);
}
}
public void StartConnectServer()
{
//serverConnectTimer.Enabled = true;
}
public void StopConnectServer()
{
//serverConnectTimer.Enabled = false;
}
public void ProcessMsg(List<Msg> msg)
{
WarnMsg = string.Join(",", msg.Select(x =>
{
if (x.msgLevel == MsgLevel.warning || x.msgLevel == MsgLevel.alarm)
{
return x.msgtxt;
}
return null;
}
).Where(x => !string.IsNullOrEmpty(x)));
}
public void SendInStoreRequest(string[] codelist, ReelParam reel, bool printlog = false)
{
if (RobotManage.InoutDebugMode)
return;
lock (serverclock)
{
var code = ProcessCode(codelist, reel.PlateW, reel.PlateH);
Operation operation = getLineBoxStatus();
operation.op = 1;
operation.data = new Dictionary<string, object>() { { "code", code }, { "boxId", StoreID.ToString() }, { "doorReelSignal", "1" } };
operation.data.Add("singleIn", "false");
int retrytimes = 0;
retry:
Operation resultOperation = HttpHelper.Post(GetPostApi(), operation, 15000, printlog);
if (RobotManage.isRunning && (resultOperation == null || operation.seq != resultOperation.seq))
{
Thread.Sleep(1000);
//SendInStoreRequest(codelist, reel, printlog);
retrytimes++;
if (retrytimes <= 3)
goto retry;
}
ResultProcess(resultOperation);
}
}
public bool SendStoreState(string posid, StoreStatus storeStatus)
{
lock (serverclock)
{
Operation operation = getLineBoxStatus();
if (!string.IsNullOrEmpty(posid))
operation.boxStatus[StoreID].data.Add(ParamDefine.posId, posid);
operation.boxStatus[StoreID].status = (int)storeStatus;
LogUtil.info(JsonHelper.SerializeObject(operation));
if (RobotManage.InoutDebugMode)
return true;
Operation resultOperation = HttpHelper.Post(GetPostApi(), operation, 15000);
if (resultOperation == null)
{
LogUtil.error($"SendStoreState error,posid:{posid}, storeStatus:{storeStatus}");
return false;
}
if (operation.seq != resultOperation.seq)
{
LogUtil.error($"SendStoreState seq error,posid:{posid}, storeStatus:{storeStatus}");
return false;
}
LogUtil.info($"SendStoreState success,posid:{posid}, storeStatus:{storeStatus}");
ResultProcess(resultOperation);
if (storeStatus == StoreStatus.OutStoreEnd ||
storeStatus == StoreStatus.OutStoreBoxEnd ||
storeStatus == StoreStatus.InStoreEnd)
{
this.storeStatus = StoreStatus.StoreOnline;
}
}
return true;
}
public string spiltStr = "##";
private string ProcessCode(string[] codeList, int reelw, int reelh)
{
string message = "";
//= 7x12 = CODE
foreach (string str in codeList)
{
string code = str.Replace("\r", "");
code = code.Replace("\n", "");
//根据二维码开头获取固定尺寸
string codeSize = $"{reelw}x{reelh}";
if (FixtureConfig.GetCodeSize(str, out int h, out int w, out bool rcode))
{
codeSize = $"{w}x{h}";
if (!rcode)
message = message + "=" + "1+0x0-" + codeSize + "=" + code + spiltStr;
LogUtil.info($"加载到fixcode,{w}x{h},remove:{rcode}");
}
else
message = message + "=" + "1+0x0-" + codeSize + "=" + code + spiltStr;
}
return message;
}
/// <summary>
/// 获取整个料仓的状态
/// </summary>
Operation getLineBoxStatus()
{
//构建发送给服务器的对象
Operation lineOperation = new Operation();
lineOperation.msg = "";
lineOperation.alarmList = new List<AlarmInfo>();
lineOperation.cid = CID;
lineOperation.seq = ConfigAppSettings.nextSeq();
lineOperation.status = 1;
lineOperation.data = GetBtnStatus();
lineOperation.data.Add("inArea", CameraPointTest.inArea);
lineOperation.data.Add("outArea", CameraPointTest.outArea);
lineOperation.status = (int)storeStatus;
//判断如果是等待料盘拿走超时,状态改为4Warning
//if (alarmType.Equals(StoreAlarmType.IoSingleTimeOut) && StoreMove.MoveType.Equals(StoreMoveType.OutStore))
//{
// if (StoreMove.MoveStep.Equals(StoreMoveStep.SO_15_WaitTake) || StoreMove.MoveStep.Equals(StoreMoveStep.SO_16_CheckIsTake))
// {
// lineOperation.status = (int)StoreStatus.Warning;
// }
//}
BoxStatus boxStatus = new BoxStatus();
boxStatus.boxId = StoreID;
boxStatus.humidity = HumitureController.LastData.Humidity.ToString();
boxStatus.temperature = HumitureController.LastData.Temperate.ToString();
//状态
boxStatus.status = (int)storeStatus;
string sendmsg = "";
if (commandResultMsg.Count() > 0)
{
if (commandResultMsg.TryDequeue(out string msg))
{
sendmsg = msg.Trim().Trim(',');
}
}
else if (!string.IsNullOrEmpty(WarnMsg))
{
sendmsg = string.Join(",", new string[] { WarnMsg });
}
else if (!RobotManage.isRunning)
{
sendmsg = crc.GetString("Res0059","设备未启动");
}
lineOperation.msg = sendmsg;
lineOperation.msg = lineOperation.msg.Trim().Trim(',');
boxStatus.msg = lineOperation.msg;
lineOperation.msgEn = lineOperation.msg;
lineOperation.msgJp = lineOperation.msg;
lineOperation.boxStatus.Add(StoreID, boxStatus);
return lineOperation;
}
private static string api_communication = "service/store/communication"; //流水线状态通信接口
public static string GetPostApi()
{
var host = server;
if (!host.StartsWith("http://"))
{
host = "http://" + host;
}
if (!host.EndsWith("/"))
{
host = host + "/";
}
return host + api_communication;
}
int getthtime = 0;
int laststatus = 0;
public void SendLineStatus()
{
if (RobotManage.InoutDebugMode)
return;
lock (serverclock)
{
bool printlog = false;
DateTime time = DateTime.Now;
//构建发送给服务器的对象
Operation lineOperation = getLineBoxStatus();
//如果还没湿度范围,先获取
if (getthtime < 3)
{
if (Max_Humidity <= 0 || (Max_Temperature <= 0))
{
lineOperation.op = 5;
LogUtil.info(StoreName + "没有湿度预警范围,需要从服务器获取,发送OP=" + lineOperation.op);
getthtime++;
}
}
if (lineOperation.status != laststatus)
{
laststatus = lineOperation.status;
printlog = true;
}
Operation resultOperation = HttpHelper.Post(GetPostApi(), lineOperation, 700, printlog);
if (resultOperation != null)
getthtime = 0;
//LogUtil.info(JsonHelper.SerializeObject(resultOperation.data));
ResultProcess(resultOperation);
TimeSpan span = DateTime.Now - time;
if (span.TotalMilliseconds > 700)
{
LogUtil.info(StoreName + "TimerProcess[" + span.TotalMilliseconds + "]");
}
}
}
public int queueTaskCount = -1;
ConcurrentQueue<string> commandResultMsg = new ConcurrentQueue<string>();
void ResultProcess(Operation resultOperation)
{
//发送状态信息到服务器
if (resultOperation == null)
{
//判断服务端是否返回出库操作
return;
}
if (resultOperation.op.Equals(1))
{
var barcode = "";
if (resultOperation.data.ContainsKey("code"))
barcode = resultOperation.data["code"].ToString();
ReviceInStoreProcess(barcode, resultOperation);
}
else if (resultOperation.op.Equals(2))
{
ReviceOutStoreProcess(resultOperation);
}
else if (resultOperation.op.Equals(5))
{
//ProcessHumidityCMD(resultOperation);
}
ProcessHumidityCMD(resultOperation);
if (resultOperation.data != null)
{
string result = "";
Dictionary<string, object> dataMap = resultOperation.data;
if (dataMap.ContainsKey(ParamDefine.queueTaskCount))
{
var s = dataMap[ParamDefine.queueTaskCount].ToString();
if (int.TryParse(s, out int c))
{
queueTaskCount = c;
}
else
{
queueTaskCount = -1;
}
}
if (dataMap.ContainsKey(ParamDefine.selfAudit))
{
if (!string.IsNullOrEmpty(dataMap[ParamDefine.selfAudit].ToString()))
selfAudit = true;
}
else
selfAudit = false;
if (dataMap.ContainsKey(ParamDefine.selfAuditException))
{
if (dataMap[ParamDefine.selfAuditException].ToString()=="true")
selfAuditException = true;
}
else
selfAuditException = false;
if (dataMap.ContainsKey(ParamDefine.openInLock) && dataMap[ParamDefine.openInLock].Equals(ParamDefine.doit))
{
LogUtil.info(StoreName + "收到服务器命令:openInLock=doit");
IOManager.IOMove(IO_Type.Entry_Drawer_Lock,IO_VALUE.LOW);
result = "";
}
else if (dataMap.ContainsKey(ParamDefine.closeInLock) && dataMap[ParamDefine.closeInLock].Equals(ParamDefine.doit))
{
LogUtil.info(StoreName + "收到服务器命令:closeInLock=doit");
IOManager.IOMove(IO_Type.Entry_Drawer_Lock, IO_VALUE.HIGH);
if (!selfAuditException)
{
RobotManage.mainMachine.newDrawer = false;
RobotManage.mainMachine.NGInfoList = new List<ReelParam>();
Setting_Init.Runtime_NGINFOLIST = JsonConvert.SerializeObject(RobotManage.mainMachine.NGInfoList);
RobotManage.mainMachine.StoreMoveInfo.NewMove(MoveStep.StoreIn01);
RobotManage.mainMachine.StoreMoveInfo.log(StoreName + " 服务器锁定抽屉,开始入库");
}
else
{
RobotManage.mainMachine.StoreMoveInfo.log(StoreName + " 服务器锁定抽屉,有自检错误,不允许入库");
result = crc.GetString("Res0171.14f1eca7","有自检错误,仅锁入库抽屉");
}
}
if (dataMap.ContainsKey(ParamDefine.openOutLock) && dataMap[ParamDefine.openOutLock].Equals(ParamDefine.doit))
{
LogUtil.info(StoreName + "收到服务器命令:openOutLock=doit");
IOManager.IOMove(IO_Type.Out_Drawer_Lock, IO_VALUE.LOW);
result = "";
}
else if (dataMap.ContainsKey(ParamDefine.closeOutLock) && dataMap[ParamDefine.closeOutLock].Equals(ParamDefine.doit))
{
LogUtil.info(StoreName + "收到服务器命令:closeOutLock=doit");
IOManager.IOMove(IO_Type.Out_Drawer_Lock, IO_VALUE.HIGH);
result = "";
}
if (!result.Equals(""))
{
LogUtil.info(StoreName + "收到服务器命令:执行返回:" + result);
while (commandResultMsg.TryDequeue(out _)) ;
for (int i = 0; i < 10; i++)
commandResultMsg.Enqueue(result);
}
//SendLineStatus(result);
}
}
public Dictionary<string, object> GetBtnStatus()
{
Dictionary<string, object> map = new Dictionary<string, object>();
map.Add(ParamDefine.inDoorStatus, ParamDefine.disable);
map.Add(ParamDefine.outDoorStatus, ParamDefine.disable);
if (storeStatus == StoreStatus.ResetMove
|| storeStatus == StoreStatus.SuddenStop
|| storeStatus == StoreStatus.Debugging
)
return map;
if (IOManager.IOValue(IO_Type.Entry_Drawer).Equals(IO_VALUE.LOW)) {
map[ParamDefine.inDoorStatus]=ParamDefine.disable;
}
else if (IOManager.IOValue(IO_Type.Entry_Drawer_Lock).Equals(IO_VALUE.HIGH)
&& RobotManage.mainMachine.StoreMoveInfo.MoveStep == MoveStep.Wait)
{
map[ParamDefine.inDoorStatus] = ParamDefine.close;
}else if ((RobotManage.mainMachine.newDrawer || IOManager.IOValue(IO_Type.Entry_Drawer_Lock).Equals(IO_VALUE.LOW))
&& RobotManage.mainMachine.StoreMoveInfo.MoveStep == MoveStep.Wait)
{
map[ParamDefine.inDoorStatus] = ParamDefine.open;
}
if (IOManager.IOValue(IO_Type.Out_Drawer).Equals(IO_VALUE.LOW))
{
map[ParamDefine.outDoorStatus]= ParamDefine.disable;
}
else if (IOManager.IOValue(IO_Type.Out_Drawer_Lock).Equals(IO_VALUE.HIGH)
&& RobotManage.mainMachine.StoreMoveInfo.MoveStep == MoveStep.Wait)
{
map[ParamDefine.outDoorStatus] = ParamDefine.close;
}
else if (IOManager.IOValue(IO_Type.Out_Drawer_Lock).Equals(IO_VALUE.LOW)
&& RobotManage.mainMachine.StoreMoveInfo.MoveStep == MoveStep.Wait)
{
map[ParamDefine.outDoorStatus] = ParamDefine.open;
}
return map;
}
/// <summary>
/// 处理服务器入库库位消息
/// </summary>
/// <param name="message"></param>
/// <param name="resultOperation"></param>
private void ReviceInStoreProcess(string message, Operation resultOperation)
{
Dictionary<string, object> 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].ToString();
string usedCountstr= data["usedCount"].ToString();
//int storeId = int.Parse(posArray[0]);
//根据发送的posId获取位置列表
ACStorePosition position = CSVPositionReader<ACStorePosition>.GetPositon(posId);
if (position == null)
{
//出入库没有找到服务器发送的库位,需要打印日志方便查询原因
//SetWarnMsg(ResourceControl.InStoreNoPosition, message, posId);
WarnMsg = crc.GetString(L.in_store_nothave_position, "入库未找到库位:") + posId;//0505
LogUtil.info("收到服务器入库命令:入库未找到库位:二维码【" + message + "】库位【" + posId + "】");
return;
}
int usedCount = 0;
int.TryParse(usedCountstr, out usedCount);
WarnMsg = "";
JobInfo inStoreJob = new JobInfo(message, posId);
RobotManage.mainMachine.LabelingMoveInfo.MoveParam.PosID = inStoreJob.PosId;
RobotManage.mainMachine.LabelingMoveInfo.MoveParam.usedCount = usedCount;
//如果当前正在出入库中,需要记录下来,等待空闲时执行
LogUtil.info(StoreName + " 收到服务器入库命令:库位号【" + posId + ",usedCount" + usedCount + "】二维码【" + message + "】 开始入库!");
}
else
{
string msg = crc.CurrLanguage != "zh-CN"? resultOperation.msgEn: resultOperation.msg;
SendStoreState("", StoreStatus.InStoreError);
RobotManage.mainMachine.LabelingMoveInfo.MoveParam.IsNg = true;
RobotManage.mainMachine.LabelingMoveInfo.MoveParam.NgMsg = msg;
RobotManage.mainMachine.LabelingMoveInfo.MoveParam.PosID = "NG";
LogUtil.info("服务器没有正确返回库位. msg=" + msg);
}
}
public float Max_Humidity;
public float Max_Temperature;
/// <summary>
/// 处理服务器温湿度消息
/// </summary>
/// <param name="resultOperation"></param>
private void ProcessHumidityCMD(Operation resultOperation)
{
if (resultOperation.data == null)
return;
Dictionary<string, object> data = resultOperation.data;
if (data.ContainsKey(ParamDefine.maxHumidity) && data.ContainsKey(ParamDefine.maxTemperature))
{
string maxHumidity = data[ParamDefine.maxHumidity].ToString();
string maxTemp = data[ParamDefine.maxTemperature].ToString();
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());
}
}
}
/// <summary>
/// 处理服务器出库任务消息
/// </summary>
/// <param name="resultOperation"></param>
private void ReviceOutStoreProcess(Operation resultOperation)
{
DateTime time = DateTime.Now;
Dictionary<string, object> data = resultOperation.data;
if (data != null && data.ContainsKey(ParamDefine.posId)
&& data.ContainsKey(ParamDefine.plateH) && data.ContainsKey(ParamDefine.plateW))
{
string posIdStr = data[ParamDefine.posId].ToString();
string plateWStr = data[ParamDefine.plateW].ToString();
string plateHStr = data[ParamDefine.plateH].ToString();
string singleOut = data[ParamDefine.singleOut].ToString();
object code = "";
if (!data.TryGetValue("code", out code))
data.TryGetValue(ParamDefine.barcode, out code);
LogUtil.info("收到服务器出库消息:poaIs=" + posIdStr + ",platew=" + plateWStr + ",plateh=" + plateHStr + ",singleOut=" + singleOut + ",code=" + code);
char splitChar = '|';
string[] posIdArray = posIdStr.Split(splitChar);
string[] plateWArray = plateWStr.Split(splitChar);
string[] plateHArray = plateHStr.Split(splitChar);
string[] singleOutArray = singleOut.Split(splitChar);
int index = -1;
foreach (string posId in posIdArray)
{
index++;
int.TryParse(plateWArray[index], out int plateW);
int.TryParse(plateHArray[index], out int plateH);
bool isSingleOut = singleOutArray[index].ToLower().Equals("true");
//根据发送的posId获取位置列表
ACStorePosition position = CSVPositionReader<ACStorePosition>.GetPositon(posId);
if (position == null)
{
//出入库没有找到服务器发送的库位,需要打印日志方便查询原因
WarnMsg = StoreName + "出库未找库位:【" + posId + "】";
LogUtil.error("收到服务器出库命令:未找到【" + posId + "】的库位信息");
continue;
}
else
{
var ngReel = false;
object ngMsg = "";
if (data.ContainsKey("ngReel") && data["ngReel"].ToString().ToLower() == "true")
{
ngReel = true;
data.TryGetValue("ngMsg", out ngMsg);
}
RobotManage.mainMachine.AddOutStoreTask(code.ToString(), posId, ngReel, ngMsg.ToString());
}
}
TimeSpan span = DateTime.Now - time;
if (span.TotalMilliseconds > 100)
{
LogUtil.info(StoreName + "执行 ReviceOutStoreProcess 共处理了【" + span.TotalMilliseconds + "】毫秒");
}
}
}
private static string Addr_cancelPutInTask = "/service/store/cancelPutInTask";
public string cancelPutInTask(string deviceName, string barcode)
{
string msg = "";
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("barcode", barcode);
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 + "】");
ResultData data = JsonHelper.DeserializeJsonToObject<ResultData>(resultStr);
if (data == null)
{
return msg = deviceName + " cancelPutInTask【 " + barcode + "】 没有收到服务器反馈";
}
else if (data.code.Equals(0).Equals(false))
{
return msg = deviceName + " cancelPutInTask【 " + barcode + "】 :" + data.msg;
}
return "";
}
catch (Exception ex)
{
LogUtil.error(deviceName + " " + ex.ToString());
}
return msg;
}
public string DisabledPos(string posId, string barcode)
{
string msg = "";
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("posId", posId);
paramMap.Add("barcode", barcode);
string server = GetAddr("/service/store/disabledPos", paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.info("DisabledPos " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
ResultData data = JsonHelper.DeserializeJsonToObject<ResultData>(resultStr);
if (data == null)
{
return msg = " DisabledPos【 " + posId + "】 没有收到服务器反馈";
}
else if (data.code.Equals(0).Equals(false))
{
return msg = " DisabledPos【 " + posId + "】 :" + data.msg;
}
return "";
}
catch (Exception ex)
{
LogUtil.error("DisabledPos: " + ex.ToString());
}
return msg;
}
public string cancelAndDisable(string posId)
{
string msg = "";
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("posName", posId);
string server = GetAddr("/service/store/cancelAndDisable", paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Get(server);
LogUtil.info("cancelAndDisable " + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
ResultData data = JsonHelper.DeserializeJsonToObject<ResultData>(resultStr);
if (data == null)
{
return msg = " cancelAndDisable【 " + posId + "】 没有收到服务器反馈";
}
else if (data.code.Equals(0).Equals(false))
{
return msg = " cancelAndDisable【 " + posId + "】 :" + data.msg;
}
return "";
}
catch (Exception ex)
{
LogUtil.error("cancelAndDisable: " + ex.ToString());
}
return msg;
}
public JobInfo SelfAudit_getNetPos()
{
string msg = "";
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("cid", CID);
string server = GetAddr("/rest/device/selfAudit/getNetPos", paramMap);
DateTime startTime = DateTime.Now;
string resultStr = HttpHelper.Post(server, "");
LogUtil.info("SelfAudit:" + FormUtil.GetSpanStr(DateTime.Now - startTime) + " 【" + server + "】【" + resultStr + "】");
ResultData data = JsonHelper.DeserializeJsonToObject<ResultData>(resultStr);
if (data == null)
{
return null;
}
else if (data.code.Equals(0).Equals(false))
{
return null;
}
try
{
//data 中包含:posName 库位号,barcode 条码,batchNo 盘点批次号
var d = JsonConvert.DeserializeObject<Dictionary<string, string>>(data.data.ToString());
var posName = d["posName"];
var barcode = d["barcode"];
var batchNo = d["batchNo"];
var j = new JobInfo(barcode, posName);
j.batchNo = batchNo;
return j;
}
catch (Exception ex) {
LogUtil.info("SelfAudit:" + data.data.ToString());
return null;
}
}
catch (Exception ex)
{
LogUtil.error("SelfAudit: " + ex.ToString());
}
return null;
}
public string SelfAudit_posOutEnd(string posName)
{
string msg = "";
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("posName", posName);
string server = GetAddr("/rest/device/selfAudit/posOutEnd", paramMap);
string resultStr = HttpHelper.Post(server, "");
ResultData data = JsonHelper.DeserializeJsonToObject<ResultData>(resultStr);
if (data == null)
return msg = " DisabledPos【 " + posName + "】 没有收到服务器反馈";
else if (data.code.Equals(0).Equals(false))
return msg = " DisabledPos【 " + posName + "】 :" + data.msg;
return "";
}
catch (Exception ex)
{
LogUtil.error("DisabledPos: " + ex.ToString());
}
return msg;
}
public string SelfAudit_posSelfAuditEnd(string posName,string barcode,string actualBarcode)
{
string msg = "";
try
{
Dictionary<string, string> paramMap = new Dictionary<string, string>();
paramMap.Add("posName", posName);
paramMap.Add("barcode", barcode);
paramMap.Add("actualBarcode", actualBarcode);
string server = GetAddr("/rest/device/selfAudit/posSelfAuditEnd", paramMap);
string resultStr = HttpHelper.Post(server, "");
ResultData data = JsonHelper.DeserializeJsonToObject<ResultData>(resultStr);
if (data == null)
return msg = " posSelfAuditEnd【 " + posName + "】没有收到服务器反馈";
else if (data.code.Equals(0).Equals(false))
return msg = " posSelfAuditEnd【 " + posName + "】:" + data.msg;
return resultStr;
}
catch (Exception ex)
{
LogUtil.error("DisabledPos: " + ex.ToString());
}
return msg;
}
private static string GetAddr(string addr, Dictionary<string, string> paramsMap)
{
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;
}
}
public class ResultData
{
//{"code":0,"msg":"ok","data":"7"}
public int code { get; set; }
public string msg { get; set; }
//public Dictionary<string, object> data { get; set; }
public object data { get; set; }
}
/// <summary>
///1=设备联机(正常就绪)(入库后,BOX恢复原始状态)(出库后,移载装置恢复原始状态),
///2=急停,3=故障,4=警告,5=调试
/// 6=入库执行中,7=入仓完成,8=入仓失败
/// 9=出库执行,10=出仓完成,11=出库失败
/// </summary>
public enum StoreStatus
{
None = 0,
/// <summary>
/// 1=设备联机(正常就绪)(入库后,BOX恢复原始状态)(出库后,移载装置恢复原始状态),
/// </summary>
StoreOnline = 1,
/// <summary>
///2=急停中
/// </summary>
SuddenStop = 2,
/// <summary>
/// 3=故障中
/// </summary>
InTrouble = 3,
/// <summary>
/// 4=警告
/// </summary>
Warning = 4,
/// <summary>
/// 5=设备调试中
/// </summary>
Debugging = 5,
/// <summary>
/// 6=入库执行中
/// </summary>
InStoreExecute = 6,
/// <summary>
/// 7= 入仓位完成(料仓Box把料盘放入对应的库位中,装置还未恢复原始状态)
/// </summary>
InStoreEnd = 7,
/// <summary>
/// 8=入库失败
/// </summary>
InStoreFaild = 8,
/// <summary>
/// 9=出库执行中",
/// </summary>
OutStoreExecute = 9,
/// <summary>
///10= 出仓位完成( 料盘已经放到Box门口)
/// </summary>
OutStoreBoxEnd = 10,
/// <summary>
///11=出库完成
/// </summary>
OutStoreEnd = 11,
/// <summary>
/// 12=移栽出库移栽过程中(移栽完成后变成OnLine)
/// </summary>
OutMoveExecute = 12,
/// <summary>
/// 重置中(原点返回和重置都发此状态)
/// </summary>
ResetMove = 13,
/// <summary>
/// 扫码入库失败
/// </summary>
InStoreError = 14,
}
}