AutomaticBaiting_Partial.cs
34.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public partial class AutomaticBaiting
{
private static int StartMovePosition = 0;
private static int EndMovePosition = 0;
//public static int AutoAxisIsMove = 0;
private static void ACAxisSpeedMove(ConfigMoveAxis moveAxis, int targetSpeed,string targetSingle)
{
//AutoAxisIsMove = 1;
StartMovePosition = ACServerManager.GetActualtPosition(moveAxis.DeviceName, moveAxis.GetAxisValue());
EndMovePosition = StartMovePosition;
LogUtil.debug("当前坐标:"+StartMovePosition+",批量上料轴开始匀速"+targetSpeed+"上升");
StoreMove.WaitList.Add(WaitResultInfo.WaitBatchAxisStop(moveAxis,0, targetSingle));
BatchAxisController.StartCheck(targetSingle);
ACServerManager.SpeedMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetSpeed);
}
private static void ACAxisAbsMove(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed)
{
StoreMove.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, targetPosition, targetSpeed));
moveAxis.TargetPosition = targetPosition;
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
}
private static void ACAxisHomeMove(ConfigMoveAxis moveAxis)
{
moveAxis.TargetPosition = 0;
LogUtil.debug(Name + moveAxis.DisplayStr + "speed[" + moveAxis.TargetSpeed + "]开始原点返回");
ACServerManager.HomeMove(moveAxis.DeviceName, (short)moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
StoreMove.WaitList.Add(WaitResultInfo.WaitAxis(moveAxis, true));
}
private static bool ACHomeMoveIsEnd(ConfigMoveAxis moveAxis, out string msg)
{
msg = "";
if (ACServerManager.IsHomeMoveEnd(moveAxis.DeviceName, moveAxis.GetAxisValue()))
{
//原点完成并且位置=0
int outCount = ACServerManager.GetActualtPosition(moveAxis.DeviceName, moveAxis.GetAxisValue());
int errorCount = Math.Abs(outCount);
if (errorCount > moveAxis.CanErrorCountMax)
{
//判断是否需要重新运动
if (StoreMove.CanWhileCount > 0)
{
LogUtil.error(Name + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],重新回原点,剩余[" + StoreMove.CanWhileCount + "]次");
ACServerManager.HomeMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), moveAxis.HomeHighSpeed);
StoreMove.CanWhileCount--;
}
else
{
// msg = Name + " storeMoveStep=" + StoreMove.MoveStep + moveAxis.DisplayStr + "收到原点完成信号,当前位置[" + outCount + "],误差过大,需要报警";
SetWarnMsgAndLog(ResourceControl.AxisHomeMoveAlarm, StoreMove.MoveStep + "", moveAxis.GetNameStr(), outCount + "");
msg = WarnObj.WarnMsg;
LogUtil.error(msg, 100);
return false;
}
}
return true;
}
return false;
}
private static void CheckWait()
{
List<WaitResultInfo> list = StoreMove.WaitList;
if (list.Count <= 0)
{
StoreMove.EndStepWait();
return;
}
try
{
//当等待超过一分钟时,需要打印提示
TimeSpan span = DateTime.Now - StoreMove.LastSetpTime;
string NotOkMsg = "";
int waitType = 0;
bool isOk = !StoreMove.OneWaitCanEndStep;
foreach (WaitResultInfo wait in list)
{
if (wait.IsEnd)
{
continue;
}
NotOkMsg = wait.ToStr();
waitType = wait.WaitType;
if (wait.WaitType == (int)Wait_Type.AxisMove_1)
{
bool isAlarm = false;
wait.IsEnd = AxisMoveISEnd(wait, ref isAlarm);
if (isAlarm)
{
return;
}
}
else if (wait.WaitType == (int)Wait_Type.IOMove_2)
{
wait.IsEnd = IOManager.IOValue(wait.IoType).Equals(wait.IoValue);
//int timeOutMs = StoreManager.Config.IOSingle_TimerOut;
//timeOutMs = 20;
//if ((!wait.IsEnd) && span.TotalMilliseconds > timeOutMs)
//{
// ConfigIO io = StoreManager.Config.getWaitIO(wait.IoType);
// WarnMsg = "[" + StoreMove.MoveStep + "] 等待[" + io.ElectricalDefinition + "_" + io.Explain + "=" + wait.IoValue + "]超时";
// StoreManager.Store.Alarm(StoreAlarmType.BatchIoTimeOut, io.ElectricalDefinition, WarnMsg, StoreMove.MoveType);
// LogUtil.error(WarnMsg, 101);
// isOk = false;
// break;
//}
//如果是气缸动作,若Do未输出,重新写一遍
if (!wait.IsEnd && span.TotalSeconds > 2)
{
if (wait.IoType.Equals(IO_Type.SuckingDisc_Down) || wait.IoType.Equals(IO_Type.SuckingDisc_Up))
{
IO_VALUE doValue = IOManager.DOValue(wait.IoType);
if (!doValue.Equals(wait.IoValue))
{
LogUtil.error("等待[" + NotOkMsg + "],重写DO(" + wait.IoType + "=" + wait.IoValue + ")");
IOManager.IOMove(wait.IoType, wait.IoValue);
string ioType = wait.IoType.Equals(IO_Type.SuckingDisc_Down) ? IO_Type.SuckingDisc_Up : IO_Type.SuckingDisc_Down;
IO_VALUE ioValue = wait.IoValue.Equals(IO_VALUE.LOW) ? IO_VALUE.HIGH : IO_VALUE.LOW;
LogUtil.error("等待[" + wait.ToStr() + "],重写气缸DO(" + ioType + "=" + ioValue + ")");
IOManager.IOMove(ioType, ioValue);
}
}else if (wait.IoType.Equals(IO_Type.SuckingDisc_Air))
{
string ioType = IO_Type.SuckingDisc_Work;
IO_VALUE doValue = IOManager.DOValue(ioType);
if (!doValue.Equals(wait.IoValue))
{
LogUtil.error("等待[" + NotOkMsg + "],重写DO(" + ioType + "=" + wait.IoValue + ")");
IOManager.IOMove(ioType, wait.IoValue);
}
}
}
}
else if (wait.WaitType == (int)Wait_Type.Time_3)
{
wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
}
else if (wait.WaitType == (int)Wait_Type.ShuoKe_5)
{
}
else if (wait.WaitType == (int)Wait_Type.AxisHomeSingle_6)
{
IO_VALUE value = (IO_VALUE)ACServerManager.GetHomeSingle(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue());
wait.IsEnd = wait.IoValue.Equals(value);
}
else if (wait.WaitType == (int)Wait_Type.BatchAxisMove_10)
{
wait.IsEnd = BatchAxisIsEnd(wait,span);
if (wait.IsEnd)
{
BatchAxisController.StopCheck();
}
}
else if (wait.WaitType == (int)Wait_Type.ScanCode_11)
{
wait.IsEnd = (LastCode.Equals("").Equals(false));
}
else if (wait.WaitType == (int)Wait_Type.StoreRuning_13)
{
wait.IsEnd = (StoreManager.Store.storeRunStatus.Equals(StoreRunStatus.Runing) && StoreManager.Store.StoreMove.MoveType.Equals(StoreMoveType.None));
}
if (wait.IsEnd)
{
if (StoreMove.OneWaitCanEndStep)
{
isOk = true;
break;
}
}
else
{
if (!StoreMove.OneWaitCanEndStep)
{
isOk = false;
break;
}
}
}
if (isOk)
{
StoreMove.EndStepWait();
}
else if (span.TotalSeconds > StoreMove.TimeOutSeconds)
{
string msg = "[" + StoreMove.MoveStep + "]" + ResourceControl.GetString(ResourceControl.TimeOut, "超时") + " [" + NotOkMsg + "][" + Math.Round(span.TotalSeconds, 0) + "秒]";
string newType = ResourceControl.MoveTimeOut + "_" + waitType.ToString().PadLeft(2, '0');
SetWaitWarnMsg(msg, newType,StoreMove.MoveStep+"", Math.Round(span.TotalSeconds, 0) + "");
LogUtil.error(msg, 102);
StoreManager.Store.Alarm(StoreAlarmType.BatchIoTimeOut, "", msg, StoreMove.MoveType);
}
}
catch (Exception ex)
{
LogUtil.error(Name + "CheckWait出错:" + ex.StackTrace);
}
}
/// <summary>
/// 判断AC伺服电机轴是否运动完成
/// </summary>
private static bool ACAxisMoveIsEnd(ConfigMoveAxis moveAxis, int targetPosition, int targetSpeed, out string msg)
{
msg = "";
bool isOk = ACServerManager.GetBusyStatus(moveAxis.DeviceName, moveAxis.GetAxisValue()).Equals(0);
if (isOk)
{
int outCount = ACServerManager.GetActualtPosition(moveAxis.DeviceName, moveAxis.GetAxisValue());
int errorCount = Math.Abs(outCount - targetPosition);
if (errorCount <= moveAxis.CanErrorCountMax)
{
return true;
}
//判断是否需要重新运动
if (StoreMove.CanWhileCount > 0)
{
LogUtil.error(Name + moveAxis.DisplayStr + "目标[" + targetPosition + "]当前[" + outCount +
"],误差过大,重新运动,剩余[" + StoreMove.CanWhileCount + "]次");
ACServerManager.AbsMove(moveAxis.DeviceName, moveAxis.GetAxisValue(), targetPosition, targetSpeed);
StoreMove.CanWhileCount--;
}
else
{
// msg = Name + moveAxis.DisplayStr + "目标[" + targetPosition + "]当前[" + outCount + "],误差过大,需要报警";
SetWarnMsgAndLog(ResourceControl.AxisMoveAlarm, StoreMove.MoveStep + "", moveAxis.GetNameStr(), targetPosition + "", outCount + "");
msg = WarnObj.WarnMsg;
LogUtil.error(msg);
}
}
return false;
}
private static bool AxisMoveISEnd(WaitResultInfo wait ,ref bool isAlarm)
{
isAlarm = false;
string msg = "";
if (wait.IsHomeMove)
{
wait.IsEnd = ACHomeMoveIsEnd(wait.AxisInfo, out msg);
}
else
{
wait.IsEnd = ACAxisMoveIsEnd(wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
}
if (!msg.Equals(""))
{
isAlarm = true;
// WarnMsg = msg;
StoreManager.Store.Alarm(StoreAlarmType.BatchAxisAlarm, StoreManager.Store.GetAlarmCodeByAxis(wait.AxisInfo).ToString(), WarnObj.WarnMsg, StoreMove.MoveType);
}
return wait.IsEnd;
}
/// <summary>
/// 判断批量上下轴是否运动完成
/// </summary>
/// <param name="wait"></param>
/// <returns></returns>
public static bool BatchAxisIsEnd(WaitResultInfo wait,TimeSpan startSpan)
{
bool result = false;
if (IOManager.IOValue(wait.IoType).Equals(wait.IoValue))
{
LogUtil.debug(wait.ToStr() + " 检测到 " + wait.IoType + "="+wait.IoValue+",可以停止运动");
result = true;
}
else if (IOManager.IOValue(IO_Type.BatchAxis_Limit).Equals(IO_VALUE.HIGH))
{
LogUtil.debug(wait.ToStr() + " 检测到正极限信号,可以停止运动");
result = true;
}
else if (wait.TargetPosition > 0)
{
bool MoveEnd = ACServerManager.GetBusyStatus(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue()).Equals(0);
int outCount = ACServerManager.GetActualtPosition(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue());
int errorCount = Math.Abs(outCount - wait.TargetPosition);
if (MoveEnd && errorCount < wait.AxisInfo.CanErrorCountMax)
{
result = true;
}
}
if (result)
{
LogUtil.debug(wait.ToStr() + " 停止运动");
ACServerManager.SuddenStop(wait.AxisInfo);
}
else if (startSpan.TotalSeconds > 2)
{
TimeSpan span = DateTime.Now - AxisResetMoveTime;
if ((AutoBaitingStatus.Equals(StoreRunStatus.Busy) || AutoBaitingStatus.Equals(StoreRunStatus.Reset)) && span.TotalSeconds > 10)
//if (AutoBaitingStatus.Equals(StoreRunStatus.Busy) && StoreMove.CanWhileCount > 0)
{
AxisResetMoveTime = DateTime.Now;
//如果批量轴已经停止运动,重新开始
bool isEnd = ACServerManager.GetBusyStatus(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue()).Equals(0);
if (isEnd)
{
ACServerManager.SuddenStop(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue());
Thread.Sleep(2000);
if (wait.TargetPosition <= 0)
{
LogUtil.error(wait.ToStr() + " 未收到信号且停止运动,重新匀速" + StoreManager.Config.BatchAxis_SlowSpeed + "运动,剩余[" + StoreMove.CanWhileCount + "]次");
ACServerManager.SpeedMove(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue(), StoreManager.Config.BatchAxis_SlowSpeed);
}
else
{
LogUtil.error(wait.ToStr() + " 未收到信号且停止运动,绝对运动" + wait.TargetPosition + " ,剩余[" + StoreMove.CanWhileCount + "]次");
ACServerManager.AbsMove(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue(), wait.TargetPosition, StoreManager.Config.BatchAxis_SlowSpeed);
}
//判断是否需要重新运动
StoreMove.CanWhileCount--;
}
}
}
return result;
}
private static DateTime AxisResetMoveTime = DateTime.Now;
#region Halcon扫码枪代码
public bool IsTestCamera = false;
private static string spiltStr = "##";
public static void GetCameraCode()
{
Task.Factory.StartNew(delegate ()
{
IOManager.IOMove(IO_Type.CameraLight_Power, IO_VALUE.HIGH);
string message = "";
List<string> codeList = CodeManager.CameraScan();
if (codeList.Count <= 0)
{
codeList = CodeManager.CameraScan();
}
//需要过滤重复的二维码
List<string> hasList = new List<string>();
foreach (string str in codeList)
{
//message = message + "=1+0x0-" + LastSize + "x" + LastHeight + " =" + str + spiltStr;
if (!hasList.Contains(str))
{
hasList.Add(str);
message = message + spiltStr + str;
}
}
LastCodeList = hasList;
LastCode = message;
if (LastCode.Equals("") && (StoreManager.Store.IsDebug ))
{
LastCode = "NoCode";
LogUtil.info(Name + "模拟二维码:NoCode");
}
if (LastCode.Equals(""))
{
StoreManager.Store.CodeOrInoutMsg =ResourceControl.GetString(ResourceControl.InStoreNoCode, "未扫到二维码,需要将料盘送出");
LogUtil.error("未扫到二维码,需要将料盘送出");
}
else
{
LogUtil.debug("扫到二维码:" + LastCode);
}
IOManager.IOMove(IO_Type.CameraLight_Power, IO_VALUE.LOW);
// StoreManager.Store.onCodeReceived(message);
});
}
public static string ProcessBarcode(List<string> codeList )
{
// p/n 的码是P打头,SKID码是2T475打头
// RI;PN;QTY
string split = ";";
string result = "";
try
{
List<string> rCodes = new List<string>();
string pCode = GetCodeByStart(codeList, "P");
string riCode = GetCodeByStart(codeList, "2T475");
if (riCode.Equals(""))
{
return result;
}
else
{
result = riCode + split + pCode + split + "1";
}
}catch(Exception ex)
{
LogUtil.error("ProcessBarcode出错:"+ex.ToString());
}
return result;
}
private static string GetCodeByStart(List<string> codeList, string start)
{
List<string> pCode = (from m in codeList where m.StartsWith(start) select m).ToList<string>();
if (pCode.Count > 0)
{
return pCode[0];
}
return "";
}
#endregion
private static void CylinderMove(string highType, string lowType, bool isWait)
{
if (isWait)
{
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(lowType, IO_VALUE.LOW));
StoreMove.WaitList.Add(WaitResultInfo.WaitIO(highType, IO_VALUE.HIGH));
}
IOManager.IOMove(lowType, IO_VALUE.LOW);
IOManager.IOMove(highType, IO_VALUE.HIGH);
}
public static string ProcessMsg()
{
string msg = "";
//string[] codeArray = LastCode.Split(new string[] { spiltStr});
if (LastCodeList.Count > 0)
{
string codeInfo = ProcessBarcode(LastCodeList);
if (codeInfo.Equals(""))
{
foreach (string code in LastCodeList)
{
if (!code.Equals(""))
{
msg = msg + "=1+0x0-" + LastWidth + "x" + LastHeight + "=" + code + spiltStr;
}
}
}
else
{
msg = "=1+0x0-" + LastWidth + "x" + LastHeight + "=" + codeInfo;
}
}
else if (!LastCode.Equals(""))
{
msg = msg + "=1+0x0-" + LastWidth + "x" + LastHeight + "=" + LastCode + spiltStr;
}
return msg;
}
//=1+0x0-13x24=201810220856;025;5N02018101;121;700012865;92498;1800;##
private static void GetInStorePosId(string message)
{
try
{
//if (StoreManager.Store.IsDebug || StoreManager.Store.autoNext)
if (StoreManager.Store.IsDebug )
{
string posId = ConfigAppSettings.GetValue(Setting_Init.DebugPosId);
if (!posId.Equals(""))
{
string type = StoreManager.Store.autoNext ? "自动出入库" : "入库模拟调试";
LogUtil.info(Name + type + " ,模拟库位号【" + posId + "】");
if (StoreManager.Store.CanStarInOut())
{
LastPosId = posId;
InOutStoreParam param = new InOutStoreParam(message, posId, LastHeight, LastWidth);
bool result = StoreManager.Store.StartInStoreMove(param, true);
//如果当前正在出入库中,需要记录下来,等待空闲时执行
LogUtil.info(Name + type + " :库位号【" + posId + "】二维码【" + message + "】 开始入库!");
}
else
{
LogUtil.info(Name + type + " :库位号【" + posId + "】二维码【" + message + "】 正在忙碌中,无法入库!");
}
//清理库位号,防止重复入库
if (StoreManager.Store.autoNext)
{
ConfigAppSettings.SaveValue(Setting_Init.DebugPosId, "");
}
return;
}
}
else
{
InOutStoreParam param = GetInStoreParam(Name, message);
if (param == null)
{
return;
}
//TODO:判断BOX是否处于可以入库状态,如果调试或急停中,需要返回给服务器;
if (StoreManager.Store.CanStarInOut())
{
bool result = StoreManager.Store.StartInStoreMove(param, true);
//如果当前正在出入库中,需要记录下来,等待空闲时执行
LogUtil.info(Name + " 收到服务器入库命令:库位号【" + param.PositionNum + "】二维码【" + message + "】 开始入库!");
}
else
{
LogUtil.info(Name + " 收到服务器入库命令:库位号【" + param.PositionNum + "】二维码【" + message + "】 正在忙碌中,无法入库!");
}
}
}
catch (Exception ex)
{
LogUtil.error(Name + ex.StackTrace);
}
}
public static InOutStoreParam GetInStoreParam(string LogName, string message)
{
message = ScanCodeManager.ReplaceCode(message);
if (message.Equals("") || string.IsNullOrEmpty(message))
{
CodeMsg =ResourceControl.GetString(ResourceControl.NoCodeMsg, "没有收到二维码信息,请重新放入料盘");
LogUtil.info(LogName + "没有收到二维码信息,请重新放入料盘");
return null;
}
if (StoreManager.Store.storeRunStatus.Equals(StoreRunStatus.Wait))
{
LogUtil.info(LogName + "【 " + message + "】,设备未启动,不需要发送服务器");
return null;
}
LogUtil.info(LogName + "【 " + message + "】,发送给服务器获取入库PosID");
Operation operation = StoreManager.Store.getLineBoxStatus();
operation.op = 1;
operation.data.Add("code", message);
operation.data.Add("boxId", StoreManager.Store.StoreID.ToString());
if (LastHeight.Equals(0) && LastWidth.Equals(0))
{
//singleIn 单盘入库
operation.data.Add("singleIn", "true");
}
else
{
operation.data.Add("singleIn", "false");
}
string autoposId = StoreManager.Store.GetAutoPosid(true);
if (StoreManager.Store.autoNext && (!String.IsNullOrEmpty(autoposId)))
{
operation.data.Add(ParamDefine.inPos, autoposId);
LogUtil.debug("添加自动入库库位号:" + autoposId);
}
string server = ConfigAppSettings.GetValue(Setting_Init.http_server);
Operation resultOperation = HttpHelper.Post(StoreManager.GetPostApi(server), operation, false);
if (resultOperation == null)
{
LogUtil.info(LogName + "二维码【" + message + "】没有收到服务器反馈!");
return null;
}
else if (!string.IsNullOrEmpty(resultOperation.msg))
{
LogUtil.info(LogName + "服务器反馈 二维码【" + message + "】【" + autoposId + "】 :" + resultOperation.msg);
return null;
}
Dictionary<string, string> data = resultOperation.data;
if (data != null && data.ContainsKey(ParamDefine.posId) && data.ContainsKey(ParamDefine.plateH) && data.ContainsKey(ParamDefine.plateW))
{
//服务器返回时有:posId库位编号,plateW:料盘宽度,plateH:料盘高度,
//postId格式BoxId#位置
string posId = data[ParamDefine.posId];
try
{
int plateW = Convert.ToInt32(data[ParamDefine.plateW]);
int plateH = Convert.ToInt32(data[ParamDefine.plateH]);
string singleOut = data[ParamDefine.singleOut];
//bool isSingleOut = singleOut.ToLower().Equals("true");
string[] posArray = posId.Split('#');
if (!(posArray.Length == 2))
{
// WarnMsg = Name + ResourceControl.GetString(ResourceControl.InStoreError, "入库库位格式错误:") + "【" + message + "】【" + posId + "】";
SetWarnMsgAndLog(ResourceControl.InStoreError, message, posId);
// LogUtil.error("服务器反馈 入库库位格式错误:二维码【" + message + "】库位【" + posId + "】");
return null;
}
int storeId = int.Parse(posArray[0]);
//根据发送的posId获取位置列表
AutoStorePosition position = CSVPositionReader<AutoStorePosition>.GetPositon(posId);
if (position == null)
{ //出入库没有找到服务器发送的库位,需要打印日志方便查询原因
// WarnMsg = ResourceControl.GetString(ResourceControl.InStoreNoPosition, "入库未找到库位:") + "【" + message + "】【" + posId + "】 ";
SetWarnMsgAndLog(ResourceControl.InStoreNoPosition, message, posId);
// LogUtil.error("服务器反馈 入库未找到库位:二维码【" + message + "】库位【" + posId + "】");
return null;
}
LastPosId = posId;
InOutStoreParam param = new InOutStoreParam(message, posId, plateH, plateW);
return param;
}
catch (Exception ex)
{
LogUtil.error(LogName + "解析服务发送的入库【" + posId + "】出错" + ex.StackTrace);
}
}return null;
}
public static Dictionary<string, string> GetBtnStatus()
{
Dictionary<string, string> map = new Dictionary<string, string>();
map.Add(ParamDefine.openLock, ParamDefine.disable);
map.Add(ParamDefine.startBatchIn, ParamDefine.disable);
map.Add(ParamDefine.closeLock, ParamDefine.disable);
map.Add(ParamDefine.takeOutReel, ParamDefine.disable);
map.Add(ParamDefine.confirmReelOut, ParamDefine.disable);
map.Add(ParamDefine.singleReelIn, ParamDefine.disable);
if ( DoorStatus.Equals(2))
{
map.Add(ParamDefine.doorStatus, ResourceControl.GetString(ResourceControl.doorClose, "Door lock close"));
}
else
{
map.Add(ParamDefine.doorStatus, ResourceControl.GetString(ResourceControl.doorOpen, "Doorlock open"));
}
if (IsWaitTragGo && (IsGetTrayGo.Equals(false)))
{
map[ParamDefine.confirmReelOut] = ParamDefine.enable;
}
else if (CanOpenBatchDoor())
{
if (DoorStatus.Equals(2))
{
if (BatchOutStoreCount > 0)
{
map[ParamDefine.takeOutReel] = ParamDefine.enable;
}
else
{
map[ParamDefine.openLock] = ParamDefine.enable;
map[ParamDefine.singleReelIn] = ParamDefine.enable;
}
}
else if(IOManager.IOValue(IO_Type.DoorClose_LoadMaterial).Equals(IO_VALUE.HIGH))
{
map[ParamDefine.closeLock] = ParamDefine.enable;
map[ParamDefine.startBatchIn] = ParamDefine.enable;
}
}
else if (DoorStatus.Equals(1) && StoreMove.MoveType.Equals(StoreMoveType.OutStore) && IOManager.IOValue(IO_Type.DoorClose_LoadMaterial).Equals(IO_VALUE.HIGH))
{
//出库过程中 可以关门
map[ParamDefine.closeLock] = ParamDefine.enable;
}
return map;
}
public static string doOpenDoor()
{
if ( CanOpenBatchDoor())
{
BatchDoorOpen(false);
IsNeedStartInout = false;
return "";
}
else
{
return ResourceControl.GetString(ResourceControl.CnotOpen, "BUSY,open doorlock failure");
}
}
public static string doStartBatchIn()
{
if (!DoorIsClose())
{
return ResourceControl.GetString(ResourceControl.batchInError, "Batch storing Error: Close feeding device");
}
if (IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
{
return ResourceControl.GetString(ResourceControl.batchInError2, "Batch storing Error: gripper full, check before restoring");
}
StopOutProcess();
BatchDoorClose(false);
Reset(false, true);
return "";
}
public static string doTakeReel()
{
if (CanOpenBatchDoor())
{
if (BatchOutStoreCount > 0 && BatchOutStoreHeight > 0)
{
// BatchDoorOpen(false);
return StartOut();
//return "";
}
else
{
return (ResourceControl.GetString(ResourceControl.GetError, "Providing Error: BUSY, open doorlock failure"));
}
}
else
{
return (ResourceControl.GetString(ResourceControl.GetError2, "Providing Error: BUSY, open doorlock failure"));
}
}
public static string doCloseDoor()
{
if (! DoorIsClose())
{
return (ResourceControl.GetString(ResourceControl.CloseError, "Door lock Error: Close feeding device"));
}
StopOutProcess();
BatchDoorClose(false);
Reset(false,false);
return "";
}
public static string doConfirmReelGo()
{
LogUtil.info(ResourceControl.GetString(ResourceControl.TakeTrayOut, "Take out reel manually"));
//判断IO是否正确
if (!IOManager.IOValue(IO_Type.TrayCheck_Door).Equals(WaitIoValue))
{
if (WaitIoValue.Equals(IO_VALUE.LOW))
{
return ResourceControl.GetString(ResourceControl.TakeTrayOut, "Take out reel manually") + " 失败,请先拿走料盘" ;
}
//else
//{
// return ResourceControl.GetString(ResourceControl.TakeTrayOut, "Take out reel manually") + " 失败,请先放入料盘";
//}
}
IsWaitTragGo = false;
IsGetTrayGo = true;
return "";
}
public static string doSingleReelIn()
{
string defaultPosId = ConfigAppSettings.GetValue(Setting_Init.SinglePosId).Trim();
if (StoreManager.Store.PositionNumList.Contains(defaultPosId))
{
bool result = StoreManager.Store.StartInStoreMove(new InOutStoreParam("", defaultPosId), false, true);
if (!result)
{
return ResourceControl.GetMsgStr("启动单盘入库失败:") + StoreManager.Store.CodeOrInoutMsg;
}
}
else
{
return (ResourceControl.GetMsgStr("请先正确配置:") + Setting_Init.SinglePosId);
}
return "";
}
}
}