MoveEquip_Partial.cs 55.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;

namespace OnlineStore.DeviceLibrary
{
    partial class MoveEquip
    {

        #region 出库 

        private int ClampCount = 0;
        public override bool StartOutStoreMove(InOutParam param)
        {
            string posId = param != null ? param.PosId : "";

            if (param.Equals(null))
            {
                LogUtil.error(Name + "出库【" + posId + "】失败,param=null");
                return false;
            }
            if (runStatus.Equals(LineRunStatus.Runing))
            {
                LogInfo("启动出库【" + posId + "】升降气缸上升 ");
                runStatus = LineRunStatus.Busy;
                MoveInfo.NewMove(LineMoveType.OutStore);
                MoveInfo.MoveParam = param;
                MoveInfo.NextMoveStep(LineMoveStep.MO_50_StartOutProcess);
                UpdownUpMove();
                //   TrayManager.AddNeedEmptyTrayNum();
                return true;
            }
            else
            {
                LogUtil.error(Name + " 启动出库【" + posId + "】失败,runStatus=" + runStatus);
                return false;
            }
        }
        protected override void OutStoreProcess()
        {
            string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosId : "";
            if (MoveInfo.IsInWait)
            {
                CheckWait(MoveInfo);
            }
            if (SecondMoveInfo.IsInWait)
            {
                CheckWait(SecondMoveInfo);
            }
            if (MoveInfo.IsInWait)
            {
                return;
            }
            #region 移载装置 移栽物品操作
            if (MoveInfo.IsStep(LineMoveStep.MO_50_StartOutProcess))
            {
                if (UpdownIsUp())
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MO_51_CylinderBefore);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    OutLog("出库 " + MoveInfo.MoveStep + ": 前后气缸前进,等待夹爪料盘检测信号=LOW");
                    CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_After, IO_Type.BeforeAfterCylinder_Before);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampCylinder_Check, IO_VALUE.LOW));
                }
                else
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MO_50_StartOutProcess);
                    OutLog("出库 " + MoveInfo.MoveStep + ": 升降气缸上升");
                    UpdownUpMove();
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.MO_51_CylinderBefore))
            {
                //重置夹料次数=0
                ClampCount = 0;
                if (CylinderIsOk(IO_Type.BeforeAfterCylinder_After, IO_Type.BeforeAfterCylinder_Before))
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MO_52_CylinderDown);
                    OutLog("出库 " + MoveInfo.SLog + ": 上下气缸下降 ");
                    UpdownDownP3Move(MoveInfo.MoveParam.PlateH, MoveInfo.MoveParam.PlateW);
                    // CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Up, IO_Type.UpDownCylinder_Down);
                }
                else
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MO_51_CylinderBefore);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    OutLog("出库 " + MoveInfo.MoveStep + ": 前后气缸前进");
                    CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_After, IO_Type.BeforeAfterCylinder_Before);
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.MO_52_CylinderDown))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MO_53_DownWait);
                OutLog("出库 " + MoveInfo.SLog + ": 等待200ms后夹紧");
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
            }
            else if (MoveInfo.IsStep(LineMoveStep.MO_53_DownWait))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MO_54_CylinderOpen);
                OutLog("出库 " + MoveInfo.SLog + ":  夹料气缸夹紧,更新料盘位置【" + MoveInfo.MoveParam.WareCode + "】【MOVING】【" + DeviceID + "】");
                CylinderMove(MoveInfo, IO_Type.ClampCylinder_Relax, IO_Type.ClampCylinder_Work);

                //更新料盘位置
                SServerManager.UpdateTrayLoc(Name, MoveInfo.MoveParam.WareCode, LocStatus.MOVING, DeviceID.ToString());

            }
            else if (MoveInfo.IsStep(LineMoveStep.MO_54_CylinderOpen))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MO_55_CylinderUp);
                OutLog("出库 " + MoveInfo.SLog + ":  上下气缸上升");
                UpdownUpMove();
                //   CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);

            }
            else if (MoveInfo.IsStep(LineMoveStep.MO_56_ResetClamp))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MO_52_CylinderDown);
                OutLog("出库 " + MoveInfo.SLog + ": 上下气缸下降 ");
                UpdownDownP3Move(MoveInfo.MoveParam.PlateH, MoveInfo.MoveParam.PlateW);
            }
            else if (MoveInfo.IsStep(LineMoveStep.MO_55_CylinderUp))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MO_57_ClampCheck);
                if (ClampCount.Equals(0))
                {
                    OutLog("出库 " + MoveInfo.SLog + ":  检测夹爪料盘检测=HIGH,超时1000");
                    MoveInfo.OneWaitCanEndStep = true;
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampCylinder_Check, IO_VALUE.HIGH));
                }
                else
                {
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
                    OutLog("出库 " + MoveInfo.SLog + ":  检测夹爪料盘检测=HIGH ,超时200ms"); 
                    MoveInfo.OneWaitCanEndStep = true;
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampCylinder_Check, IO_VALUE.HIGH));
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.MO_57_ClampCheck))
            {
                if (UpdownIsUp())
                {

                    //判断夹爪是否有料,无料打印日志
                    if (IOValue(IO_Type.ClampCylinder_Check).Equals(IO_VALUE.LOW))
                    { 
                        OutLog("出库 " + MoveInfo.SLog + ":  夹爪料盘检测信号=LOW");
                    }

                    if (IOValue(IO_Type.ClampCylinder_Check).Equals(IO_VALUE.HIGH) || ClampCount > 0)
                    {
                        if (IsBigStore())
                        {
                            MoveInfo.NextMoveStep(LineMoveStep.MO_58_WaitTray);
                            OutLog("出库 " + MoveInfo.SLog + ":  等待托盘到达");
                        }
                        else
                        {
                            MoveInfo.NextMoveStep(LineMoveStep.MO_59_CylinderAfter);
                            MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
                            OutLog("出库 " + MoveInfo.SLog + ":  前后气缸后退");
                            CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
                        }
                    }
                    else
                    {
                        MoveInfo.NextMoveStep(LineMoveStep.MO_56_ResetClamp);
                        ClampCount = 1;
                        OutLog("出库 " + MoveInfo.SLog + ":  第一次未抓到料,重新抓一次,夹爪先放松", 1);
                        CylinderMove(MoveInfo, IO_Type.ClampCylinder_Work, IO_Type.ClampCylinder_Relax);
                    }
                }
                else
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MO_55_CylinderUp);
                    OutLog("出库 " + MoveInfo.SLog + ":  上下气缸上升");
                    UpdownUpMove();
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.MO_58_WaitTray))
            {
                if (TrayIsOk())
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MO_59_CylinderAfter);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
                    OutLog("出库 " + MoveInfo.SLog + ":  前后气缸后退");
                    CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
                }
            }
            #endregion

            #region 移载装置,放物品到流水线操作
            else if (MoveInfo.IsStep(LineMoveStep.MO_59_CylinderAfter))
            {
                if (CylinderIsOk(IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After))
                {
                    if (TrayIsOk())
                    {
                        int trayNum = SecondMoveInfo.MoveParam.TrayNumber;
                        //去掉直接丢盘处理
                        MoveInfo.NextMoveStep(LineMoveStep.MO_60_CylinderDown);
                        OutLog("出库 " + MoveInfo.SLog + ": 拦截到空托盘【" + trayNum + "】, 上下气缸下降 ,顶升气缸上升");
                        if (MoveInfo.MoveParam != null)
                        {
                            MoveInfo.MoveParam.TrayNumber = trayNum;
                        }
                        else
                        {
                            MoveInfo.MoveParam = SecondMoveInfo.MoveParam;
                        }

                        UpdownDownP2Move(MoveInfo.MoveParam.PlateH, MoveInfo.MoveParam.PlateW);
                        CylinderMove(MoveInfo, IO_Type.TopCylinder_Down, IO_Type.TopCylinder_Up);
                    }
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.MO_60_CylinderDown))
            {
                OutLog("出库 " + MoveInfo.SLog + ":    夹料气缸放松, ");
                int trayNum = MoveInfo.MoveParam.TrayNumber;
                //更新料盘位置
                SServerManager.UpdateTrayLoc(Name, MoveInfo.MoveParam.WareCode, LocStatus.INLINE, "E" + trayNum.ToString().PadLeft(2, '0'));
                TrayManager.UpdateTrayInfo(MoveInfo.MoveParam.TrayNumber, true, ReelType.OutStore, MoveInfo.MoveParam.Clone());
                TrayInfo tray = TrayManager.GetTrayInfo(MoveInfo.MoveParam.TrayNumber);
                LogInfo("出库 " + MoveInfo.SLog + ":    夹料气缸放松,更新料盘位置【" + MoveInfo.MoveParam.WareCode + "】【INLINE】更新托盘【" + trayNum + "】 " + tray.ToStr() + "");
                //出库全部完成  
                MoveInfo.NextMoveStep(LineMoveStep.MO_61_CylinderRelax);
                CylinderMove(MoveInfo, IO_Type.ClampCylinder_Work, IO_Type.ClampCylinder_Relax);
            }
            else if (MoveInfo.IsStep(LineMoveStep.MO_61_CylinderRelax))
            {
                this.MoveInfo.NextMoveStep(LineMoveStep.MO_62_CylinderUp);
                OutLog("出库 " + MoveInfo.SLog + ": 上下气缸上升,同时顶升气缸先下降");
                UpdownUpMove();
                CylinderMove(null, IO_Type.TopCylinder_Up, IO_Type.TopCylinder_Down);
            }
            else if (MoveInfo.IsStep(LineMoveStep.MO_62_CylinderUp))
            {
                //  减去需要的盘数
                //  TrayManager.DelNeedEmptyTrayNum();
                OutLog("出库  :移栽完成,放行托盘");
                SecondMoveInfo.NewMove(LineMoveType.Fixture);
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_14_TopDown);
                CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_Up, IO_Type.TopCylinder_Down);

                OutLog("出库处理结束!");
                MoveEndS();
            }

            #endregion
        }
        private bool TrayIsOk()
        {
            if (SecondMoveInfo.IsStep(LineMoveStep.MO_11_CodeRember) && !SecondMoveInfo.IsInWait)
            {
                ClearTimeoutAlarm("等待空托盘到达超时");
                return true;
            }
            else if (MoveInfo.IsTimeOut(180))
            {
                MoveTimeoutAlarm(MoveInfo, "等待空托盘到达超时");
                return false;
            }
            return false;
        }
        private bool IsBigStore()
        {
            return Config.IsBigTray.Equals(1);
        }
        #endregion

        #region 入库
        /// <summary>
        /// 入库移动移动
        /// </summary> 
        public override bool StartInStoreMove(InOutParam param)
        {
            string posId = param != null ? param.PosId : "";
            if (runStatus.Equals(LineRunStatus.Runing))
            {
                runStatus = LineRunStatus.Busy;
                MoveInfo.MoveParam = param;
                MoveInfo.NewMove(LineMoveType.InStore);

                if (UpdownIsUp())
                {
                    LogInfo("入库【" + posId + "】处理(移栽):MI_02_ToLineUp, 前后气缸后退,等待夹爪检测=LOW");
                    MoveInfo.NextMoveStep(LineMoveStep.MI_02_ToLineUp);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampCylinder_Check, IO_VALUE.LOW));
                }
                else
                {
                    LogInfo("入库【" + posId + "】处理(移栽):MI_01_UpdownUp, 顶升气缸先上升");
                    MoveInfo.NextMoveStep(LineMoveStep.MI_01_UpdownUp);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    UpdownUpMove();
                }
                return true;
            }
            else
            {
                LogUtil.error(Name + " 启动一个 入库【" + posId + "】运动失败,当前状态,storeStatus=" + runStatus);
            }
            return false;
        }

        protected override void InStoreProcess()
        {
            if (MoveInfo.IsInWait)
            {
                CheckWait(MoveInfo);
            }
            if (SecondMoveInfo.IsInWait)
            {
                CheckWait(SecondMoveInfo);
            }
            if (MoveInfo.IsInWait)
            {
                return;
            }
            string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosId : "";
            if (MoveInfo.IsStep(LineMoveStep.MI_01_UpdownUp))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_02_ToLineUp);
                InLog("入库 " + MoveInfo.SLog + ":  前后气缸后退,等待夹爪检测=LOW");
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(100));
                CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampCylinder_Check, IO_VALUE.LOW));
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_02_ToLineUp))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_03_CylinderDown);
                InLog("入库 " + MoveInfo.SLog + ":  升降下降,顶升上升");
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
                UpdownDownP2Move(MoveInfo.MoveParam.PlateH, MoveInfo.MoveParam.PlateW);
                CylinderMove(MoveInfo, IO_Type.TopCylinder_Down, IO_Type.TopCylinder_Up);
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_03_CylinderDown))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_04_DownWait);
                InLog("入库 " + MoveInfo.SLog + ":  等待200ms后夹紧");
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
            }
            //只有当BOX可以进行出入库时,移栽物品,防止卡住
            else if (MoveInfo.IsStep(LineMoveStep.MI_04_DownWait))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_05_CylinderOpen);
                InLog("入库 " + MoveInfo.SLog + ":  夹料气缸夹紧");
                CylinderMove(MoveInfo, IO_Type.ClampCylinder_Relax, IO_Type.ClampCylinder_Work);
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_05_CylinderOpen))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_06_CylinderUp);
                InLog("入库 " + MoveInfo.SLog + ":  上下气缸上升");
                UpdownUpMove();
                CylinderMove(null, IO_Type.TopCylinder_Up, IO_Type.TopCylinder_Down);
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_06_CylinderUp))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_07_ClampCheck);
                InLog("入库 " + MoveInfo.SLog + ":  等待抓到料盘:夹爪料盘检测信号=HIGH,最多等待10秒");

                MoveInfo.TimeOutSeconds = 15;
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampCylinder_Check, IO_VALUE.HIGH));
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(10000));
                MoveInfo.OneWaitCanEndStep = true;
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_07_ClampCheck))
            {
                //判断是否拿起来料
                if (IOValue(IO_Type.ClampCylinder_Check).Equals(IO_VALUE.HIGH))
                {
                    InLog("入库 " + MoveInfo.SLog + ":成功抓取料盘");
                    int num = MoveInfo.MoveParam.TrayNumber;
                    MoveInfo.NextMoveStep(LineMoveStep.MI_10_WaitBox);
                    LogInfo("入库【" + posId + "】 " + MoveInfo.SLog + ":  物品(高" + MoveInfo.MoveParam.PlateH + ")已移走,更新托盘【" + num + "】为空盘,删除入库任务");
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitBoxCanReviceTray());
                    TrayManager.UpdateTrayInfo(num);
                    RemoveInStore(MoveInfo.MoveParam);
                    if (MoveInfo.MoveParam.PlateH < 44)
                    {
                        InLog("放托盘(放开阻挡): " + MoveInfo.SLog + " 物品已移走,顶升气缸1下降");
                        SecondMoveInfo.NextMoveStep(LineMoveStep.MO_14_TopDown);
                        CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_Up, IO_Type.TopCylinder_Down);
                    }
                }
                else
                {
                    //int num = MoveInfo.MoveParam.TrayNumber;
                    //InLog("入库 " + MoveInfo.SLog + ":抓取料盘失败,取消入库任务,清空托盘[" + num + "]信息。报警:未抓起料盘,请取走料盘后复位。");
                    ////未抓起料盘,直接报警
                    //MoveInfo.NextMoveStep(LineMoveStep.MI_07_ClampCheck);
                    //MoveInfo.WaitList.Add(WaitResultInfo.WaitNoTrayAlarm());
                    //SetWarnMsg("未抓起料盘,请取走料盘后复位", MoveInfo.GetStepDes() + "_" + "未抓起料", MoveInfo);
                    //Alarm(LineAlarmType.IoSingleTimeOut);

                    //TrayInfo tray = TrayManager.GetTrayInfo(num);
                    //LogUtil.error(Name + " 抓料失败自动清空入库任务 :" + tray.InoutPar.ToStr());
                    //TrayManager.ClearInstore(tray, "抓料失败自动清空入库任务");
                    //TrayManager.UpdateTrayInfo(num);

                    MoveInfo.NextMoveStep(LineMoveStep.MI_21_CylinderDown);
                    int num = MoveInfo.MoveParam.TrayNumber;
                    InLog("入库 " + MoveInfo.SLog + ":抓取料盘失败,取消入库任务,更新托盘[" + num + "]为NG ,将料再放到托盘上");
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
                    UpdownDownP2Move(MoveInfo.MoveParam.PlateH, MoveInfo.MoveParam.PlateW);
                    TrayInfo tray = TrayManager.GetTrayInfo(num);
                    TrayManager.ClearInstore(tray, "抓料失败自动清空入库任务");
                    TrayManager.UpdateInStoreNG(num, true, "入库抓料失败");
                    InLog("入库: " + MoveInfo.SLog + " 抓料失败,升降气缸下降");
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_21_CylinderDown))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_22_CylinderRelax);
                InLog("入库: " + MoveInfo.SLog + " 抓料失败,夹爪放松");
                CylinderMove(MoveInfo, IO_Type.ClampCylinder_Work, IO_Type.ClampCylinder_Relax);
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_22_CylinderRelax))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_23_UpdownUp);
                InLog("入库: " + MoveInfo.SLog + " 抓料失败,升降上升");
                UpdownUpMove();
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_23_UpdownUp))
            {
                LogInfo("入库【" + posId + "】抓料失败,已放料回托盘,放托盘离开"); 
                InLog("放托盘(放开阻挡): " + MoveInfo.SLog + " 物品已移走,顶升气缸1下降");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_14_TopDown);
                CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_Up, IO_Type.TopCylinder_Down); 
                MoveEndS();
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_10_WaitBox))
            {
                if (UpdownIsUp())
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MI_08_CylinderBefore);
                    InLog("入库: " + MoveInfo.SLog + " 前后气缸1前进");
                    CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_After, IO_Type.BeforeAfterCylinder_Before);
                }
                else
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MI_10_WaitBox);
                    InLog("入库: " + MoveInfo.SLog + " 升降气缸上升");
                    UpdownUpMove();
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_08_CylinderBefore))
            {
                if (CylinderIsOk(IO_Type.BeforeAfterCylinder_After, IO_Type.BeforeAfterCylinder_Before))
                {
                    if (MoveInfo.MoveParam.PlateH >= 44)
                    {
                        InLog("放托盘(放开阻挡): " + MoveInfo.SLog + " 物品已移走,顶升气缸1下降");
                        SecondMoveInfo.NextMoveStep(LineMoveStep.MO_14_TopDown);
                        CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_Up, IO_Type.TopCylinder_Down);
                    }
                    MoveInfo.NextMoveStep(LineMoveStep.MI_11_CylinderDown);
                    InLog("入库 " + MoveInfo.SLog + " ,上下气缸下降");
                    UpdownDownP3Move(MoveInfo.MoveParam.PlateH, MoveInfo.MoveParam.PlateW);
                }
                else
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MI_08_CylinderBefore);
                    InLog("入库: " + MoveInfo.SLog + " 前后气缸1前进");
                    CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_After, IO_Type.BeforeAfterCylinder_Before);
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_11_CylinderDown))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_12_CylinderRelax);
                InLog("入库 " + MoveInfo.SLog + ",夹料气缸放松");
                CylinderMove(MoveInfo, IO_Type.ClampCylinder_Work, IO_Type.ClampCylinder_Relax);
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_12_CylinderRelax))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_13_UpdownCylinderUp);
                InLog("入库 " + MoveInfo.SLog + ",上下气缸上升");
                UpdownUpMove();
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_13_UpdownCylinderUp))
            {
                if (UpdownIsUp())
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MI_14_CylinderAfter);
                    InLog("入库 " + MoveInfo.SLog + ",前后气缸后退,等待300 ");
                    CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(300));
                    //此时box就可以入库操作了                //触发事件,BOX入库
                    //  LineServer.StartInStore(DeviceID, MoveInfo.MoveParam);
                }
                else
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MI_13_UpdownCylinderUp);
                    InLog("入库 " + MoveInfo.SLog + ",上下气缸上升");
                    UpdownUpMove();
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_14_CylinderAfter))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_15_SendPosToStore);
                InLog("入库 " + MoveInfo.SLog + ",通知BOX开始入库,等待3000");
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000));
                LineServer.StartInStore(DeviceID, MoveInfo.MoveParam);
                sendCount = 1;
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_15_SendPosToStore))
            {
                String notOkMsg = "";
                if (!LineServer.IsInStorePro(DeviceID, MoveInfo.MoveParam.PosId, out notOkMsg))
                {
                    //InLog("入库 " + MoveInfo.SLog + " , 送料流程完成,料仓还未开始入库,再次发送starIn命令");
                    //LineServer.StartInStore(DeviceID, MoveInfo.MoveParam);

                    MoveInfo.NextMoveStep(LineMoveStep.MI_15_SendPosToStore);
                    InLog("入库 " + MoveInfo.SLog + ",再次通知BOX开始入库,等待3000");
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000));
                    LineServer.StartInStore(DeviceID, MoveInfo.MoveParam);
                    sendCount++;

                    if (sendCount >= 3)
                    {
                        SetWarnMsg(MoveInfo.Name + "[" + MoveInfo.MoveStep + "] " + " 等待BOX开始入库超时 " + notOkMsg + "  已发送" + sendCount + "次", "等待BOX开始入库超时");
                        //WarnMsg = MoveInfo.Name + "[" + MoveInfo.MoveStep + "] " + " 等待BOX开始入库超时  已发送" + sendCount + "次";
                        //LogUtil.error(WarnMsg);
                        Alarm(LineAlarmType.IoSingleTimeOut);
                    }
                }
                else
                {
                    sendCount = 0;
                    LogInfo("入库【" + posId + "】处理(移栽)全部完成!");
                    MoveEndS();
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.MI_16_SendEnd))
            {
                sendCount = 0;
                LogInfo("入库【" + posId + "】处理(移栽)全部完成!");
                MoveEndS();
            }
        }
        private int sendCount = 0;
        private bool IsInStoreNeed()
        {

            if (waitInStoreList.Count > 0)
            {
                lock (waitInListLock)
                {
                    bool needRemove = false;
                    int index = 0;
                    //判断是否是自己排队列表中的入库信息 
                    foreach (InOutParam cc in waitInStoreList)
                    {
                        if (cc.TrayNumber.Equals(currTrayNum) && (!cc.PosId.Equals("")))
                        {
                            //判断是否验证成功,如果验证失败,不入库
                            if (LineServer.RightInPosId(DeviceID, cc.PosId))
                            {
                                SecondMoveInfo.MoveParam = new InOutParam(cc.TrayNumber, cc.WareCode, cc.PosId, cc.PlateH, cc.PlateW, cc.IsNG);
                                return true;
                            }
                            else
                            {
                                SecondMoveInfo.MoveParam = new InOutParam(cc.TrayNumber, cc.WareCode, cc.PosId, cc.PlateH, cc.PlateW, cc.IsNG);
                                LogUtil.error(Name + "托盘号【" + currTrayNum + "】入库信息【" + cc.ToStr() + "】料仓未验证成功,重新发送验证消息");
                                LineServer.CheckInStorePos(DeviceID, cc);
                                return true;
                            }
                        }
                        index++;
                    }
                    if (needRemove && index >= 0 && index < waitInStoreList.Count)
                    {
                        waitInStoreList.RemoveAt(index);
                        LogUtil.info("从waitInStoreList中删除 index=" + index + "的任务");
                    }
                }
            }
            return false;
        }

        /// <summary>
        /// 是否需要出库的托盘
        /// </summary>
        /// <param name="currMoveTrayNum"></param>
        /// <returns></returns>
        private bool CheckIsNeedOutStore()
        {
            if (currTrayNum <= 0)
            {
                return false;
            }
            bool isFull = TrayManager.TrayIsFull(currTrayNum);
            if (isFull)
            {
                return false;
            }
            bool moveOk = (IsBigStore() && MoveInfo.MoveStep >= LineMoveStep.MO_58_WaitTray) || MoveInfo.MoveStep >= LineMoveStep.MO_59_CylinderAfter;
            if (MoveInfo.MoveType.Equals(LineMoveType.OutStore) && moveOk
                 && (!MoveInfo.IsStep(LineMoveStep.MO_62_CylinderUp)))
            {
                if (isFull.Equals(false))
                {
                    LogInfo(" 出库中,拦截空托盘【 " + currTrayNum + "】~");
                    return true;
                }
            }
            return false;
        }

        internal bool IsWaitEmptyTray()
        {
            if (isInSuddenDown || isNoAirCheck)
            {
                return false;
            }
            bool moveOk = (IsBigStore() && MoveInfo.MoveStep >= LineMoveStep.MO_58_WaitTray) || MoveInfo.MoveStep >= LineMoveStep.MO_59_CylinderAfter;
            if (MoveInfo.MoveType.Equals(LineMoveType.OutStore) && moveOk
                 && (!MoveInfo.IsStep(LineMoveStep.MO_62_CylinderUp)))
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 判断盘号是否需要入库
        /// </summary>
        /// <returns></returns>
        private bool CheckIsNeedInStore()
        {
            if (currTrayNum <= 0)
            {
                return false;
            }
            if (LineManager.DisGetWare)
            {
                return false;
            }
            //如果正在出库执行中,不能拦截入库托盘
            if (MoveInfo.MoveType.Equals(LineMoveType.OutStore))
            {
                return false;
            }
            else if (waitOutStoreList.Count > 0)
            {
                return false;
            }

            bool isfull = TrayManager.TrayIsFull(currTrayNum);
            if (!isfull)
            {
                return false;
            }

            InOutParam currCode = null;
            TrayInfo tray = TrayManager.GetTrayInfo(currTrayNum);

            if (waitInStoreList.Count > 0)
            {
                lock (waitInListLock)
                {
                    //判断是否是自己排队列表中的入库信息
                    int reIndex = -1;
                    for (int i = 0; i < waitInStoreList.Count; i++)
                    {
                        InOutParam cc = waitInStoreList[i];
                        if (cc.TrayNumber.Equals(currTrayNum) && (!cc.WareCode.Equals("")))
                        {
                            reIndex = i;
                            currCode = cc;
                            SecondMoveInfo.MoveParam = new InOutParam(cc.TrayNumber, cc.WareCode, cc.PosId, cc.PlateH, cc.PlateW, cc.IsNG);
                            break;
                        }
                    }
                    if (reIndex >= 0)
                    {
                        if (currCode.PosId.Equals(tray.InoutPar.PosId) && tray.InOrOutStore.Equals(1) && tray.InoutPar.IsNG.Equals(false))
                        {
                            if (!LineServer.BoxCanInStore(DeviceID))
                            {
                                LogInfo("*******托盘" + currTrayNum + "需要入库【" + currCode.ToStr() + "】,BoxCanInStore验证失败,先放托盘通过");
                                return false;
                            }
                            else
                            {
                                //判断是否验证成功,如果验证失败,不入库
                                if (LineServer.RightInPosId(DeviceID, currCode.PosId))
                                {
                                    //waitInStoreList.RemoveAt(reIndex);
                                    LogInfo("*******托盘" + currTrayNum + "需要入库【" + currCode.ToStr() + "】 ,开始入库移栽");
                                    return true;
                                }
                                else
                                {
                                    LogUtil.error(Name + "托盘号【" + currTrayNum + "】入库信息【" + currCode.ToStr() + "】料仓未验证成功,更新为入库NG料,从waitInStoreList中删除" + reIndex + ",取消入库任务");
                                    TrayManager.UpdateInStoreNG(currTrayNum, true, "Box验证入库失败");
                                    waitInStoreList.RemoveAt(reIndex);
                                    SServerManager.cancelPutInTask(Name, currCode.WareCode, true);
                                    return false;
                                }
                            }
                        }
                        else
                        {
                            LogUtil.error(Name + "托盘信息 " + tray.ToStr() + " 与入库任务 " + currCode.ToStr() + " 不一致,从waitInStoreList中删除" + reIndex + ",取消入库任务");
                            waitInStoreList.RemoveAt(reIndex);
                            SServerManager.cancelPutInTask(Name, currCode.WareCode, true);
                            return false;
                        }
                    }
                }
            }

            return false;
        }
        public bool RemoveInStore(InOutParam param, string logName = "料盘已移走")
        {
            if (waitInStoreList.Count > 0)
            {
                lock (waitInListLock)
                {
                    //判断是否是自己排队列表中的入库信息
                    int reIndex = -1;
                    for (int i = 0; i < waitInStoreList.Count; i++)
                    {
                        InOutParam cc = waitInStoreList[i];
                        //托盘号一致,二维码一致,库位号一致
                        if (cc.TrayNumber.Equals(param.TrayNumber) && cc.PosId.Equals(param.PosId) && cc.WareCode.Equals(param.WareCode))
                        {
                            reIndex = i;
                            break;
                        }
                    }
                    if (reIndex >= 0)
                    {
                        waitInStoreList.RemoveAt(reIndex);
                        LogInfo("*******" + logName + ",清理入库任务:【" + param.ToStr() + "】");
                        return true;
                    }
                }
            }

            return false;
        }
        public bool RemoveOutStore(InOutParam param, string logName = "料盘已移走")
        {
            if (waitOutStoreList.Count > 0)
            {
                //判断是否是自己排队列表中的出库信息
                //托盘号一致,二维码一致,库位号一致
                List<InOutParam> paramList = (from m in waitOutStoreList where m.TrayNumber.Equals(param.TrayNumber) && m.PosId.Equals(param.PosId) && m.WareCode.Equals(param.WareCode) select m).ToList<InOutParam>();
                if (paramList!=null && paramList.Count > 0)
                {
                    waitInStoreList.RemoveAt(0);
                    LogInfo("*******" + logName + ",清理出库任务:【" + param.ToStr() + "】");
                    return true;
                }

            }

            return false;
        }
        #endregion

        #region 托盘检测
        private Stopwatch trayCheckWait = new Stopwatch();
        private Stopwatch trayCheck2LowWait = new Stopwatch();
        private object lockObj = "";
        private void CheckFixture()
        {
            if (Monitor.TryEnter(lockObj, TrayManager.mTimeOut))
            {
                try
                {
                    if (SecondMoveInfo.MoveType.Equals(LineMoveType.None).Equals(false))
                    {
                        if (IOValue(IO_Type.StopCheck2).Equals(IO_VALUE.HIGH))
                        {
                            trayCheck2LowWait.Stop();
                        }
                        else
                        {
                            CheckStopWatch(trayCheck2LowWait, 30000, false);
                        }
                        LogUtil.error(Name + "  CheckFixture " + " 不在空闲中,直接返回 ");
                        return;
                    }
                    if (SecondMoveInfo.MoveType.Equals(LineMoveType.None))
                    {
                        //bool canpro = LineManager.Line.Move5CanProcessTray(DeviceID);
                        bool canpro = true;
                        if (IOValue(IO_Type.StopCheck2).Equals(IO_VALUE.HIGH))
                        {
                            trayCheck2LowWait.Stop();
                            if (canpro && CheckStopWatch(trayCheckWait, TrayWaitTime, true))
                            {
                                SecondMoveInfo.NewMove(LineMoveType.Fixture);
                                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_03_StopUp);

                                CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "  阻挡气缸1-1上升)");
                                IOMove(IO_Type.StopDown1, IO_VALUE.LOW);
                                IOMove(IO_Type.StopDown2, IO_VALUE.LOW);
                                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopDown1, IO_VALUE.LOW));
                            }
                        }
                        else
                        {
                            bool check2IsOk = CheckStopWatch(trayCheck2LowWait, TrayWaitTime, false);
                            if (IOValue(IO_Type.StopCheck1).Equals(IO_VALUE.HIGH))
                            {
                                if (CheckStopWatch(trayCheckWait, TrayWaitTime, false) && check2IsOk && canpro)
                                {
                                    StopDownCount = 0;
                                    trayCheckWait.Stop();
                                    trayCheck2LowWait.Stop();
                                    //托盘在第一个阻挡处
                                    SecondMoveInfo.NewMove(LineMoveType.Fixture);
                                    SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down);
                                    CheckLog(" 托盘检测:料盘检测StopCylinder_Check1 " + SecondMoveInfo.SLog + "阻挡气缸1-1下降 , 等待  StopCylinder_Check1=0,清理托盘RFID");
                                    ClearTrayRFID();
                                    IOMove(IO_Type.StopDown2, IO_VALUE.LOW);
                                    IOMove(IO_Type.StopDown1, IO_VALUE.HIGH, TrayManager.StopDTime);
                                    SecondMoveInfo.OneWaitCanEndStep = true;
                                    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCheck1, IO_VALUE.LOW));
                                    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCheck2, IO_VALUE.HIGH));
                                    //最多等待30秒
                                    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(30000));
                                }
                            }
                            else
                            {
                                trayCheckWait.Stop();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.error(Name + "  CheckFixture " + " 出错:" + ex.ToString());
                }
                finally
                {
                    Monitor.Exit(lockObj);
                }
            }
            else
            {
                LogUtil.error(Name + "  CheckFixture " + "失败,未得到锁");
            }
        }

        private int StopDownCount = 0;
        protected override void FixtureProcess()
        {
            if (!LineManager.Line.CanProcessLine())
            {
                return;
            }
            if (SecondMoveInfo.IsInWait)
            {
                CheckWait(SecondMoveInfo);
            }
            if (SecondMoveInfo.IsInWait)
            {
                return;
            }

            #region 托盘检测
            if (SecondMoveInfo.IsStep(LineMoveStep.MIO_00_Stop1Down))
            {
                if (IOValue(IO_Type.StopCheck1).Equals(IO_VALUE.LOW))
                {
                    SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_01_StopDownWait);
                    CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "   前阻挡检测消失后再等待300ms上升阻挡");
                    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(300));
                }
                else
                {
                    MIO_02_TrayCheck();
                }
            }
            else if (SecondMoveInfo.IsStep(LineMoveStep.MIO_01_StopDownWait))
            {
                MIO_02_TrayCheck();
            }
            else if (SecondMoveInfo.IsStep(LineMoveStep.MIO_02_TrayCheck))
            {
                if (IOValue(IO_Type.StopCheck2).Equals(IO_VALUE.HIGH))
                {
                    SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_03_StopUp);
                    CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "  再次等待托盘信号");
                    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCheck2, IO_VALUE.HIGH));
                }
                else
                {
                    ////未检测到信号或阻挡下降失败,结束处理
                    //LogInfo(SecondMoveInfo.SLog + "未等到信号   StopCheck2=HIGH,结束处理 ");
                    //SecondMoveInfo.EndMove();

                    EndOrReStopDown("未等到信号   StopCheck2=HIGH,结束处理");
                }
            }
            else if (SecondMoveInfo.IsStep(LineMoveStep.MIO_03_StopUp))
            {
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_04_Wait);
                CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "  ,等待编码信号稳定StopCylinder_Check2=1");
                CheckAndMove(IO_Type.StopDown1, IO_VALUE.LOW);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCheck2, IO_VALUE.HIGH));
            }
            else if (SecondMoveInfo.IsStep(LineMoveStep.MIO_04_Wait))
            {
                try
                {
                    //判断是否需要顶升
                    bool isNeed = false;
                    bool result = UpdateTrayNum();
                    bool isFull = TrayManager.TrayIsFull(currTrayNum);
                    if (result)
                    { 
                        //出库中,需要拦盘
                        if (CheckIsNeedOutStore())
                        {
                            isNeed = true;
                        }
                        else if (isFull && IsInStoreNeed())
                        {
                            isNeed = true;
                        }
                    }
                    if (isNeed)
                    {
                        SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_05_WaitTime);
                        CheckLog("托盘阻挡" + SecondMoveInfo.SLog + " 等待200");
                        SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
                    }
                    else
                    {
                        LogUtil.debug(Name + SecondMoveInfo.MoveNum + "***************上个托盘号【" + preTrayNum + "】,当前" + (isFull ? "有料托盘" : "空托盘") + "【" + currTrayNum + "】没有出入库任务,放盘通过~");
                        //  preTrayNum = currMoveTrayNum;
                        if (TrayManager.ErrorDeviceId.Equals(DeviceID))
                        {
                            TrayManager.UpdateTrayNumError(-1, "");
                        }
                        SecondMoveInfo.NextMoveStep(LineMoveStep.MO_15_WaitCanGo);
                        SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(100));

                    }
                }
                catch (Exception ex)
                {
                    LogUtil.error("判断托盘是否需要顶升出错:", ex);
                }
            }
            else if (SecondMoveInfo.IsStep(LineMoveStep.MIO_05_WaitTime))
            {
                //如果是出库,且盘高大于30,暂不顶升
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_06_TopUp);

                if (MoveInfo.MoveType.Equals(LineMoveType.OutStore))
                {
                    if (MoveInfo.MoveParam != null && MoveInfo.MoveParam.PlateH >= 30)
                    {
                        CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "  高度>30,暂不顶升上升");
                    }
                }
                else if (SecondMoveInfo.MoveParam != null)
                {
                    if (!LineServer.RightInPosId(DeviceID, SecondMoveInfo.MoveParam.PosId))
                    {
                        LogUtil.error(Name + " " + SecondMoveInfo.SLog + "[" + SecondMoveInfo.MoveParam.PosId + "]料仓未验证成功,等待9秒");
                        SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(9000));
                    }
                    if (SecondMoveInfo.MoveParam.PlateH >= 30)
                    {
                        CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "  高度>30,暂不顶升上升");
                    }
                }
                else
                {
                    CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "  顶升气缸上 升 )");
                    CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_Down, IO_Type.TopCylinder_Up);
                }
            }
            else if (SecondMoveInfo.IsStep(LineMoveStep.MIO_06_TopUp))
            {
                CheckLog("托盘阻挡*************** 托盘号【" + currTrayNum + "】");
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(10000));
                //托盘号正确
                //preTrayNum = num;
                bool isNeedMove = false;
                //判断盘是空盘,空盘并且编号正确才需要放料盘过去
                if (CheckIsNeedOutStore())
                {
                    SecondMoveInfo.MoveParam = new InOutParam(currTrayNum);
                    isNeedMove = true;
                    LogInfo(SecondMoveInfo.MoveNum + "*************** 空托盘【" + currTrayNum + "】,正在出库中,移栽料盘");
                    SecondMoveInfo.NextMoveStep(LineMoveStep.MO_11_CodeRember);
                    SecondMoveInfo.EndStepWait();
                }
                else if (CheckIsNeedInStore())
                {
                    LogInfo(SecondMoveInfo.MoveNum + "*************** 托盘【" + currTrayNum + "】,有对应的入库任务,等待移栽");
                    SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_08_WaitInStore);
                    isNeedMove = true;
                }
                else
                {
                    LogInfo(SecondMoveInfo.MoveNum + "*************** 托盘【" + currTrayNum + "】不需要出入库, 放盘通过");
                }

                if (!isNeedMove)
                {
                    //preTrayNum = num;
                    if (TrayManager.ErrorDeviceId.Equals(DeviceID))
                    {
                        TrayManager.UpdateTrayNumError(-1, "");
                    }
                    SecondMoveInfo.NextMoveStep(LineMoveStep.MO_14_TopDown);
                    CheckLog("托盘检测" + SecondMoveInfo.SLog + " ,托盘号【" + currTrayNum + "】,直接放盘通过,顶升气缸下降 ");
                    CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_Up, IO_Type.TopCylinder_Down);
                }

            }
            else if (SecondMoveInfo.IsStep(LineMoveStep.MIO_08_WaitInStore) && MoveInfo.MoveType.Equals(LineMoveType.None))
            {
                StartInStoreMove(SecondMoveInfo.MoveParam);
                CheckLog("托盘放行" + SecondMoveInfo.SLog + " ,等待移栽完成后放开阻挡)");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_09_WaitTrayCanGo);
            }
            #endregion

            #region 不需要出入库,直接放行
            else if (SecondMoveInfo.IsStep(LineMoveStep.MO_14_TopDown))
            {
                MO_16_Stop2Down();

            }
            else if (SecondMoveInfo.IsStep(LineMoveStep.MO_15_WaitCanGo))
            {
                MO_16_Stop2Down();
            }
            else if (SecondMoveInfo.IsStep(LineMoveStep.MO_16_Stop2Down))
            {
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_17_Stop2Check);
                CheckLog("托盘放行" + SecondMoveInfo.SLog + " , 等待StopCylinder_Check2=0");
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCheck2, IO_VALUE.LOW));
            }
            else if (SecondMoveInfo.IsStep(LineMoveStep.MO_17_Stop2Check))
            {
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_18_WaitTime);
                CheckLog("托盘放行  " + SecondMoveInfo.SLog + " , 等待300ms后阻挡2上升");
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(300));

                //LineManager.Line.Move5Stop2Down(DeviceID);
            }
            else if (SecondMoveInfo.IsStep(LineMoveStep.MO_18_WaitTime))
            {
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_19_StopUp);
                CheckLog("托盘放行" + SecondMoveInfo.SLog + " , 阻挡气缸1-2上升 )");
                IOMove(IO_Type.StopDown2, IO_VALUE.LOW);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(100));
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopDown2, IO_VALUE.LOW));
            }
            else if (SecondMoveInfo.IsStep(LineMoveStep.MO_19_StopUp))
            {
                ClearTrayRFID();
                CheckLog("托盘放行  SecondMove:(托盘放行结束) ");
                SecondMoveInfo.EndMove();
            }
            #endregion
        }

        private void MIO_02_TrayCheck()
        {
            if (IOValue(IO_Type.StopCheck1).Equals(IO_VALUE.LOW) || IOValue(IO_Type.StopCheck2).Equals(IO_VALUE.HIGH))
            {
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_02_TrayCheck);
                CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "   阻挡气缸1-1上升,等待 阻挡2托盘检测=1)");
                SecondMoveInfo.OneWaitCanEndStep = true;
                IOMove(IO_Type.StopDown1, IO_VALUE.LOW);
                IOMove(IO_Type.StopDown2, IO_VALUE.LOW);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCheck2, IO_VALUE.HIGH));
                //最多等待30秒
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(30000));
            }
            else
            {
                EndOrReStopDown("未等到信号 StopCheck1=LOW,或 StopCheck2=HIGH,结束处理");
                ////未检测到信号或阻挡下降失败,结束处理
                //LogInfo(SecondMoveInfo.SLog + "未等到信号 StopCheck1=LOW,或 StopCheck2=HIGH,结束处理 ");
                //SecondMoveInfo.EndMove();
            }
        }

        private void EndOrReStopDown(string msg= "未等到信号   StopCheck2=HIGH,结束处理")
        {
            if (StopDownCount == 0)
            {
                LogInfo(SecondMoveInfo.SLog + msg+",暂不结束,重新下降一次前阻挡");
                //阻挡重新下降一次
                StopDownCount ++; 
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down);
                CheckLog(" 托盘检测:料盘检测StopCylinder_Check1 " + SecondMoveInfo.SLog + "阻挡气缸1-1下降 , 等待  StopCylinder_Check1=0,清理托盘RFID");
                ClearTrayRFID();
                IOMove(IO_Type.StopDown2, IO_VALUE.LOW);
                IOMove(IO_Type.StopDown1, IO_VALUE.HIGH, TrayManager.StopDTime);
                SecondMoveInfo.OneWaitCanEndStep = true;
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCheck1, IO_VALUE.LOW));
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCheck2, IO_VALUE.HIGH));
                //最多等待30秒
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(30000));
            }
            else
            { 
                LogInfo(SecondMoveInfo.SLog + msg);
                SecondMoveInfo.EndMove();
            }
        }

        private void MO_16_Stop2Down()
        {
            if (LineManager.Line.Move5CanStop2Down(DeviceID))
            {
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_16_Stop2Down);
                CheckLog("托盘放行" + SecondMoveInfo.SLog + " ,阻挡气缸1-2下降 ");
                IOMove(IO_Type.StopDown2, IO_VALUE.HIGH);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopDown2, IO_VALUE.HIGH));
            }
            else if (SecondMoveInfo.IsTimeOut(120))
            {
                MoveTimeoutAlarm(SecondMoveInfo, "等待HY8空闲超时");
                //WarnMsg = MoveInfo.Name + "[" + MoveInfo.MoveType + "][" + MoveInfo.SLog + "]等待HY8空闲[" + Math.Round(MoveInfo.StepSpan().TotalSeconds, 1) + "]秒";
                //LogUtil.error(WarnMsg, DeviceID * 1000 + 12);
                //Alarm(LineAlarmType.IoSingleTimeOut);
            }
        }

        #endregion

        #region 如果是进仓5,托盘横移后直接结束处理

        internal void EndProcessTray()
        {
            if (DeviceID.Equals(5))
            {
                if (SecondMoveInfo.MoveType.Equals(LineMoveType.Fixture) && SecondMoveInfo.MoveStep <= LineMoveStep.MIO_04_Wait)
                {
                    UpdateTrayNum();
                    LogUtil.info(Name + " EndProcessTray ,结束当前托盘[" + currTrayNum + "]处理【" + SecondMoveInfo.MoveType + "】【" + SecondMoveInfo.MoveStep + "】 ");
                    SecondMoveInfo.EndMove();
                }
            }
        }
        #endregion

    }
}