FeedingEquip_OutStore.cs 43.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
    partial class FeedingEquip
    {
        #region 出料流程
        private int OutStoreHeight = -1;
        private int OutStoreCount = -1;
        private TaskData taskData = null;
        private InOutParam LastOutParam = new InOutParam();
        private bool NeedCheckShelf = true;
         
        public  bool StartTrayOut(InOutParam outParam)
        {
            if (outParam == null || outParam.PosId == null || outParam.PosId.Equals(""))
            {
                LogUtil.error(Name + "出库失败,参数不完整,托盘先离开");
                TrayMoveOk();
                LogUtil.error(outParam.ToStr());
                return false;
            }
            if (IOValue(IO_Type.SL_Location_Check).Equals(IO_VALUE.LOW) || OutStoreHeight < 0)
            {
                LogUtil.error(Name + "出库" + outParam.ToStr() + "失败,未准备好料架,托盘先离开");
                TrayMoveOk();
                return false;
            }

            //如果已经开始送出料架,暂不处理
            if (MoveInfo.MoveType.Equals(LineMoveType.OutStore) && MoveInfo.MoveStep >= LineMoveStep.FO_51_BatchAxisToP2)
            {
                LogUtil.error(Name + "出库" + outParam.ToStr() + "失败,正在送出料架,托盘先离开");
                TrayMoveOk();
                return false;
            }

            if (!MoveInfo.MoveType.Equals(LineMoveType.None))
            {
                return false;
            }

            runStatus = LineRunStatus.Busy; 
            string lastXuniRfid = LastOutParam.rfid;
            if (lastXuniRfid.Equals("") || lastXuniRfid.Equals(outParam.rfid))
            {
                //如果虚拟料架号为空,或者虚拟料架号与当前一致才可以出库
            }
            else
            {
                //料架号不一致时,直接送出料架
                //如果流水线还有次料架的任务,暂不送出
                int count = TrayManager.GetOutTaskByRfid(lastXuniRfid);
                if (count <= 0)
                {
                    LogUtil.info(Name + "出库" + outParam.ToStr() + "失败,料架号不一致[" + lastXuniRfid + "][" + outParam.rfid + "],当前料架暂时无任务,送出料架,托盘先离开");
                    TrayMoveOk();
                    MoveInfo.NewMove(LineMoveType.OutStore, LastOutParam);
                    SendOutShelfOut("料架号[" + lastXuniRfid + "][" + outParam.rfid + "]不一致");
                    return false;
                }
                else
                {
                    LogUtil.info(Name + "出库" + outParam.ToStr() + "失败,料架号不一致[" + lastXuniRfid + "][" + outParam.rfid + "],当前料架还有【" + count + "】个任务,托盘先离开");
                    TrayMoveOk();
                    return false;
                }
            }

            MoveInfo.NewMove(LineMoveType.OutStore, outParam);
            LastOutParam = outParam;
            //可以开始出库啦
            MoveInfo.NextMoveStep(LineMoveStep.FO_21_AxisDownMove);
            // CylinderMove(MoveInfo, IO_Type.SW_LocationCylinder_Down, IO_Type.SW_LocationCylinder_Up);
            int height = outParam.PlateH + 4;
            int targetPosition = BatchAxis.GetAclPosition() - height * Config.Height_ChangeValue;
            if (targetPosition < Config.BatchAxisP2)
            {
                targetPosition = Config.BatchAxisP2;
            }
            OutLog("出库移栽 " + MoveInfo.SLog + " :提升伺服下降" + height + "mm,目标:" + targetPosition);
            if (UpdownIsInP1() )
            {
                //已经在取料端
                if (CylinderIsOk(IO_Type.SL_MoveCylinder_Give, IO_Type.SL_MoveCylinder_Take))
                { 
                    int targetP = Config.GetUpdownP2Detial(MoveInfo.MoveParam.PlateH, MoveInfo.MoveParam.PlateW);
                    UpdownAxis.AbsMove(MoveInfo, targetP, Config.UpdownAxis_P2Speed);

                }
                else if (UpdownIsInP1())
                {
                    CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Give, IO_Type.SL_MoveCylinder_Take);
                } 
            }
            else
            {
                UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed);
            }
            BatchAxis.AbsMove(MoveInfo, targetPosition, Config.BatchAxis_P2Speed);
            return true;
        }
        public void StartOutStoreP()
        {
            if (OutStoreHeight >= 0)
            {
                //判断是否需要送出料架
                if (CurrShelfId != "" && CurrShelfId != "00" && LastOutParam.rfid != "")
                {
                    //重新获取剩余任务
                    string msg = SServerManager.afterPutCut(Name, CurrShelfId, "", "", 0, out taskData);
                    if (String.IsNullOrEmpty(msg).Equals(false) || taskData == null)
                    {
                        LogUtil.error(Name + "定时获取 " + LastOutParam.ToShortStr() + " 剩余任务出错:" + msg);
                    }
                    else if (LastOutParam.cutReel && taskData.cutTask <= 0)
                    {
                        MoveInfo.NewMove(LineMoveType.OutStore, LastOutParam);
                        LogUtil.info(Name + "定时获取到 " + LastOutParam.ToShortStr() + " 已无剩余任务:" + taskData.ToStr());
                        SendOutShelfOut("分盘料,cutTask=" + taskData.cutTask + ",需要送出料架");
                    }
                    else if (LastOutParam.urgentReel && taskData.urgentTask <= 0)
                    {
                        MoveInfo.NewMove(LineMoveType.OutStore, LastOutParam);
                        LogUtil.info(Name + "定时获取到 " + LastOutParam.ToShortStr() + " 已无剩余任务:" + taskData.ToStr());
                        SendOutShelfOut("紧急料,urgentTask=" + taskData.urgentTask + ",需要送出料架");
                    }
                }

                return;
            }
            //若定位工位,阻挡工位,有 料架,直接进入定位工位,并上升好位置,若需要出库,直接下降高度即可
            if (IOValue(IO_Type.SL_Location_Check).Equals(IO_VALUE.HIGH) || IOValue(IO_Type.SL_Stop_Check).Equals(IO_VALUE.HIGH) || IOValue(IO_Type.SL_Entry_Check).Equals(IO_VALUE.HIGH))
            {
                StartOutStoreMove(null);
            }
            else if (IOValue(IO_Type.SL_Entry_Check).Equals(IO_VALUE.HIGH))
            {
                //小车到达处理
            }
            else if (IOValue(IO_Type.SL_Out_Check).Equals(IO_VALUE.HIGH))
            {
                //线体出口检测到料架,需要通知AGV小车
                //  AgvClient.NeedLeave(Config.AgvOutName); 
            }
        }
        public override bool StartOutStoreMove(InOutParam param)
        {

            runStatus = LineRunStatus.Busy; 
            MoveInfo.NewMove(LineMoveType.OutStore);
            MoveInfo.MoveParam = new InOutParam();
            taskData = null;
            RFIDData data = RFIDManager.GetShelfId(DeviceID);
            //判断是哪个工位有料架
            if (data.Num > 0 && IsTrayLCylinderAfter())
            {
                OutLog("定位工位读取到料串 " + data.NumStr() + " , 等待定位工位检测信号亮");
                FO_06_WaitTime(true);
            }
            if (IOValue(IO_Type.SL_Location_Check).Equals(IO_VALUE.HIGH) && IsTrayLCylinderAfter())
            {
                FO_06_WaitTime();
            }
            else
            {
                //如果升降盘在锁紧状态,需要返回P2
                if (IsTrayLCylinderAfter())
                {
                    MoveInfo.NextMoveStep(LineMoveStep.FO_02_TrayLocation_After);
                    OutLog("准备出库料架, " + MoveInfo.SLog + "  :升降盘定位气缸后退");
                    TrayLCylinderAfter(MoveInfo);
                }
                else
                {
                    MoveInfo.NextMoveStep(LineMoveStep.FO_01_BatchAxisToP2);
                    BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP2, Config.BatchAxis_P2Speed);
                    OutLog("准备出库料架,升降盘不在后退端 " + MoveInfo.SLog + "  :提升伺服先回到P2 ["+ Config.BatchAxisP2 + "]");
                }
            }
            return true;
        }
        private void FO_06_WaitTime(bool needWaitCheck = false)
        {
            //定位工位有料架,等待1秒后再次检测
            MoveInfo.NextMoveStep(LineMoveStep.FO_06_WaitTime);
            if (needWaitCheck)
            {
                OutLog("定位工位读取到料串: " + MoveInfo.SLog + ",进料阻挡上升,缓冲阻挡上升, 等待定位工位信号");
            }
            else
            {
                OutLog("准备出库料架 " + MoveInfo.SLog + "定位工位检测到料架:进料阻挡上升, 等待3秒再次检测");
            }
            IOMove(IO_Type.SL_Line_Run, IO_VALUE.HIGH);
            IOMove(IO_Type.SL_Buffer_StopDown, IO_VALUE.LOW);
            IOMove(IO_Type.SL_Entry_StopDown, IO_VALUE.LOW);
            //MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Buffer_StopDown, IO_VALUE.LOW));
            MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000));
            if (needWaitCheck)
            {
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Location_Check, IO_VALUE.HIGH));
            }
        }


        private void LineOutStoreProcess()
        {
            //判断是哪个工位有料架
            RFIDData data = RFIDManager.GetShelfId(DeviceID);
            if (data.Num > 0)
            {
                OutLog("定位工位读取到料串 " + data.NumStr() + " , 等待定位工位检测信号亮");
                FO_06_WaitTime(true);
            } 
           else  if (IOValue(IO_Type.SL_Location_Check).Equals(IO_VALUE.HIGH))
            {
                FO_06_WaitTime();
            }
            //阻挡工位有料架,流水线转动一个工位
            else if (IOValue(IO_Type.SL_Stop_Check).Equals(IO_VALUE.HIGH))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_05_LineStart);
                OutLog("准备出库料架: " + MoveInfo.SLog + "   阻挡工位有新料架,清理缓存料架RFID,进料阻挡下降500ms,缓冲阻挡前进1000,流水线转动 5000");
                UpdateLastShelfID();
                IOMove(IO_Type.SL_Entry_StopDown, IO_VALUE.HIGH, 1500);
                IOMove(IO_Type.SL_Buffer_StopDown, IO_VALUE.HIGH, 1000);//缓冲阻挡前进1000
                IOMove(IO_Type.SL_Line_Run, IO_VALUE.HIGH);
                //等待指定时间
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(6000));
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Location_Check, IO_VALUE.HIGH));
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Line_Run, IO_VALUE.HIGH));
            }
            else if (IOValue(IO_Type.SL_Entry_Check).Equals(IO_VALUE.HIGH))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_05_LineStart);
                OutLog("准备出库料架: " + MoveInfo.SLog + "   进料口有新料架,进料阻挡上升,缓冲阻挡前进1000,流水线转动 1000");
                IOMove(IO_Type.SL_Entry_StopDown, IO_VALUE.LOW);//进料阻挡上升
                IOMove(IO_Type.SL_Buffer_StopDown, IO_VALUE.HIGH, 1000);//缓冲阻挡前进1000
                IOMove(IO_Type.SL_Line_Run, IO_VALUE.HIGH);
                //等待指定时间
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Stop_Check, IO_VALUE.HIGH));
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Line_Run, IO_VALUE.HIGH));
            }
            else
            {
                if (!ProcessShelfEnter)
                {
                    IOMove(IO_Type.SL_Line_Run, IO_VALUE.LOW);
                }
                MoveEndS();
                OutLog(" 未检测到料架, 准备出库料架结束");
            }
        }


        protected override void OutStoreProcess()
        {
            if (MoveInfo.IsInWait)
            {
                CheckWait(MoveInfo);
            }
            if (MoveInfo.IsInWait)
            {
                return;
            }
            if (MoveInfo.IsStep(LineMoveStep.FO_01_BatchAxisToP2))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_02_TrayLocation_After);
                TrayLCylinderAfter(MoveInfo);
                OutLog("准备出库料架, " + MoveInfo.SLog + "  :升降盘定位气缸后退");
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_02_TrayLocation_After))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_03_FixedUp);
                OutLog("出库:  " + MoveInfo.SLog + " 开始:固定气缸上升");
                FixedCylinderUp(MoveInfo);
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_03_FixedUp))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_04_LocationDown);
                OutLog("出库:  " + MoveInfo.SLog + " 开始:定位气缸下降,提升轴移动到P1");
                LocationCylinderDown(MoveInfo);
                BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP1, Config.BatchAxis_P1Speed);
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_04_LocationDown))
            {
                LineOutStoreProcess();
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_05_LineStart))
            {
                LineOutStoreProcess();
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_06_WaitTime))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_06_WaitTime);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(20000));
                if (IOValue(IO_Type.SL_Location_Check).Equals(IO_VALUE.HIGH))
                {
                    ReadShelfId();
                    if (CurrShelfId.EndsWith("00"))
                    {
                        SendOutShelfOut("料架号【" + CurrShelfId + "】无效");
                        return;
                    }

                    //判断是否是第一次获取料架,需要从服务器获取此料架的虚拟料架号,若无虚拟料架号,料架可以用
                    //有虚拟料架号,从服务器获取此料架剩余任务,若无任务,需要送出料架 
                    if (LastOutParam.rfid.Equals("") && NeedCheckShelf)
                    {
                        //只有启动后第一个料架才需要验证
                        NeedCheckShelf = false;
                        string tempRfid = "";
                        string msg = SServerManager.findTempRfid(Name, CurrShelfId, out tempRfid);
                        if (!String.IsNullOrEmpty(msg))
                        {
                            LogUtil.error(Name + "findTempRfid 【" + CurrShelfId + "】【" + tempRfid + "】结果:" + msg);
                        }
                        if (!String.IsNullOrEmpty(tempRfid))
                        {
                            //如果虚拟料架号存在,直接送出料架
                            SendOutShelfOut("料架【" + CurrShelfId + "】【" + tempRfid + "】已绑定,不再使用");
                            return;
                        }
                    }

                    //定位工位有料架,直接开始入料
                    MoveInfo.NextMoveStep(LineMoveStep.FO_07_LocationUp);
                    OutLog("定位工位检测到料架: " + MoveInfo.SLog + "  定位气缸上升,读取并缓存料架RFID");
                    UpdateLastShelfID(CurrShelfId);
                    LocationCylinderUp(MoveInfo);

                }
                else
                {
                    MoveEndS();
                    OutLog(" 未检测到料架,料架处理结束");
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_07_LocationUp))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_08_FixedDown);
                OutLog("准备出库料架: " + MoveInfo.SLog + "  固定气缸下降");
                FixedCylinderDown(MoveInfo);
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_08_FixedDown))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_11_BatchAxisToP2);
                OutLog("准备出库料架 " + MoveInfo.SLog + " :提升轴下降到位P2[" + Config.BatchAxisP2 + "]");
                if (!ProcessShelfEnter)
                {
                    IOMove(IO_Type.SL_Line_Run, IO_VALUE.LOW);
                }
                BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP2, Config.BatchAxis_P2Speed);
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_11_BatchAxisToP2))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_12_TrayLocation_Before);
                OutLog("准备出库料架 " + MoveInfo.SLog + " :升降盘定位气缸第一次前进 2秒");
                TrayLCylinderBefore(null);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_12_TrayLocation_Before))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_13_TrayLocation_Back);
                OutLog("准备出库料架 " + MoveInfo.SLog + " :升降盘定位气缸后退,等待再次前进");
                TrayLCylinderAfter(MoveInfo);
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_13_TrayLocation_Back))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_14_TrayLocation_Before);
                OutLog("准备出库料架 " + MoveInfo.SLog + " :升降盘定位气缸前进");
                TrayLCylinderBefore(MoveInfo);
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_14_TrayLocation_Before))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_15_AxisUpMove);
                OutLog("准备出库料架 " + MoveInfo.SLog + " :上料轴开始慢速上升到P3点,等待检测到料盘");
                BatchAxisToP3();
            }

            else if (MoveInfo.IsStep(LineMoveStep.FO_15_AxisUpMove))
            {
                //判断信号是否亮
                if (IOValue(IO_Type.SL_AxisLocationCheck).Equals(IO_VALUE.LOW))
                {
                    OutStoreHeight = 0;
                    OutStoreCount = 0;
                    //如果再出库中直接出库
                    MoveInfo.EndMove();
                    runStatus = LineRunStatus.Runing;
                    OutLog("准备出库料架完成");
                }
                else
                {
                    //检测到料盘,需要下降指定高度,此处默认下降2cm
                    int tp = BatchAxis.GetAclPosition() - Config.Height_ChangeValue * 20;
                    if (tp < Config.BatchAxisP2)
                    {
                        OutLog("准备出库料架 " + MoveInfo.SLog + " :检测到料盘,下降的目标高度为【" + tp + "】<【" + Config.BatchAxisP2 + "】,料架已满,直接送出料架");
                        MoveInfo.NextMoveStep(LineMoveStep.FO_51_BatchAxisToP2);
                        OutLog("出库移栽 " + MoveInfo.SLog + ":提升伺服到P2点 [" + Config.BatchAxisP2 + "]");
                        BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP2, Config.BatchAxis_P2Speed);
                    }
                    else
                    {
                        MoveInfo.NextMoveStep(LineMoveStep.FO_15_AxisUpMove);
                        OutLog("准备出库料架 " + MoveInfo.SLog + " :检测到料盘,需要下降指定高度,目标位置:" + tp + ",等待检测不到料盘");
                        MoveInfo.TimeOutSeconds = 200;
                        MoveInfo.CanWhileCount = 0;
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitBatchAxis(Config.Batch_Axis, tp, Config.BatchAxis_P3Speed));
                        Config.Batch_Axis.TargetPosition = tp;
                        BatchAxis.AbsMove(null, tp, Config.BatchAxis_P3Speed);
                        //开始检测信号
                        BatchAxisStartCheck(IO_Type.SL_AxisLocationCheck, IO_VALUE.LOW);
                    }
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_51_BatchAxisToP2))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_52_TrayLocation_After);
                OutLog("送出料串: " + MoveInfo.SLog + ": 升降盘定位气缸后退,重置 OutEndSendShelfOut=fasle ,OutStoreCount = 0");
                OutEndSendShelfOut = false;
                OutStoreHeight = -1;
                OutStoreCount = 0;
                TrayLCylinderAfter(MoveInfo);
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_52_TrayLocation_After))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_53_BatchAxisToP1);
                OutLog("送出料串: " + MoveInfo.SLog + ":提升伺服到P1点");
                BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP1, Config.BatchAxis_P1Speed);
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_53_BatchAxisToP1))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_54_FixedUp);
                OutLog("送出料串: " + MoveInfo.SLog + ":固定气缸上升,定位气缸下降");
                FixedCylinderUp(MoveInfo);
                LocationCylinderDown(MoveInfo);
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_54_FixedUp))
            {
                if (IOValue(IO_Type.SL_Out_Check).Equals(IO_VALUE.HIGH) && HasOutLine)
                {
                    MoveInfo.NextMoveStep(LineMoveStep.FO_55_OutCheck);
                    OutLog("送出料串: " + MoveInfo.SLog + ",出料线体转动5秒,等待出料线体无料架,");
                    IOMove(IO_Type.SL_Out_StopDown, IO_VALUE.LOW);
                    IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.HIGH);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(5000));
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Out_Check, IO_VALUE.LOW));
                }
                else
                {
                    MoveInfo.NextMoveStep(LineMoveStep.FO_55_OutCheck);
                    OutLog("送出料串: " + MoveInfo.SLog + ",等待出料线体无料架");
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Out_Check, IO_VALUE.LOW));
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_55_OutCheck))
            {
                if (!ProcessShelfOut)
                {
                    if (IsFixedCylinderUp())
                    {
                        MoveInfo.NextMoveStep(LineMoveStep.FO_56_TopUp);
                        OutLog("送出料串: " + MoveInfo.SLog + ",顶升气缸上升,出料缓冲阻挡上升");
                        TopCylinderUp(MoveInfo);
                        IOMove(IO_Type.SL_Out_StopDown, IO_VALUE.LOW);
                    }
                    else
                    {
                        OutLog("送出料串: " + MoveInfo.SLog + ",顶升气缸上升时发现固定气缸不在上升端,重新上升固定气缸");
                        MoveInfo.NextMoveStep(LineMoveStep.FO_54_FixedUp);
                        OutLog("送出料串: " + MoveInfo.SLog + ":固定气缸上升,定位气缸下降");
                        FixedCylinderUp(MoveInfo);
                        LocationCylinderDown(MoveInfo);
                    }
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_56_TopUp))
            {
                //TODO 
                MoveInfo.NextMoveStep(LineMoveStep.FO_57_SideWayLineRun);
                OutLog("送出料串: " + MoveInfo.SLog + ", 线体横移电机运转,等待料架离开定位工位");
                IOMove(IO_Type.SL_LocationSideWay_Run, IO_VALUE.HIGH);
                IOMove(IO_Type.SL_OutSideWay_Run, IO_VALUE.HIGH);
                IOMove(IO_Type.SL_RollerLine_Run, IO_VALUE.HIGH);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Location_Check, IO_VALUE.LOW));
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_57_SideWayLineRun))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_58_WaitShelfGo);
                OutLog("送出料串:" + MoveInfo.SLog + ", 线体横移电机运转,等待料架到达出口");
                IOMove(IO_Type.SL_LocationSideWay_Run, IO_VALUE.HIGH);
                IOMove(IO_Type.SL_OutSideWay_Run, IO_VALUE.HIGH);
                IOMove(IO_Type.SL_RollerLine_Run, IO_VALUE.HIGH);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Out_Check, IO_VALUE.HIGH));
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_58_WaitShelfGo))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_59_WaitTime);
                OutLog("送出料串:" + MoveInfo.SLog + ", 横移电机再转动3秒,等待料架到达出口");
                IOMove(IO_Type.SL_LocationSideWay_Run, IO_VALUE.HIGH);
                IOMove(IO_Type.SL_OutSideWay_Run, IO_VALUE.HIGH);
                IOMove(IO_Type.SL_RollerLine_Run, IO_VALUE.HIGH);
                int time = 200;
                if (HasOutLine)
                {
                    time = 3000;
                }
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(time));
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Out_Check, IO_VALUE.HIGH));
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_59_WaitTime))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_60_LineStop);
                OutLog("送出料串: " + MoveInfo.SLog + ", 料架到达出口,线体横移电机停止 ");
                IOMove(IO_Type.SL_LocationSideWay_Run, IO_VALUE.LOW);
                IOMove(IO_Type.SL_OutSideWay_Run, IO_VALUE.LOW);
                IOMove(IO_Type.SL_RollerLine_Run, IO_VALUE.LOW);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(300));
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_60_LineStop))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_61_TopDown);
                OutLog("送出料串: " + MoveInfo.SLog + ", 料架到达出口,顶升气缸下降 ,清空LastOutParam,清理料架号,清理RFID缓存 ");
                UpdateLastShelfID();
                TopCylinderDown(MoveInfo);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(300));
                LastOutParam = new InOutParam();
                //清理RFID
                RFIDManager.ClearTrayNum(DeviceID);
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_61_TopDown))
            {
                if (HasOutLine)
                {
                    MoveInfo.NextMoveStep(LineMoveStep.FO_62_OutLineRun);
                    OutLog("送出料串: " + MoveInfo.SLog + ", 出料线阻挡上升,出料线体转动5秒钟 或等待出料口信号亮");
                    IOMove(IO_Type.SL_Out_StopDown, IO_VALUE.LOW);
                    IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.HIGH);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(5000));
                    if (IOValue(IO_Type.SL_OutLine_Check).Equals(IO_VALUE.LOW))
                    {
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_OutLine_Check, IO_VALUE.HIGH));
                    }
                }
                else
                {
                    MoveEndS();
                    OutLog("送出料串: " + MoveInfo.SLog + ", 料架到达出口处, 通知AGV取空料架, 出料结束");
                    AgvClient.NeedLeave(Config.AgvOutName, LastOutShelfId, Asa.ClientLevel.High);
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_62_OutLineRun))
            {
                MoveEndS();
                OutLog("送出料串: " + MoveInfo.SLog + ", 出料线体停止,料架到达出口处, 通知AGV取空料架, 出料结束");
                IOMove(IO_Type.SL_Out_StopDown, IO_VALUE.LOW);
                IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.LOW);
                AgvClient.NeedLeave(Config.AgvOutName, LastOutShelfId, Asa.ClientLevel.High);
            }
            else if (MoveInfo.MoveStep >= LineMoveStep.FO_21_AxisDownMove && MoveInfo.MoveStep < LineMoveStep.FO_51_BatchAxisToP2)
            {
                TrayOutProcess();
            }
            else
            {
                LogUtil.error(Name + " " + MoveInfo.MoveType + MoveInfo.SLog + "未找到相关处理", 19);
            }
        }

        private void TrayOutProcess()
        {
            string outType = "紧急出料 ";
            if (MoveInfo.MoveParam != null && MoveInfo.MoveParam.cutReel)
            {
                outType = "分盘料 ";
            }
            if (MoveInfo.IsStep(LineMoveStep.FO_21_AxisDownMove))
            {
                //判断伺服检测信号是否亮
                //if (IOValue(IO_Type.SL_AxisLocationCheck).Equals(IO_VALUE.LOW) || BatchAxis.IsInPosition(Config.BatchAxisP2))
                if (IOValue(IO_Type.SL_AxisLocationCheck).Equals(IO_VALUE.HIGH) && BatchAxis.IsInPosition(Config.BatchAxisP2).Equals(false))
                {
                    //可以开始出库啦
                    MoveInfo.NextMoveStep(LineMoveStep.FO_21_AxisDownMove);
                    int height = MoveInfo.MoveParam.PlateH + 4;
                    int targetPosition = BatchAxis.GetAclPosition() - height * Config.Height_ChangeValue;
                    if (targetPosition < Config.BatchAxisP2)
                    {
                        targetPosition = Config.BatchAxisP2;
                    }
                    OutLog("出库移栽 " + MoveInfo.SLog + " :TrayOutProcess 伺服检测信号亮并且不再P2点,再次下降" + height + "mm,目标:" + targetPosition);
                    BatchAxis.AbsMove(MoveInfo, targetPosition, Config.BatchAxis_P2Speed);
                }
                else
                {

                    if (CylinderIsOk(IO_Type.SL_MoveCylinder_Give, IO_Type.SL_MoveCylinder_Take))
                    { 
                        int targetP = Config.GetUpdownP2Detial(MoveInfo.MoveParam.PlateH, MoveInfo.MoveParam.PlateW);

                        if (UpdownAxis.IsInPosition(targetP))
                        {
                            FO_25_CylinderTighten(outType);
                        }
                        else
                        {
                            MoveInfo.NextMoveStep(LineMoveStep.FO_23_UpdownAxisToP2);
                            OutLog(outType + MoveInfo.SLog + ":升降伺服下降到P2:" + targetP);
                            UpdownAxis.AbsMove(MoveInfo, targetP, Config.UpdownAxis_P2Speed);
                        }
                    }
                    else
                    {
                        if (UpdownIsInP1())
                        {
                            MoveInfo.NextMoveStep(LineMoveStep.FO_22_CylinderTake);
                            OutLog(outType + MoveInfo.SLog + ":上料横移机构取料端,等待夹爪无料");
                            CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Give, IO_Type.SL_MoveCylinder_Take);
                            MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_ClampCylinder_Check, IO_VALUE.LOW));
                        }
                        else
                        {
                            MoveInfo.NextMoveStep(LineMoveStep.FO_21_AxisDownMove);
                            OutLog(outType + MoveInfo.SLog + ":上料横移机构取料端  前升降轴先到P1 [" + Config.UpDownAxisP1 + "]");
                            UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed);
                        }
                    }
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_22_CylinderTake))
            {
                if (CylinderIsOk(IO_Type.SL_MoveCylinder_Give, IO_Type.SL_MoveCylinder_Take))
                {
                    MoveInfo.NextMoveStep(LineMoveStep.FO_23_UpdownAxisToP2);
                    int targetP = Config.GetUpdownP2Detial(MoveInfo.MoveParam.PlateH, MoveInfo.MoveParam.PlateW);
                    OutLog(outType + MoveInfo.SLog + ":升降伺服下降到P2:" + targetP);
                    UpdownAxis.AbsMove(MoveInfo, targetP, Config.UpdownAxis_P2Speed);
                }
                else
                {
                    MoveInfo.NextMoveStep(LineMoveStep.FO_22_CylinderTake);
                    OutLog(outType + MoveInfo.SLog + ":上料横移机构取料端");
                    CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Give, IO_Type.SL_MoveCylinder_Take);
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_23_UpdownAxisToP2))
            {
                FO_25_CylinderTighten(outType);
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_24_CylinderDown))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_25_CylinderTighten);
                OutLog(outType + MoveInfo.SLog + ":上料气缸夹紧");
                CylinderMove(MoveInfo, IO_Type.SL_ClampCylinder_Relax, IO_Type.SL_ClampCylinder_Work);
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_25_CylinderTighten))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_26_UpdownAxisToP1);
                OutLog(outType + MoveInfo.SLog + ":升降伺服到P1");
                if (!UpdownAxis.IsInPosition(Config.UpDownAxisP1))
                {
                    UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed);
                }

            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_26_UpdownAxisToP1))
            {
                if (UpdownIsInP1())
                {
                    if (IOValue(IO_Type.SL_ClampCylinder_Check).Equals(IO_VALUE.LOW))
                    {
                        MoveInfo.NextMoveStep(LineMoveStep.FO_27_ClampCheck);
                        OutLog(outType + MoveInfo.SLog + ":检测夹爪料盘检测=HIGH");
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_ClampCylinder_Check, IO_VALUE.HIGH));
                    }
                    else
                    {
                        FO_28_CylinderGive(outType);
                    }
                }
                else
                {
                    MoveInfo.NextMoveStep(LineMoveStep.FO_26_UpdownAxisToP1);
                    OutLog(outType + MoveInfo.SLog + ":上料横移机构到放料端前,先升降轴先到P1 [" + Config.UpDownAxisP1 + "]");
                    UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed);
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_27_ClampCheck))
            {
                FO_28_CylinderGive(outType);
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_28_CylinderGive))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_29_UpdownAxisToP3);
                OutLog(outType + MoveInfo.SLog + ":移栽伺服到P3 [" + Config.UpDownAxisP3 + "]");
                UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxisP3, Config.UpdownAxis_P3Speed);
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_29_UpdownAxisToP3))
            {
                OutStoreHeight += MoveInfo.MoveParam.PlateH;
                OutStoreCount++;
                MoveInfo.NextMoveStep(LineMoveStep.FO_30_CylinderSlack);
                OutLog(outType + MoveInfo.SLog + ":出料横移机构放松,累积出库【" + OutStoreCount + "】盘【" + OutStoreHeight + "】mm");
                CylinderMove(MoveInfo, IO_Type.SL_ClampCylinder_Work, IO_Type.SL_ClampCylinder_Relax);

            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_30_CylinderSlack))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_31_UpdownAxisToP1);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                OutLog(outType + MoveInfo.SLog + ":移栽伺服上升到待机点P1,通知服务器 afterPutCut");
                UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed);
                afterPutOk = false;
                string msg = SServerManager.afterPutCut(Name, CurrShelfId, MoveInfo.MoveParam.WareCode, "", OutStoreCount, out taskData);
                if (String.IsNullOrEmpty(msg).Equals(false))
                {
                    LogUtil.error(Name + "【" + MoveInfo.MoveParam.WareCode + "】【" + CurrShelfId + "】【" + OutStoreCount.ToString() + "】afterPutCut 结果:" + msg);
                    taskData = null;
                }
                afterPutOk = true;
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_31_UpdownAxisToP1))
            {
                MoveInfo.NextMoveStep(LineMoveStep.FO_32_ClampCheck);
                OutLog(outType + MoveInfo.SLog + ":检测夹爪料盘检测=LOW");
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_ClampCylinder_Check, IO_VALUE.LOW));
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_32_ClampCheck))
            {
                if (UpdownIsInP1())
                {
                    MoveInfo.NextMoveStep(LineMoveStep.FO_33_CylinderTake);
                    CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Give, IO_Type.SL_MoveCylinder_Take);
                    //只有提升轴位置过低时才需要到P3
                    int currPosition = BatchAxis.GetAclPosition();
                    if (currPosition <= (Config.BatchAxisP2 + Config.Height_ChangeValue * 40))
                    {
                        OutLog(outType + MoveInfo.SLog + ":上料横移机构回到取料端,提升轴[" + currPosition + "]需要到P3");
                        BatchAxisToP3();
                    }
                    else
                    {
                        OutLog(outType + MoveInfo.SLog + ":上料横移机构回到取料端,提升轴[" + currPosition + "]不需要到P3");
                    }
                }
                else
                {
                    MoveInfo.NextMoveStep(LineMoveStep.FO_31_UpdownAxisToP1);
                    OutLog(outType + MoveInfo.SLog + ":上料横移机构取料端  前升降轴先到P1");
                    UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed);
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.FO_33_CylinderTake))
            {
                if (afterPutOk)
                {
                    //出库结束 TODO
                    //    bool isNeedSendShelf = false;
                    //判断料架是否满了
                    int currPositon = BatchAxis.GetAclPosition();
                    int tp = currPositon - Config.Height_ChangeValue * 40;
                    if (tp <= Config.BatchAxisP2)
                    {
                        SendOutShelfOut("当前提升轴位置:" + currPositon + ",料架已满,需要送出料架");
                    }
                    else if (OutEndSendShelfOut)
                    {
                        SendOutShelfOut("当前提升轴位置:" + currPositon + ",OutEndSendShelfOut,需要送出料架");
                    }
                    else
                    {
                        //判断是否需要送出料架'
                        if (taskData == null)
                        {
                            SendOutShelfOut("出料结束,taskData=null,需要送出料架");
                        }
                        else if (MoveInfo.MoveParam.cutReel && taskData.cutTask <= 0)
                        {
                            SendOutShelfOut("分盘料,cutTask=" + taskData.cutTask + ",需要送出料架");
                        }
                        else if (MoveInfo.MoveParam.urgentReel && taskData.urgentTask <= 0)
                        {
                            SendOutShelfOut("紧急料,urgentTask=" + taskData.urgentTask + ",需要送出料架");
                        }
                        else
                        {
                            OutLog("出料完成,出料结束");
                            MoveEndS();
                        }
                    }
                    ClearTimeoutAlarm("等待给服务器发送afterPut完成超时");
                }
                else if (MoveInfo.IsTimeOut(60))
                {
                    MoveTimeoutAlarm(MoveInfo, "等待给服务器发送afterPut完成超时");
                }
            }
        }
        private void FO_28_CylinderGive(string outType)
        {
            int trayNum = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.TrayNumber : currTrayNum; 
            TrayManager.UpdateTrayInfo(trayNum, false);
            TrayMoveOk();

            MoveInfo.NextMoveStep(LineMoveStep.FO_28_CylinderGive);
            OutLog(outType + MoveInfo.SLog + ":更新托盘【"+ trayNum + "】为空,托盘可离开,上料横移机构到放料端 ");
            CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Take, IO_Type.SL_MoveCylinder_Give); 
        }

        private bool afterPutOk = false;
        private void FO_25_CylinderTighten(string outType)
        {
            MoveInfo.NextMoveStep(LineMoveStep.FO_25_CylinderTighten);
            OutLog(outType + MoveInfo.SLog + ":上料气缸夹紧");
            CylinderMove(MoveInfo, IO_Type.SL_ClampCylinder_Relax, IO_Type.SL_ClampCylinder_Work);

        }
        private void SendOutShelfOut(string msg = "")
        {
            MoveInfo.NextMoveStep(LineMoveStep.FO_51_BatchAxisToP2);
            OutStoreHeight = -1;
            //包装料会发往分盘区, 紧急料区, 包装线区
            // urgentReel 这个为true是紧急料   出到紧急料区
            // cutReel 为true是分盘料,AGV会拉到到分盘区
            //料串会发到分盘区和紧急料区
            //两个都为false 包装料默认拉到包装线体, 料串默认拉到紧急料区
            if (CurrShelfId.Equals("00"))
            {
                //料架号无效送出的,不发mark
                LastOutShelfId = CurrShelfId + "";
            }
            else
            {
                BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP2, Config.BatchAxis_P2Speed);
                if (MoveInfo.MoveParam.urgentReel)
                {
                    //紧急料,需要到紧急料区
                    LastOutShelfId = CurrShelfId + ",urgent";
                }
                else if (MoveInfo.MoveParam.cutReel)
                {
                    //cutReel 为true是分盘料,AGV会拉到到分盘区
                    LastOutShelfId = CurrShelfId + ",cut";
                }
                else
                {
                    LastOutShelfId = CurrShelfId + ",urgent";
                }
            }
            OutLog("紧急出料完成, " + MoveInfo.SLog + ":" + msg + ",送出料串,提升伺服到P2点,重置OutStoreHeight=-1,更新LastOutShelfId=" + LastOutShelfId);
        }
        #endregion
    }
}