InputEquip_OutStore.cs 39.8 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
using Asa;
using CodeLibrary;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Configuration;
using System.Web.Routing;
using System.Windows.Forms;

namespace OnlineStore.DeviceLibrary
{
    partial class InputEquip
    {
        #region 出库
        private DateTime startOutTime = DateTime.Now;
        bool outstoreNG = false;
        int maxCnt = ConfigAppSettings.GetIntValue(Setting_Init.MaxCntInBox, 15);
        public override bool StartOutstore(InOutParam param)
        {
            if (!NoAlarm())
            {
                SetWarnMsg("报警中,无法开始出库:" + param.PosInfo.ToStr());
                return false;
            }
            if (!IsInSafePos())
            {
                SetWarnMsg("机器人不在安全位置。出库失败:" + param.PosInfo.ToStr());
                return false;
            }

            if (MoveInfo.MoveType.Equals(MoveType.None))
            {
                outstoreNG = false;
                //获取料仓两个出料口信息
                List<BoxInfo> boxInfos = SServerManager.GetOutStateInfo();
                if (boxInfos == null)
                {
                    SetWarnMsg("无法获取出料口信息,无法开始出库:" + param.PosInfo.ToStr());
                    return false;
                }
                BoxA.UpdateBoxInfo(boxInfos);
                BoxB.UpdateBoxInfo(boxInfos);
                bool canOutstore = false;
                if (BufferDataManager.LabelInfo != null)
                {
                    outstoreNG = BufferDataManager.LabelInfo.outstoreNG;
                    if (!outstoreNG)//有贴标信息
                    {
                        PrintLabel.LabelInfo = SServerManager.GetFeederInfo(BufferDataManager.LabelInfo.barcode);
                        if (PrintLabel.LabelInfo != null)
                        {
                            if (boxInfos.Count == 0)//无料箱绑定,默认A周转箱
                            {
                                if (PrintLabel.LabelInfo.side.Equals("T"))
                                {
                                    param.ShelfType = 1;
                                    canOutstore = true;
                                }
                                else if (PrintLabel.LabelInfo.side.Equals("B"))
                                {
                                    param.ShelfType = 2;
                                    canOutstore = true;
                                }
                            }
                            else
                            {
                                var box = boxInfos.Find(s => PrintLabel.LabelInfo.hSerial.Equals(s.hSerial) && (s.boxBCount < maxCnt && s.boxTCount < maxCnt));
                                if (box != null)//相同工单且有空位
                                {
                                    TurnoverBox turnoverBox = turnoverBoxes.Find(s => s.outLet.Equals(box.outlet));
                                    if (turnoverBox.ReadBoxId())
                                    {
                                        if (turnoverBox.BoxId.Equals(box.rfid))
                                        {
                                            if (turnoverBox.outLet.Equals("A"))
                                            {
                                                if (PrintLabel.LabelInfo.side.Equals("T"))
                                                {
                                                    param.ShelfType = 1;
                                                    canOutstore = true;
                                                }
                                                else if (PrintLabel.LabelInfo.side.Equals("B"))
                                                {
                                                    param.ShelfType = 2;
                                                    canOutstore = true;
                                                }
                                            }
                                            else
                                            {
                                                if (PrintLabel.LabelInfo.side.Equals("T"))
                                                {
                                                    param.ShelfType = 3;
                                                    canOutstore = true;
                                                }
                                                else if (PrintLabel.LabelInfo.side.Equals("B"))
                                                {
                                                    param.ShelfType = 4;
                                                    canOutstore = true;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            SetWarnMsg($"工单{box.hSerial}已有料在{turnoverBox.Name}放入{box.rfid}中,无法放入其他料箱{turnoverBox.BoxId}");
                                        }
                                    }
                                    else
                                    {
                                        SetWarnMsg($"未读到RFID,工单{box.hSerial}已有料在{turnoverBox.Name}放入{box.rfid}中");
                                        return false;
                                    }
                                }
                                else //工单不同或者格口已满
                                {
                                    if(BoxA.ReadBoxId())
                                    {
                                        var boxTmp = boxInfos.Find(s => !BoxA.BoxId.Equals(s.rfid));
                                        if (boxTmp != null)
                                        {
                                            if (PrintLabel.LabelInfo.side.Equals("T"))
                                            {
                                                param.ShelfType = 1;
                                                canOutstore = true;
                                            }
                                            else if (PrintLabel.LabelInfo.side.Equals("B"))
                                            {
                                                param.ShelfType = 2;
                                                canOutstore = true;
                                            }
                                            LogUtil.info($"工单不同或者上一料箱格口已满,{PrintLabel.LabelInfo.hSerial}切换料箱为{BoxA.BoxId}");
                                        }
                                        else
                                        {
                                            if(BoxB.ReadBoxId())
                                            {
                                                var boxTmp1 = boxInfos.Find(s => !BoxB.BoxId.Equals(s.rfid));
                                                if (boxTmp1 != null)
                                                {
                                                    if (PrintLabel.LabelInfo.side.Equals("T"))
                                                    {
                                                        param.ShelfType = 3;
                                                        canOutstore = true;
                                                    }
                                                    else if (PrintLabel.LabelInfo.side.Equals("B"))
                                                    {
                                                        param.ShelfType = 4;
                                                        canOutstore = true;
                                                    }
                                                    LogUtil.info($"工单不同或者上一料箱格口已满,{PrintLabel.LabelInfo.hSerial}切换料箱为{BoxB.BoxId}");
                                                }
                                            }
                                            else
                                            {
                                                SetWarnMsg("周转箱线体上无可用料箱");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (BoxB.ReadBoxId())
                                        {
                                            var boxTmp1 = boxInfos.Find(s => !BoxB.BoxId.Equals(s.rfid));
                                            if (boxTmp1 != null)
                                            {
                                                if (PrintLabel.LabelInfo.side.Equals("T"))
                                                {
                                                    param.ShelfType = 3;
                                                    canOutstore = true;
                                                }
                                                else if (PrintLabel.LabelInfo.side.Equals("B"))
                                                {
                                                    param.ShelfType = 4;
                                                    canOutstore = true;
                                                }
                                                LogUtil.info($"工单不同或者上一料箱格口已满,{PrintLabel.LabelInfo.hSerial}切换料箱为{BoxB.BoxId}");
                                            }
                                        }
                                        else
                                        {
                                            SetWarnMsg("周转箱线体上无可用料箱");
                                        }
                                    }
                                }
                            }
                            //if (BoxA.BoxTaskInfo != null)
                            //{
                            //    string msgA = "";
                            //    if (!BoxA.CanPutIn(out string warnB))
                            //    {
                            //        msgA = warnB;
                            //    }
                            //    else if (!string.IsNullOrEmpty(BoxA.BoxTaskInfo.hSerial))
                            //    {
                            //        if (!BoxA.BoxTaskInfo.hSerial.Equals(PrintLabel.LabelInfo.hSerial))
                            //        {
                            //            msgA = ($"料盘与料箱需求单不匹配,出库失败。料盘【{PrintLabel.LabelInfo.hSerial}】料箱【{BoxA.BoxTaskInfo.hSerial}】:" + param.PosInfo.ToStr());
                            //            BoxA.NeedLeave();
                            //        }
                            //        else
                            //        {
                            //            if (PrintLabel.LabelInfo.side.Equals("T"))
                            //            {
                            //                param.ShelfType = 1;
                            //                canOutstore = true;
                            //            }
                            //            else if (PrintLabel.LabelInfo.side.Equals("B"))
                            //            {
                            //                param.ShelfType = 2;
                            //                canOutstore = true;
                            //            }
                            //            else
                            //            {
                            //                //msgA = ($"紧急料出库:" + param.PosInfo.ToStr());
                            //                outstoreNG = true;
                            //            }
                            //        }
                            //    }
                            //    else//空箱子
                            //    {
                            //        if (PrintLabel.LabelInfo.side.Equals("T"))
                            //        {
                            //            param.ShelfType = 1;
                            //            canOutstore = true;
                            //        }
                            //        else if (PrintLabel.LabelInfo.side.Equals("B"))
                            //        {
                            //            param.ShelfType = 2;
                            //            canOutstore = true;
                            //        }
                            //        else
                            //        {
                            //            // msgA = ($"料盘的面别信息有误:{PrintLabel.LabelInfo.side}。出库失败:" + param.PosInfo.ToStr());
                            //            outstoreNG = true;
                            //        }
                            //    }
                            //    BoxA.WarnMsg = msgA;
                            //    SetWarnMsg(msgA);
                            //}

                            //if (!canOutstore && BoxB.BoxTaskInfo != null)
                            //{
                            //    string msg1 = "";
                            //    if (!BoxB.CanPutIn(out string warnA))
                            //    {
                            //        msg1 = warnA;
                            //    }
                            //    else if (!string.IsNullOrEmpty(BoxB.BoxTaskInfo.hSerial))
                            //    {
                            //        if (!BoxB.BoxTaskInfo.hSerial.Equals(PrintLabel.LabelInfo.hSerial))
                            //        {
                            //            msg1 = ($"料盘与料箱需求单不匹配,出库失败。料盘【{PrintLabel.LabelInfo.hSerial}】料箱【{BoxB.BoxTaskInfo.hSerial}】:" + param.PosInfo.ToStr());
                            //            BoxB.NeedLeave();
                            //        }
                            //        else
                            //        {
                            //            if (PrintLabel.LabelInfo.side.Equals("T"))
                            //            {
                            //                param.ShelfType = 3;
                            //                canOutstore = true;
                            //            }
                            //            else if (PrintLabel.LabelInfo.side.Equals("B"))
                            //            {
                            //                param.ShelfType = 4;
                            //                canOutstore = true;
                            //            }
                            //            else
                            //            {
                            //                //msg1 = ($"料盘的面别信息有误:{PrintLabel.LabelInfo.side}。出库失败:" + param.PosInfo.ToStr());
                            //                outstoreNG = true;
                            //            }
                            //        }
                            //    }
                            //    else
                            //    {
                            //        if (PrintLabel.LabelInfo.side.Equals("T"))
                            //        {
                            //            param.ShelfType = 3;
                            //            canOutstore = true;
                            //        }
                            //        else if (PrintLabel.LabelInfo.side.Equals("B"))
                            //        {
                            //            param.ShelfType = 4;
                            //            canOutstore = true;
                            //        }
                            //        else
                            //        {
                            //            //msg1 = ($"料盘的面别信息有误:{PrintLabel.LabelInfo.side}。出库失败:" + param.PosInfo.ToStr());
                            //            outstoreNG = true;
                            //        }
                            //    }
                            //    BoxB.WarnMsg = msg1;
                            //    SetWarnMsg(msg1);
                            //}
                        }
                        else
                            outstoreNG = true;
                    }
                }
                else if (PrintLabel.LabelInfo == null)
                {
                    outstoreNG = true;
                }

                if (!outstoreNG)//正常出库
                {
                    if (!canOutstore) return false;
                }
                else
                {
                    StartNGReelOut(param);
                    return true;
                }
                runStatus = RunStatus.Busy;
                MoveInfo.NewMove(MoveType.OutStore, param);
                startOutTime = DateTime.Now;
                MoveInfo.NextMoveStep(StepEnum.IO01_ReelCheck);
                return true;
            }
            return false;
        }

        private void TrayHasLeave()
        {

        }

        private void TrayStartLeave()
        {
            // int shelf = MoveInfo.MoveParam.ShelfType;
            // if (shelf.Equals(1))
            {
                BatchMove.GetTrayStartLeave();
            }
        }
        string getSideName(int shelf)
        {
            if (shelf == 1)
            {
                return "A周转箱内侧【T面】";
            }
            else if (shelf == 2)
            {
                return "A周转箱外侧【B面】";
            }
            else if (shelf == 3)
            {
                return "B周转箱内侧【T面】";
            }
            else if (shelf == 4)
            {
                return "B周转箱外侧【B面】";
            }
            return "周转箱";
        }
        /// <summary>
        /// 出库NG料盘去NG区域
        /// </summary>
        void StartNGReelOut(InOutParam param)
        {
            runStatus = RunStatus.Busy;
            MoveInfo.NewMove(MoveType.OutStore, param);
            startOutTime = DateTime.Now;
            //获取位置是左侧还是右侧。
            int startp = MoveInfo.MoveParam.PosInfo.GetPosType();
            if (startp.Equals(1))
            {
                MoveInfo.NextMoveStep(StepEnum.IO10_ToLowerA);
                ToA下皮带末端();
                MoveLog($"出库A->NG箱:机器人去A下");
            }
            else
            {
                MoveInfo.NextMoveStep(StepEnum.IO16_ToLowerB);
                ToB下皮带末端();
                MoveLog($"出库B->NG箱:机器人去B下");
            }
        }
        protected override void OutstoreProcess()
        {
            if (MoveInfo.IsInWait)
            {
                CheckWait(MoveInfo);
            }
            if (MoveInfo.IsInWait)
            {
                return;
            }
            int shelf = MoveInfo.MoveParam.ShelfType;

            #region 打印标签
            if (MoveInfo.IsStep(StepEnum.IO01_ReelCheck))
            {
                MoveInfo.NextMoveStep(StepEnum.IO07_ToPrintPos);
                To打印机();
                MoveLog($"出库->{getSideName(shelf)}:去打印机取标签处");
                //MoveInfo.NextMoveStep(StepEnum.IO03_PrintLabel);
                //MoveLog($"出库->{getSideName(shelf)}:开始打印标签:{labelInfo.ToStr()}");
                //Printer.Print(new Label_LZ(labelInfo?.pn, labelInfo?.side, labelInfo?.station, labelInfo?.line), out string msg);
                //Printer.Connect();
                //MoveLog($"出库->周转箱:获取贴标信息");
                //new Label_LZ("123456789", "1", "ABCD-10_1  1A");
            }
            //else if (MoveInfo.IsStep(StepEnum.IO02_GetReelLabelInfo))
            //{
            //    MoveInfo.NextMoveStep(StepEnum.IO03_PrintLabel);
            //    Label_CylinderBack(MoveInfo);
            //    MoveLog($"出库->{shelf}周转箱:标签气缸后退");
            //}
            //else if (MoveInfo.IsStep(StepEnum.IO03_PrintLabel))
            //{
            //    MoveInfo.NextMoveStep(StepEnum.IO04_CheckPrinterState);
            //    MoveLog($"出库->{getSideName(shelf)}:检查打印机口是否有标签");
            //}
            //else if (MoveInfo.IsStep(StepEnum.IO04_CheckPrinterState))
            //{
            //    //if (Printer.IsLabelOnPeeler())
            //    //{
            //    //    SetWarnMsg("打印机口有标签,无法打印,需要处理");
            //    //}
            //    //else
            //    {
            //        IO05_WaitPrintLabelOK(shelf);
            //    }

            //}
            //else if (MoveInfo.IsStep(StepEnum.IO05_WaitPrintLabelOK))
            //{
            //    MoveInfo.NextMoveStep(StepEnum.IO06_PrinteLabelFwd);
            //    Label_CylinderFwd(MoveInfo);
            //    MoveLog($"出库->{getSideName(shelf)}:标签气缸前进");
            //}
            //else if (MoveInfo.IsStep(StepEnum.IO06_PrinteLabelFwd))
            //{
            //    MoveInfo.NextMoveStep(StepEnum.IO07_ToPrintPos);
            //    To打印机();
            //    MoveLog($"出库->{getSideName(shelf)}:去打印机取标签处");
            //}
            else if (MoveInfo.IsStep(StepEnum.IO07_ToPrintPos))
            {
                MoveInfo.NextMoveStep(StepEnum.IO08_ClamWork);
                ClampWork(null, true, MoveInfo.MoveParam.PosInfo.barcode);
                MoveLog($"出库->{getSideName(shelf)}:吸取标签");
            }
            else if (MoveInfo.IsStep(StepEnum.IO08_ClamWork))
            {
                MoveInfo.NextMoveStep(StepEnum.IO09_BackToP1);
                From打印机回原();
                MoveLog($"出库->{getSideName(shelf)}:从打印机回原点");
            }
            else if (MoveInfo.IsStep(StepEnum.IO09_BackToP1))
            {
                //料盘放贴标平台,机器人取好标签
                SServerManager.UploadLocInfo(MoveInfo.MoveParam.PosInfo.barcode, LocStatus.GET_LABEL);
                //获取位置是左侧还是右侧。
                int startp = MoveInfo.MoveParam.PosInfo.GetPosType();
                int round = BufferDataManager.LabelInfo.relativeAngle;
                if (startp.Equals(1))
                {
                    // if (scanCode == null || (scanCode.IsCompleted))
                    //{
                    //round = LabelManager.CalcLabelAngle(MoveInfo?.MoveParam?.PosInfo?.LabelParam);
                    MoveInfo.NextMoveStep(StepEnum.IO10_ToLowerA);
                    ToA下皮带末端(round);
                    MoveLog($"出库A->{getSideName(shelf)}:机器人去A下,并旋转 {round}°");
                    BufferDataManager.LabelInfo = null;
                    //}
                }
                else
                {
                    //if (scanCode == null || (scanCode.IsCompleted))
                    //{
                    //round = LabelManager.CalcLabelAngle(MoveInfo?.MoveParam?.PosInfo?.LabelParam);
                    MoveInfo.NextMoveStep(StepEnum.IO16_ToLowerB);
                    ToB下皮带末端(round);
                    MoveLog($"出库B->{getSideName(shelf)}:机器人去B下,并旋转 {round}°");
                    BufferDataManager.LabelInfo = null;
                    //}
                }

                //Label_CylinderBack();
            }
            #endregion
            #region 出库A侧取料
            else if (MoveInfo.IsStep(StepEnum.IO10_ToLowerA))
            {
                MoveInfo.NextMoveStep(StepEnum.IO11_ClamRelax);
                //ClampRelax(null, MoveInfo.MoveParam.PosInfo.barcode);
                //MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                MoveLog($"出库A->{getSideName(shelf)}:将标签贴到料盘");
            }
            else if (MoveInfo.IsStep(StepEnum.IO11_ClamRelax))
            {
                MoveInfo.NextMoveStep(StepEnum.IO12_ReClamWork);
                //贴标完成,等待放入周转箱
                SServerManager.UploadLocInfo(MoveInfo.MoveParam.PosInfo.barcode, LocStatus.LABELED);
                ClampWork(null, true, MoveInfo.MoveParam.PosInfo.barcode);
                MoveLog($"出库A->{getSideName(shelf)}:吸取料盘");
            }
            else if (MoveInfo.IsStep(StepEnum.IO12_ReClamWork))
            {
                MoveInfo.NextMoveStep(StepEnum.IO13_BackToP1);
                FromA下皮带末端回原();
                MoveLog($"出库A->{getSideName(shelf)}:从出料暂存区回原点");
            }
            else if (MoveInfo.IsStep(StepEnum.IO13_BackToP1))
            {
                //
                //if (!HasBoxInPos())
                //{
                //    {
                //        MoveInfo.NextMoveStep(StepEnum.IO21_WaitBoxReady);
                //        MoveLog($"出库A->{shelf}周转箱: 等待周转箱到位");
                //    }
                //}
                //else
                {
                    MoveInfo.NextMoveStep(StepEnum.IO14_WaitReelCheckLow);
                    MoveLog($"出库A->{getSideName(shelf)}: 料盘已拿走,等待料盘检测信号=0");
                    MoveInfo.TimeOutSeconds = 10;
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LineA_ReelInPlaceCheck, IO_VALUE.LOW));
                }
            }
            else if (MoveInfo.IsStep(StepEnum.IO14_WaitReelCheckLow))
            {
                MoveInfo.NextMoveStep(StepEnum.IO21_WaitBoxReady);
                BufferDataManager.AOutStoreInfo = null;
                //料盘在机器人上,准备放入周转箱
                SServerManager.UploadLocInfo(MoveInfo.MoveParam.PosInfo.barcode, LocStatus.TO_BOX);
                MoveLog($"出库A->{getSideName(shelf)}: 等待周转箱到达");
            }
            #endregion

            #region 出库B侧取料
            else if (MoveInfo.IsStep(StepEnum.IO16_ToLowerB))
            {
                MoveInfo.NextMoveStep(StepEnum.IO17_ClamRelax);
                //ClampRelax(null, MoveInfo.MoveParam.PosInfo.barcode);
                //MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                MoveLog($"出库B->{getSideName(shelf)}:将标签贴到料盘");
            }
            else if (MoveInfo.IsStep(StepEnum.IO17_ClamRelax))
            {
                MoveInfo.NextMoveStep(StepEnum.IO18_ReClamWork);
                //贴标完成,等待放入周转箱
                SServerManager.UploadLocInfo(MoveInfo.MoveParam.PosInfo.barcode, LocStatus.LABELED);
                ClampWork(null, true, MoveInfo.MoveParam.PosInfo.barcode);
                MoveLog($"出库B->{getSideName(shelf)}:吸取料盘");
            }
            else if (MoveInfo.IsStep(StepEnum.IO18_ReClamWork))
            {
                MoveInfo.NextMoveStep(StepEnum.IO19_BackToP1);
                FromB下皮带末端回原();
                MoveLog($"出库B->{getSideName(shelf)}:从出料暂存区回原点");
            }
            else if (MoveInfo.IsStep(StepEnum.IO19_BackToP1))
            {
                //判断料盘信号是否消失 
                //if (!HasBoxInPos())
                //{
                //    // if (!HasBoxInPos())
                //    {
                //        MoveInfo.NextMoveStep(StepEnum.IO21_WaitBoxReady);
                //        MoveLog($"出库B->{shelf}周转箱: 等待周转箱到达");
                //    }
                //}
                //else
                {
                    MoveInfo.NextMoveStep(StepEnum.IO20_WaitReelCheckLow);
                    MoveLog($"出库B->{getSideName(shelf)}: 料盘已拿走,等待料盘检测信号=0");
                    MoveInfo.TimeOutSeconds = 10;
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LineB_ReelInPlaceCheck, IO_VALUE.LOW));
                }
            }
            else if (MoveInfo.IsStep(StepEnum.IO20_WaitReelCheckLow))
            {
                MoveInfo.NextMoveStep(StepEnum.IO21_WaitBoxReady);
                //料盘在机器人上,准备放入周转箱
                SServerManager.UploadLocInfo(MoveInfo.MoveParam.PosInfo.barcode, LocStatus.TO_BOX);
                BufferDataManager.BOutStoreInfo = null;
                if (outstoreNG)
                {
                    MoveLog($"出库B->NG箱子");
                }
                else
                    MoveLog($"出库B->{getSideName(shelf)}: 等待周转箱到位");
            }
            #endregion
            #region 出库放料到周转箱
            else if (MoveInfo.IsStep(StepEnum.IO21_WaitBoxReady))
            {
                if (outstoreNG)
                {
                    IO40_ToUrgentBoxPos();
                }
                else
                {
                    if (HasBoxInPos())
                    {
                        IO23_ToBoxPos(shelf);
                        ClearSpecifiedAlarm($"等待{getSideName(shelf)}到位");
                    }
                    else if (MoveInfo.IsTimeOut(15))
                    {
                        SetWarnMsg($"等待{getSideName(shelf)}到位");
                    }
                }

            }
            else if (MoveInfo.IsStep(StepEnum.IO23_ToBoxPos))
            {
                MoveInfo.NextMoveStep(StepEnum.IO24_ClamRelax);
                ClampRelax(MoveInfo, MoveInfo.MoveParam.PosInfo.barcode);
                MoveLog($"出库->{getSideName(shelf)}:放下料盘");
            }
            else if (MoveInfo.IsStep(StepEnum.IO24_ClamRelax))
            {
                MoveInfo.NextMoveStep(StepEnum.IO25_UpdateLocInfo);
                UploadLocInfo(shelf);
            }
            else if (MoveInfo.IsStep(StepEnum.IO25_UpdateLocInfo))
            {
                MoveInfo.NextMoveStep(StepEnum.IO26_BackToP1);
                IO26_BackToP1(shelf);
            }
            else if (MoveInfo.IsStep(StepEnum.IO26_BackToP1))
            {
                PutReelInBox(shelf);
                MoveInfo.EndMove();
                runStatus = RunStatus.Runing;
                TimeSpan span = DateTime.Now - startOutTime;
                MoveLog($"出库->{getSideName(shelf)}: 放料完成,耗时【{FormUtil.GetSpanStr(span)}】");
            }
            #endregion

            #region 出库到紧急料区域
            else if (MoveInfo.IsStep(StepEnum.IO40_ToUrgentBoxPos))
            {
                MoveInfo.NextMoveStep(StepEnum.IO41_ClamRelax);
                ClampRelax(MoveInfo, MoveInfo.MoveParam.PosInfo.barcode);
                MoveLog($"出库->紧急料箱子:放下料盘");
            }
            else if (MoveInfo.IsStep(StepEnum.IO41_ClamRelax))
            {
                MoveInfo.NextMoveStep(StepEnum.IO42_UploadReelInfo);
            }
            else if (MoveInfo.IsStep(StepEnum.IO42_UploadReelInfo))
            {
                MoveInfo.NextMoveStep(StepEnum.IO43_BackToP1);
                // NGBox.PutIn(MoveInfo.MoveParam);
                SServerManager.UploadLocInfo(MoveInfo.MoveParam.PosInfo.barcode, LocStatus.FINISHED);
                IO43_BackToP1(shelf);
            }
            else if (MoveInfo.IsStep(StepEnum.IO43_BackToP1))
            {
                MoveInfo.EndMove();
                runStatus = RunStatus.Runing;
                TimeSpan span = DateTime.Now - startOutTime;
                MoveLog($"出库->紧急料箱子: 放料完成,耗时【{FormUtil.GetSpanStr(span)}】");
            }
            #endregion
        }
        void UploadLocInfo(int shelf)
        {
            string boxSide = "B";
            if (shelf == 1 || shelf==3)
            {
                boxSide = "T";
            }
            if (shelf.Equals(1) || shelf.Equals(2))
            {
                //料盘在机器人上,准备放入周转箱
              BoxA.BoxTaskInfo=  SServerManager.UploadLocInfo(MoveInfo.MoveParam.PosInfo.barcode, LocStatus.FINISHED, BoxAId,BoxA.BoxInfo.hSerial,BoxA.outLet, boxSide);
                SServerManager.ShelfFinish(BoxAId, MoveInfo.MoveParam.PosInfo.barcode, BoxA.BoxTaskInfo);
            }
            else if (shelf.Equals(3) || shelf.Equals(4))
            {
                //料盘在机器人上,准备放入周转箱
               BoxB.BoxTaskInfo= SServerManager.UploadLocInfo(MoveInfo.MoveParam.PosInfo.barcode, LocStatus.FINISHED, BoxBId,BoxB.BoxInfo.hSerial,BoxB.outLet, boxSide);
                SServerManager.ShelfFinish(BoxBId, MoveInfo.MoveParam.PosInfo.barcode, BoxB.BoxTaskInfo);
            }

        }
        void IO05_WaitPrintLabelOK(int shelf)
        {
            ClearSpecifiedAlarm("打印机口有标签,无法打印,需要处理");
            MoveInfo.NextMoveStep(StepEnum.IO05_WaitPrintLabelOK);
            MoveInfo.TimeOutSeconds = 30;
            // Printer.Print(new Label_LZ(labelInfo?.pn, labelInfo?.side, labelInfo?.station), out string msg);
            //Task.Factory.StartNew(delegate
            //{
            //    int cnt = 1;
            //    while (cnt > 0)
            //    {
            //        // if (!Printer.IsLabelOnPeeler())
            //        Printer.Print(new Label_LZ(labelInfo?.pn, labelInfo?.side, labelInfo?.station), out string msg);
            //        //Thread.Sleep(2000);
            //        if (Printer.IsLabelOnPeeler())
            //            break;
            //        cnt--;
            //    }

            //});
            MoveInfo.OneWaitCanEndStep = true;
            MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
            MoveInfo.WaitList.Add(WaitResultInfo.WaitPrintOK());
            MoveLog($"出库->{getSideName(shelf)}:等待标签打印完成");//结果:{msg}
        }
        void PutReelInBox(int shelf)
        {
            if (shelf.Equals(1) || shelf.Equals(2))
            {
                //ReadBoxAId();
                BoxA.PutReelIn(shelf);
            }
            if (shelf.Equals(3) || shelf.Equals(4))
            {
                //ReadBoxBId();
                BoxB.PutReelIn(shelf);
            }
        }
        void IO26_BackToP1(int shelf)
        {
            /// 0=未知,1=A侧周转箱内侧,2=A侧周转箱外
            /// 3=B侧周转箱内侧,4=B侧周转箱外
            if (shelf.Equals(1))
            {
                FromA周转1_内侧回原();
                MoveLog($"出库->{getSideName(shelf)}:机器人从A周转箱内侧回原");
            }
            else if (shelf.Equals(2))
            {
                FromA周转2_外侧回原();
                MoveLog($"出库->{getSideName(shelf)}:机器人从A周转箱外侧回原");
            }
            else if (shelf.Equals(3))
            {
                FromB周转1_内侧回原();
                MoveLog($"出库->{getSideName(shelf)}:机器人从B周转箱内侧回原");
            }
            else if (shelf.Equals(4))
            {
                FromB周转2_外侧回原();
                MoveLog($"出库->{getSideName(shelf)}:机器人从B周转箱外侧回原");
            }
        }
        void IO43_BackToP1(int shelf)
        {
            From紧急料回原();
            MoveLog($"出库->紧急料箱子:从紧急料区域回原");
        }
        void IO23_ToBoxPos(int shelf)
        {
            MoveInfo.NextMoveStep(StepEnum.IO23_ToBoxPos);
            //清空暂存区
            int startp = MoveInfo.MoveParam.PosInfo.GetPosType();
            //if (startp.Equals(1))
            //{
            //    BufferDataManager.AOutStoreInfo = null;
            //}
            //else
            //{
            //    BufferDataManager.BOutStoreInfo = null;
            //}
            /// 0=未知,1=A侧周转箱内侧,2=A侧周转箱外
            /// 3=B侧周转箱内侧,4=B侧周转箱外
            string pos = "";
            if (startp.Equals(1))//从A下
            {
                pos = getSideName(shelf);
                if (shelf.Equals(1))
                {
                    AToA周转1_内侧();
                }
                else if (shelf.Equals(2))
                {
                    AToA周转2_外侧();
                }
                else if (shelf.Equals(3))
                {
                    AToB周转1_内侧();
                }
                else if (shelf.Equals(4))
                {
                    AToB周转2_外侧();
                }
            }
            else//从B下
            {
                if (shelf.Equals(1))
                {
                    BToA周转1_内侧();
                }
                else if (shelf.Equals(2))
                {
                    BToA周转2_外侧();
                }
                else if (shelf.Equals(3))
                {
                    BToB周转1_内侧();
                }
                else if (shelf.Equals(4))
                {
                    BToB周转2_外侧();
                }
            }
            MoveLog($"出库->{getSideName(shelf)}:机器人去{getSideName(shelf)}");
        }

        void IO40_ToUrgentBoxPos()
        {
            //if (NGBox.CanPutIn(out string msg))
            {
                MoveInfo.NextMoveStep(StepEnum.IO40_ToUrgentBoxPos);
                ClearSpecifiedAlarm("无法放料");
                BufferDataManager.LabelInfo = null;
                //清空暂存区
                int startp = MoveInfo.MoveParam.PosInfo.GetPosType();
                //if (startp.Equals(1))
                //{
                //    BufferDataManager.AOutStoreInfo = null;
                //}
                //else
                //{
                //    BufferDataManager.BOutStoreInfo = null;
                //}
                /// 0=未知,1=A侧周转箱内侧,2=A侧周转箱外
                /// 3=B侧周转箱内侧,4=B侧周转箱外
                if (startp.Equals(1))//从A下
                {
                    //ToNG箱();
                    To紧急料();
                }
                else//从B下
                {
                    //B下ToNG箱();
                    BTo紧急料();
                }
                MoveLog($"出库->紧急料箱子:机器人去紧急料箱子");
            }
            //else
            //{
            //    SetWarnMsg(msg);
            //}
        }
        /// <summary>
        /// 是否有周转箱
        /// </summary>
        /// <returns></returns>
        private bool HasBoxInPos()
        {
            bool isTest = MoveInfo.MoveParam.PosInfo.barcode.EndsWith("TEST");
            int shelf = MoveInfo.MoveParam.ShelfType;
            bool shelfOk = false;
            if (shelf.Equals(1) || shelf.Equals(2))
            {
                shelfOk = IOValue(IO_Type.TurnoverBoxA_InPlaceCheck).Equals(IO_VALUE.HIGH) && ReadBoxAId();
            }
            else if (shelf.Equals(3) || shelf.Equals(4))
            {
                shelfOk = IOValue(IO_Type.TurnoverBoxB_InPlaceCheck).Equals(IO_VALUE.HIGH) && ReadBoxBId();
            }
            //shelfOk = TurnoverBox.HasBoxInPos(shelf);
            if (isTest || shelfOk)
            {
                ClearSpecifiedAlarm($"等待{getSideName(shelf)}到位");
                //MoveInfo.NextMoveStep(StepEnum.IO23_ToBoxPos);
                return true;
            }
            return false;

        }

        private void ShelfBatchAxisDown()
        {
            int shelf = MoveInfo.MoveParam.ShelfType;
            //判断料串是否完成
            if (shelf.Equals(1))
            {
                BatchMove.NewReelOut(MoveInfo.MoveParam.PosInfo);
            }
            else
            {
                LogUtil.error($"{Name}{MoveInfo.SLog}出库错误:未找到准备好的料串    ");
            }
        }

        #endregion
    }
}