MoveEquip_Partial.cs 63.4 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 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302
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 出库 
        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;
                lineStatus = LineStatus.OutStoreExecute;
                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.MoveStep.Equals(LineMoveStep.MO_50_StartOutProcess))
            {
                if (UpdownIsUp())
                {
                    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);
                    if (ClampNeedCheck)
                    {
                        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.MoveStep.Equals(LineMoveStep.MO_51_CylinderBefore))
            {
                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.MoveStep.Equals(LineMoveStep.MO_52_CylinderDown))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MO_53_DownWait);
                OutLog("出库 " + MoveInfo.SLog + ": 等待200ms后夹紧");
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MO_53_DownWait))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MO_54_CylinderOpen);
                OutLog("出库 " + MoveInfo.SLog + ":  夹料气缸夹紧,更新料盘位置【" + MoveInfo.MoveParam.WareCode + "】【MOVING】【" + DeviceID + "】");
                CylinderMove(MoveInfo, IO_Type.ClampCylinder_Tighten, IO_Type.ClampCylinder_Slack);

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

            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MO_54_CylinderOpen))
            {
                MO_55_CylinderUp();

            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MO_55_CylinderUp))
            {
                if (UpdownIsUp())
                {
                    if (ClampNeedCheck && IOValue(IO_Type.ClampCylinder_Check).Equals(IO_VALUE.LOW))
                    {
                        //MoveInfo.NextMoveStep(LineMoveStep.MO_56_ClarmpCheck);
                        //OutLog("出库 " + MoveInfo.SLog + ":  等待夹爪有料");
                        //MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampCylinder_Check, IO_VALUE.HIGH));
                        LogUtil.info("出库 " + MoveInfo.SLog + ": 出库从仓门口抓料后, 夹爪检测信号无料, 忽略此信号");
                    }
                    //else
                    {
                        if (IsBigStore())
                        {
                            if (TrayIsOk())
                            {
                                MO_61_CylinderAfter();
                            }
                        }
                        else
                        {
                            MO_61_CylinderAfter();
                        }
                    }
                }
                else
                {
                    MO_55_CylinderUp();
                }
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MO_56_ClarmpCheck))
            {
                if (UpdownIsUp())
                {
                    if (IsBigStore())
                    {
                        if (TrayIsOk())
                        {
                            MO_61_CylinderAfter();
                        }
                    }
                    else
                    {
                        MO_61_CylinderAfter();
                    }
                }
                else
                {
                    MO_55_CylinderUp();
                }
            }
            #endregion

            #region 移载装置,放物品到流水线操作
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MO_61_CylinderAfter))
            {
                if (CylinderIsOk(IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After))
                {
                    if (TrayIsOk())
                    {
                        int trayNum = SecondMoveInfo.MoveParam.TrayNumber;
                        //去掉直接丢盘处理
                        MoveInfo.NextMoveStep(LineMoveStep.MO_62_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.MoveStep.Equals(LineMoveStep.MO_62_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);
                TrayInfo tray = TrayManager.GetTrayInfo(trayNum);
                LogInfo("出库 " + MoveInfo.SLog + ":    夹料气缸放松,更新料盘位置【" + MoveInfo.MoveParam.WareCode + "】【INLINE】更新托盘【" + trayNum + "】 " + tray.ToStr() + "");

                //出库全部完成 
                lineStatus = LineStatus.StoreOnline;
                MoveInfo.NextMoveStep(LineMoveStep.MO_63_CylinderRelax);
                CylinderMove(MoveInfo, IO_Type.ClampCylinder_Slack, IO_Type.ClampCylinder_Tighten);
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MO_63_CylinderRelax))
            {
                if (MoveInfo.MoveParam.PlateW > 7)
                {
                    this.MoveInfo.NextMoveStep(LineMoveStep.MO_64_CylinderWork);
                    OutLog("出库 " + MoveInfo.SLog + ": 夹紧气缸夹紧");
                    CylinderMove(MoveInfo, IO_Type.ClampCylinder_Tighten, IO_Type.ClampCylinder_Slack);
                }
                else
                {
                    this.MoveInfo.NextMoveStep(LineMoveStep.MO_66_CylinderUp);
                    OutLog("出库 " + MoveInfo.SLog + ": 上下气缸上升,同时顶升气缸先下降");
                    UpdownUpMove();
                    CylinderMove(null, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);

                }
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MO_64_CylinderWork))
            {
                this.MoveInfo.NextMoveStep(LineMoveStep.MO_65_CylinderRelax2);
                OutLog("出库 " + MoveInfo.SLog + ": 夹紧气缸再次放松");
                CylinderMove(MoveInfo, IO_Type.ClampCylinder_Slack, IO_Type.ClampCylinder_Tighten);
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MO_65_CylinderRelax2))
            {
                this.MoveInfo.NextMoveStep(LineMoveStep.MO_66_CylinderUp);
                OutLog("出库 " + MoveInfo.SLog + ": 上下气缸上升,同时顶升气缸先下降");
                UpdownUpMove();
                CylinderMove(null, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MO_66_CylinderUp))
            {
                //  减去需要的盘数
                //  TrayManager.DelNeedEmptyTrayNum();
                SOutLog("出库  :移栽完成,放行托盘");
                SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_14_TopDown);
                CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);

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

                RunLogUtil.MoveEndLog(new MoveEndLog(Name, "出库", MoveInfo.MoveStartTime, DateTime.Now, MoveInfo.MoveParam.PosId, MoveInfo.MoveParam.WareCode));
                MoveEndS();
            }

            #endregion
        }
        private void MO_55_CylinderUp()
        {
            MoveInfo.NextMoveStep(LineMoveStep.MO_55_CylinderUp);
            OutLog("出库 " + MoveInfo.SLog + ":  上下气缸上升");
            UpdownUpMove();
        }
        private void MO_61_CylinderAfter()
        {
            MoveInfo.NextMoveStep(LineMoveStep.MO_61_CylinderAfter);
            MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
            OutLog("出库 " + MoveInfo.SLog + ":  前后气缸后退");
            CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
        }
        private bool TrayIsOk()
        {
            if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MO_11_CodeRember) && !SecondMoveInfo.IsInWait)
            {
                return true;
            }
            else if (MoveInfo.IsTimeOut(300))
            {
                MoveTimeoutAlarm(MoveInfo, "等待空托盘到达超时");
                //WarnMsg = MoveInfo.Name + "[" + MoveInfo.MoveType + "][" + MoveInfo.SLog + "]等待空托盘到达超时[" + Math.Round(MoveInfo.StepSpan().TotalSeconds, 1) + "]秒";
                //LogUtil.error(WarnMsg, DeviceID * 1000 + 12);
                //Alarm(LineAlarmType.IoSingleTimeOut);
                return false;
            }
            return false;
        }
        private bool IsBigStore()
        {
            return Config.IsBigTray.Equals(1);
        }
        #endregion

        #region 入库 
        public override bool StartInStoreMove(InOutParam param)
        {
            string posId = param != null ? param.PosId : "";
            if (runStatus.Equals(LineRunStatus.Runing))
            {
                runStatus = LineRunStatus.Busy;
                lineStatus = LineStatus.InStoreExecute;
                MoveInfo.MoveParam = param;
                MoveInfo.NewMove(LineMoveType.InStore);

                LogInfo("入库【" + posId + "】处理(移栽):MI_01_ToLineUp, 前后气缸后退,等待夹爪无料");

                MoveInfo.NextMoveStep(LineMoveStep.MI_01_ToLineUp);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
                if (ClampNeedCheck)
                {
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampCylinder_Check, IO_VALUE.LOW));
                }
                return true;
            }
            else
            {
                LogUtil.error(Name + " 启动一个 入库【" + posId + "】运动失败,当前状态,storeStatus=" + runStatus);
            }
            return false;
        }
        private void MI_18_UpdownUp()
        {
            MoveInfo.NextMoveStep(LineMoveStep.MI_18_UpdownUp);
            MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(300));
            //CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
            UpdownUpMove();
            SecondMoveInfo.NextMoveStep(LineMoveStep.MO_14_TopDown);
            CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
        }
        protected override void InStoreProcess()
        {
            if (MoveInfo.IsInWait)
            {
                CheckWait(MoveInfo);
            }
            if (SecondMoveInfo.IsInWait)
            {
                CheckWait(SecondMoveInfo);
            }
            string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosId : "";
            if (MoveInfo.IsInWait)
            {
                if (!UseAxis)
                {
                    if (MoveInfo.MoveStep.Equals(LineMoveStep.MI_03_CylinderDown) && MoveInfo.IsTimeOut(20))
                    {
                        //顶升气缸上升到位,升降气缸下降不到位
                        if (CylinderIsOk(IO_Type.TopCylinder_Down, IO_Type.TopCylinder_UP) &&
                            IOValue(IO_Type.UpDownCylinder_Up).Equals(IO_VALUE.LOW) &&
                            IOValue(IO_Type.UpDownCylinder_Down).Equals(IO_VALUE.LOW))
                        {
                            LogUtil.error(Name + "入库 [" + posId + "],升降气缸下降到托盘[" + currTrayNum + "]取料失败,升降轴上升,禁用托盘,同时放行托盘");
                            LogInfo("入库 [" + posId + "]" + MoveInfo.SLog + ":  升降轴上升,禁用托盘,同时放行托盘,顶升气缸1下降");
                            TrayDisableManager.AddDisable(currTrayNum, Name, "入库取料失败",0, DeviceID);
                            MI_18_UpdownUp();
                        }
                    }
                }
                return;
            }
            if (MoveInfo.MoveStep.Equals(LineMoveStep.MI_01_ToLineUp))
            {
                if (MoveInfo.MoveParam?.PlateH >= 30)
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MI_02_TopUP);
                    InLog("入库 " + MoveInfo.SLog + ":  顶升上升");
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
                    CylinderMove(MoveInfo, IO_Type.TopCylinder_Down, IO_Type.TopCylinder_UP);
                }
                else
                {
                    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.MoveStep.Equals(LineMoveStep.MI_02_TopUP))
            { 
                TrayInfo tray = TrayManager.GetTrayInfo(currTrayNum);
                bool needCheck = (tray == null || (!tray.InoutPar.Corrected));
                if (!needCheck)
                {
                    LogInfo("入库 [" + posId + "]" + MoveInfo.SLog + ":   托盘【 " + currTrayNum + "】托盘已纠正,不再验证料盘检测信号");
                }
                //判断料盘检测信号是否正确
                if (needCheck&&
                    CylinderIsOk(IO_Type.TopCylinder_Down, IO_Type.TopCylinder_UP) &&
                          LineManager.useTrayCheck.Contains(DeviceID) &&
                          IOValue(IO_Type.TrayCheck).Equals(IO_VALUE.LOW))
                { 
                        ConfigIO io = Config.getWaitIO(IO_Type.TrayCheck);
                        if (io != null)
                        {
                            LogInfo("当前托盘上的料盘检测信号[" + io.ConfigStr + "]的值:" + IOValue(IO_Type.TrayCheck));
                        }
                        LogUtil.error(Name + "入库 [" + posId + "],托盘【 " + currTrayNum + "】,有料托盘料盘检测信号不亮,升降轴上升,禁用托盘,同时放行托盘");
                        LogInfo("入库 [" + posId + "]" + MoveInfo.SLog + ":  升降轴上升,禁用托盘,同时放行托盘,顶升气缸1下降");
                        TrayDisableManager.AddDisable(currTrayNum, Name, "有料托盘料盘检测信号不亮", 1, DeviceID);
                        MI_18_UpdownUp();
                }
                else
                {
                    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.MoveStep.Equals(LineMoveStep.MI_03_CylinderDown))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_04_DownWait);
                InLog("入库 " + MoveInfo.SLog + ":  等待200ms后夹紧");
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
            }
            //只有当BOX可以进行出入库时,移栽物品,防止卡住
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MI_04_DownWait))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_05_CylinderOpen);
                InLog("入库 " + MoveInfo.SLog + ":  夹料气缸夹紧");
                CylinderMove(MoveInfo, IO_Type.ClampCylinder_Tighten, IO_Type.ClampCylinder_Slack);
            }
            else if (MoveInfo.MoveStep.Equals(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.MoveStep.Equals(LineMoveStep.MI_06_CylinderUp))
            {
                if (ClampNeedCheck && IOValue(IO_Type.ClampCylinder_Check).Equals(IO_VALUE.LOW))
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MI_07_ClampCheck);
                    InLog("入库 " + MoveInfo.SLog + ":  等待夹爪有料");
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampCylinder_Check, IO_VALUE.HIGH));
                }
                else
                {
                    MI_08_WaitBox();
                }
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MI_07_ClampCheck))
            {
                MI_08_WaitBox();
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MI_08_WaitBox))
            {
                if (UpdownIsUp())
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MI_09_CylinderBefore);
                    InLog("入库: " + MoveInfo.SLog + " 前后气缸1前进");
                    CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_After, IO_Type.BeforeAfterCylinder_Before);
                }
                else
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MI_08_WaitBox);
                    InLog("入库: " + MoveInfo.SLog + " 升降气缸上升");
                    UpdownUpMove();
                }
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MI_09_CylinderBefore))
            {
                if (CylinderIsOk(IO_Type.BeforeAfterCylinder_After, IO_Type.BeforeAfterCylinder_Before))
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MI_11_CylinderDown);
                    InLog("入库 " + MoveInfo.SLog + " ,上下气缸下降");
                    UpdownDownP3Move(MoveInfo.MoveParam.PlateH, MoveInfo.MoveParam.PlateW);
                    if (IsBigStore())
                    {
                        InLog("放托盘(放开阻挡): " + MoveInfo.SLog + " 物品已移走,顶升气缸1下降");
                        SecondMoveInfo.NextMoveStep(LineMoveStep.MO_14_TopDown);
                        CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
                    }
                }
                else
                {
                    MoveInfo.NextMoveStep(LineMoveStep.MI_09_CylinderBefore);
                    InLog("入库: " + MoveInfo.SLog + " 前后气缸1前进");
                    CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_After, IO_Type.BeforeAfterCylinder_Before);
                }
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MI_11_CylinderDown))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_12_CylinderRelax);
                InLog("入库 " + MoveInfo.SLog + ",夹料气缸放松");
                CylinderMove(MoveInfo, IO_Type.ClampCylinder_Slack, IO_Type.ClampCylinder_Tighten);
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MI_12_CylinderRelax))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_13_UpdownCylinderUp);
                InLog("入库 " + MoveInfo.SLog + ",上下气缸上升");
                UpdownUpMove();
            }
            else if (MoveInfo.MoveStep.Equals(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.MoveStep.Equals(LineMoveStep.MI_14_CylinderAfter))
            {
                MoveInfo.NextMoveStep(LineMoveStep.MI_15_SendPosToStore);
                InLog("入库 " + MoveInfo.SLog + ",通知BOX开始入库,等待3000");
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000));
                LineServer.StartInStore(StoreID, MoveInfo.MoveParam);
                sendCount = 1;
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MI_15_SendPosToStore))
            {
                if (!LineServer.IsInStorePro(StoreID, MoveInfo.MoveParam.PosId))
                {
                    //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(StoreID, MoveInfo.MoveParam);
                    sendCount++;

                    if (sendCount >= 3)
                    {
                        SetWarnMsg(MoveInfo.Name + "[" + MoveInfo.MoveStep + "] " + " 等待BOX开始入库超时  已发送" + sendCount + "次", "等待BOX开始入库超时");
                        //LogUtil.error(WarnMsg);
                        Alarm(LineAlarmType.IoSingleTimeOut);
                    }
                }
                else
                {
                    RunLogUtil.MoveEndLog(new MoveEndLog(Name, "入库", MoveInfo.MoveStartTime, DateTime.Now, MoveInfo.MoveParam.PosId, MoveInfo.MoveParam.WareCode));
                    sendCount = 0;
                    LogInfo("入库【" + posId + "】处理(移栽)全部完成!");
                    MoveEndS();
                }
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MI_16_SendEnd))
            {
                RunLogUtil.MoveEndLog(new MoveEndLog(Name, "入库", MoveInfo.MoveStartTime, DateTime.Now, MoveInfo.MoveParam.PosId, MoveInfo.MoveParam.WareCode));
                LogInfo("入库【" + posId + "】处理(移栽)全部完成!");
                MoveEndS();
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.MI_18_UpdownUp))
            {
                LogInfo("入库【" + posId + "】失败,自动复位完成");
                MoveEndS();
            }
        }

        private int sendCount = 0;
        private void MI_08_WaitBox()
        {
            string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosId : "";
            int num = MoveInfo.MoveParam.TrayNumber;
            MoveInfo.NextMoveStep(LineMoveStep.MI_08_WaitBox);
            LogInfo("入库【" + posId + "】 " + MoveInfo.SLog + ":  等待box可入库,更新托盘【" + num + "】为空盘,清理入库任务 ");
            MoveInfo.WaitList.Add(WaitResultInfo.WaitBoxCanReviceTray());
            TrayManager.UpdateTrayInfo(num);
            RemoveInStore(MoveInfo.MoveParam);
            if (IsBigStore()) { }
            else
            {
                InLog("放托盘(放开阻挡): " + MoveInfo.SLog + " 物品已移走,顶升气缸1下降");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_14_TopDown);
                CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
            }
        }
        private bool IsInStoreNeed()
        {
            if (TrayDisableManager.DisableTray(currTrayNum))
            {
                return false;
            }

            if (waitInStoreList.Count > 0)
            {
                lock (waitInListLock)
                {
                    bool needRemove = false;
                    int index = 0;
                    //判断是否是自己排队列表中的入库信息 
                    foreach (InOutParam cc in waitInStoreList)
                    {
                        if (cc.TrayNumber.Equals(currTrayNum) && (!cc.WareCode.Equals("")))
                        {

                            //TODO 需要判断托盘的料盘信息与入库的是否一致
                            TrayInfo trayInfo = TrayManager.GetTrayInfo(currTrayNum);
                            if (trayInfo.IsFull && trayInfo.InOrOutStore.Equals(1) && trayInfo.InoutPar.PosId.Equals(cc.PosId)){

                            }
                            else
                            {
                                LogUtil.error(Name + "托盘号【" + currTrayNum + "】的入库任务【" + cc.ToStr() + "】与托盘实际信息不一致:【" + trayInfo.ToStr() + "】不拦截托盘入库");
                                return false;
                            }

                            //if (LineManager.useTrayCheck.Contains(DeviceID) && IOValue(IO_Type.TrayCheck).Equals(IO_VALUE.LOW))
                            //{
                            //    LogInfo(" 入库需拦截有料托盘【 " + currTrayNum + "】,有料托盘料盘检测信号不亮,禁用托盘");
                            //    TrayDisableManager.AddDisable(currTrayNum, Name, "有料托盘料盘检测信号不亮");
                            //    return false;
                            //}
                            //判断是否验证成功,如果验证失败,不入库
                            if (LineServer.RightInPosId(StoreID, cc.PosId))
                            {
                                SecondMoveInfo.MoveParam = new InOutParam(cc.TrayNumber, cc.WareCode, cc.PosId, cc.PlateH, cc.PlateW, cc.InStoreNg);
                                return true;
                            }
                            else
                            {
                                SecondMoveInfo.MoveParam = new InOutParam(cc.TrayNumber, cc.WareCode, cc.PosId, cc.PlateH, cc.PlateW, cc.InStoreNg);
                                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;
        }

        private bool CheckIsNeedOutStore()
        {
            if (currTrayNum <= 0)
            {
                return false;
            }
            if (TrayDisableManager.DisableTray(currTrayNum))
            {
                return false;
            }
            bool isFull = TrayManager.TrayIsFull(currTrayNum);

            bool moveOk = (IsBigStore() && MoveInfo.MoveStep >= LineMoveStep.MO_55_CylinderUp) || MoveInfo.MoveStep >= LineMoveStep.MO_61_CylinderAfter;
            if (MoveInfo.MoveType.Equals(LineMoveType.OutStore) && moveOk
                 && (!MoveInfo.MoveStep.Equals(LineMoveStep.MO_66_CylinderUp)))
            {
                if (isFull.Equals(false))
                {
                    TrayInfo tray = TrayManager.GetTrayInfo(currTrayNum); 
                    bool needCheck = (tray == null || (!tray.InoutPar.Corrected));
                    if (!needCheck)
                    {
                        LogInfo("出库中,拦截空托盘【 " + currTrayNum + "】托盘已纠正,不再验证料盘检测信号");
                    }
                    //顶升上升时才判断
                    if (needCheck&& CylinderIsOk(IO_Type.TopCylinder_Down, IO_Type.TopCylinder_UP) &&
                        LineManager.useTrayCheck.Contains(DeviceID) &&
                        IOValue(IO_Type.TrayCheck).Equals(IO_VALUE.HIGH))
                    {
                        ConfigIO io = Config.getWaitIO(IO_Type.TrayCheck);
                        if (io != null)
                        {
                            LogInfo("当前托盘上的料盘检测信号[" + io.ConfigStr + "]的值:" + IOValue(IO_Type.TrayCheck));
                        }
                        LogInfo(" 出库中,需拦截空托盘【 " + currTrayNum + "】,空托盘料盘检测信号亮,禁用托盘");
                        TrayDisableManager.AddDisable(currTrayNum, Name, "空托盘料盘检测信号亮", 2, DeviceID);
                    }
                    else
                    {
                        LogInfo(" 出库中,拦截空托盘【 " + currTrayNum + "】~");
                        return true;
                    }
                }
            }
            return false;
        }

        internal bool IsWaitEmptyTray()
        {
            if (isInSuddenDown || isNoAirCheck)
            {
                return false;
            }
            bool moveOk = (IsBigStore() && MoveInfo.MoveStep >= LineMoveStep.MO_55_CylinderUp) || MoveInfo.MoveStep >= LineMoveStep.MO_61_CylinderAfter;
            if (MoveInfo.MoveType.Equals(LineMoveType.OutStore) && moveOk
                 && (!MoveInfo.MoveStep.Equals(LineMoveStep.MO_66_CylinderUp)))
            {
                return true;
            }
            return false;
        }

        private bool CheckIsNeedInStore()
        {
            if (currTrayNum <= 0)
            {
                return false;
            }
            if (TrayDisableManager.DisableTray(currTrayNum))
            {
                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;
            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("")))
                        //if (cc.TrayNumber.Equals(currTrayNum) && (!cc.WareCode.Equals("")) && LineServer.RightInPosId(DeviceID, cc.PosId))
                        {
                            reIndex = i;
                            currCode = cc;
                            SecondMoveInfo.MoveParam = new InOutParam(cc.TrayNumber, cc.WareCode, cc.PosId, cc.PlateH, cc.PlateW, cc.InStoreNg);
                            break;
                        }
                    }
                    if (reIndex >= 0)
                    {
                        TrayInfo tray = TrayManager.GetTrayInfo(currTrayNum);
                        bool needCheck = (tray == null || (!tray.InoutPar.Corrected));
                        if (!needCheck)
                        {
                            LogInfo("入库需拦截有料托盘【 " + currTrayNum + "】托盘已纠正,不再验证料盘检测信号");
                        }
                        if (needCheck&& CylinderIsOk(IO_Type.TopCylinder_Down, IO_Type.TopCylinder_UP) &&
                            LineManager.useTrayCheck.Contains(DeviceID) &&
                            IOValue(IO_Type.TrayCheck).Equals(IO_VALUE.LOW))
                        {
                            ConfigIO io = Config.getWaitIO(IO_Type.TrayCheck);
                            if (io != null)
                            {
                                LogInfo("当前托盘上的料盘检测信号[" + io.ConfigStr + "]的值:" + IOValue(IO_Type.TrayCheck));
                            }
                            LogInfo(" 入库需拦截有料托盘【 " + currTrayNum + "】,有料托盘料盘检测信号不亮,禁用托盘");
                            TrayDisableManager.AddDisable(currTrayNum, Name, "有料托盘料盘检测信号不亮", 1,DeviceID);
                            return false;
                        }
                        else if (!LineServer.BoxCanInStore(StoreID))
                        {
                            LogInfo("*******托盘" + currTrayNum + "需要入库【" + currCode.ToStr() + "】,BoxCanInStore验证失败,先放托盘通过");
                            return false;
                        }
                        else
                        {
                            //判断是否验证成功,如果验证失败,不入库
                            if (LineServer.RightInPosId(StoreID, currCode.PosId))
                            {
                                //waitInStoreList.RemoveAt(reIndex);
                                LogInfo("*******托盘" + currTrayNum + "需要入库【" + currCode.ToStr() + "】 ,开始入库移栽,清理托盘时再删除入库任务");
                                return true;
                            }
                            else
                            {
                                //LogUtil.error(Name + "托盘号【" + currTrayNum + "】入库信息【" + currCode.ToStr() + "】料仓未验证成功,不拦截托盘,更新此托盘为NG,从waitInStoreList中删除,取消入库任务");
                                //TrayManager.UpdateInStoreNG(currTrayNum, true, "Box验证入库失败");
                                //waitInStoreList.RemoveAt(reIndex);
                                //SServerManager.cancelPutInTask(Name, currCode.WareCode, true);
                                //return false;

                                LogUtil.error(Name + "托盘号【" + currTrayNum + "】入库信息【" + currCode.ToStr() + "】料仓未验证成功,重新发送验证消息, 先放托盘通过");
                                LineServer.CheckInStorePos(DeviceID, currCode);
                                return false;
                            }

                        }
                    }
                }
            }

            return false;
        }
        public bool RemoveInStore(InOutParam param, string logName = "料盘已移走", bool IsCancel = false)
        {
            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() + "】");
                        if (IsCancel)
                        {
                            SServerManager.cancelPutInTask(Name, param.WareCode, false);
                        }
                        return true;
                    }
                }
            }

            return false;
        }
        #endregion

        #region 托盘检测
        private Stopwatch trayCheckWait = new Stopwatch();
        private Stopwatch trayCheck2LowWait = new Stopwatch();
        private object lockObj = "";
        private void StartCheckFixture()
        {
            if (Monitor.TryEnter(lockObj, TrayManager.mTimeOut))
            {
                try
                {
                    if (SecondMoveInfo.MoveType.Equals(LineMoveType.None).Equals(false))
                    {
                        if (IOValue(IO_Type.StopCylinder_Check2).Equals(IO_VALUE.HIGH))
                        {
                            trayCheck2LowWait.Stop();
                        }
                        else
                        {
                            TrayManager.checkWatch(trayCheck2LowWait, 30000, false);
                        }
                        LogUtil.error(Name + "  StartCheckFixture " + " 不在空闲中,直接返回 ");
                        return;
                    }
                    if (SecondMoveInfo.MoveType.Equals(LineMoveType.None))
                    {
                        bool canpro = LineManager.Line.Move5CanProcessTray(DeviceID);
                        if (IOValue(IO_Type.StopCylinder_Check2).Equals(IO_VALUE.HIGH))
                        {
                            trayCheck2LowWait.Stop();
                            if (canpro && TrayManager.checkWatch(trayCheckWait, TrayManager.SwTrayWaitTime, true))
                            {
                                SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
                                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_03_Stop2Down);
                                CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "  阻挡气缸1-1上升)");
                                if (TrayManager.HasCheck1(DeviceID))
                                {
                                    IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
                                    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.LOW));
                                }
                            }
                        }
                        else
                        {

                            bool check2IsOk = TrayManager.checkWatch(trayCheck2LowWait, TrayManager.SwTrayWaitTime, false);
                            if (IOValue(IO_Type.StopCylinder_Check1).Equals(IO_VALUE.HIGH) && TrayManager.HasCheck1(DeviceID))
                            {
                                if (TrayManager.checkWatch(trayCheckWait, TrayManager.SwTrayWaitTime, false) && check2IsOk && canpro)
                                {
                                    trayCheckWait.Stop();
                                    trayCheck2LowWait.Stop();
                                    //托盘在第一个阻挡处
                                    SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
                                    SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_00_Stop1Down);
                                    ClearTrayRFID();
                                    //ClearAllBuff();
                                    //StartReadRfid();
                                    CheckLog(" 托盘检测:料盘检测StopCylinder_Check1 " + SecondMoveInfo.SLog + "阻挡气缸1-1下降 , 等待  StopCylinder_Check1=0,清理托盘RFID,开始记录rfid缓存");
                                    IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);//TrayManager.StopDTime
                                    SecondMoveInfo.OneWaitCanEndStep = true;
                                    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check1, IO_VALUE.LOW));
                                    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check2, IO_VALUE.HIGH));
                                    //SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(30000));
                                }
                            }
                            else
                            {
                                trayCheckWait.Stop();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.error(Name + "  StartCheckFixture " + " 出错:" + ex.ToString());
                }
                finally
                {
                    Monitor.Exit(lockObj);
                }
            }
            else
            {
                LogUtil.error(Name + "  StartCheckFixture " + "失败,未得到锁");
            }
        }
        protected override void CheckFixtureProcess()
        {
            if (!LineManager.Line.LineCanRun())
            {
                return;
            }
            if (SecondMoveInfo.IsInWait)
            {
                CheckWait(SecondMoveInfo);
            }
            if (SecondMoveInfo.IsInWait)
            {
                return;
            }

            #region 托盘检测
            if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_00_Stop1Down))
            {
                if (IOValue(IO_Type.StopCylinder_Check2).Equals(IO_VALUE.HIGH))
                {
                    MIO_02_FixtureCheck();
                }
                else
                {
                    SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_01_StopDownWait);
                    CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "   再次等待前阻挡检测消失");
                    //CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "   100ms后StopCylinder_Check1上升");
                    // IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
                    IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
                    // SecondMoveInfo.OneWaitCanEndStep = true;
                    // SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check1, IO_VALUE.LOW));
                    // SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check2, IO_VALUE.HIGH));
                    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(100));
                }
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_01_StopDownWait))
            {
                MIO_02_FixtureCheck();
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_02_FixtureCheck))
            {
                //if (IOValue(IO_Type.StopCylinder_Check2).Equals(IO_VALUE.HIGH))
                //{
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_03_Stop2Down);
                CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "  再次等待托盘信号");
                IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check2, IO_VALUE.HIGH));
                //}
                //else
                //{
                //    //未检测到信号或阻挡下降失败,结束处理
                //    LogInfo(SecondMoveInfo.SLog + "未等到信号   StopCylinder_Check2=HIGH,结束处理 ");
                //    SecondMoveInfo.EndMove(); 
                //}
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_03_Stop2Down))
            {
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_04_Wait);
                CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "  ,等待编码信号稳定StopCylinder_Check2=1");
                CheckAndMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
                //SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500)); 
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check2, IO_VALUE.HIGH));
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_04_Wait))
            {
                try
                {
                    //try
                    //{
                    //    //StopReadRfid();
                    //    LogUtil.debug($"【{Name}】停止记录rfid缓存");
                    //}
                    //catch (Exception ex1)
                    //{
                    //    LogUtil.error($"【{Name}】停止记录rfid缓存:", ex1);
                    //}
                    //判断是否需要顶升
                    bool isNeed = false;
                    //UpdateTrayNumFromBuff();
                    UpdateTrayNum();
                    bool isFull = TrayManager.TrayIsFull(currTrayNum);
                    if (TrayManager.RightTrayCode(currTrayNum, preTrayNum, false))
                    {
                        TrayInfo tray = TrayManager.GetTrayInfo(currTrayNum);
                        if (tray.InoutPar?.ManualJudgeNG ?? false)
                        {
                            LogInfo(SecondMoveInfo.MoveNum + "*************** 托盘【" + currTrayNum + "】被为标记判定NG,放盘通过");
                        }
                        //出库中,需要拦盘
                        else if (CheckIsNeedOutStore())
                        {
                            isNeed = true;
                        }
                        else if (isFull && IsInStoreNeed())
                        {
                            isNeed = true;
                        }
                    }
                    else
                    {
                        string msg = Name + " 托盘顺序错乱,上个托盘号【" + preTrayNum + "】当前托盘号 【" + currTrayNum + "】最大盘号【" + TrayManager.MaxTrayNum + "】";
                        TrayManager.UpdateTrayNumError(DeviceID, msg);
                        LogUtil.error(msg);
                        return;
                    }
                    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.MoveStep.Equals(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,暂不顶升上升");
                    //}
                    CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "  顶升气缸上 升 )");
                    CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_Down, IO_Type.TopCylinder_UP);
                }
                else
                {
                    if (!LineServer.RightInPosId(StoreID, 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
                //{
                //    CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "  顶升气缸上 升 )");
                //    CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_Down, IO_Type.TopCylinder_UP);
                //}
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_06_TopUp))
            {
                CheckLog("托盘阻挡*************** 托盘号【" + currTrayNum + "】");
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(10000));
                //托盘号正确
                //preTrayNum = num;
                bool isNeedMove = false;
                TrayInfo tray = TrayManager.GetTrayInfo(currTrayNum);
                if(tray.InoutPar?.ManualJudgeNG??false)
                {
                    LogInfo(SecondMoveInfo.MoveNum + "*************** 托盘【" + currTrayNum + "】被为标记判定NG,放盘通过");
                }
                //判断盘是空盘,空盘并且编号正确才需要放料盘过去
                else if (CheckIsNeedOutStore())
                {
                    SecondMoveInfo.MoveParam = new InOutParam(currTrayNum);
                    isNeedMove = true;

                    //如果是>=30的盘,需要先下降顶升
                    if (MoveInfo.MoveParam != null && MoveInfo.MoveParam.PlateH >= 30)
                    {
                        LogInfo(SecondMoveInfo.MoveNum + "*************** 空托盘【" + currTrayNum + "】,正在出库>=30的盘中,顶升先下降");
                        SecondMoveInfo.NextMoveStep(LineMoveStep.MO_10_TopDown);
                        CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
                    }
                    else
                    {
                        LogInfo(SecondMoveInfo.MoveNum + "*************** 空托盘【" + currTrayNum + "】,正在出库中,移栽料盘");
                        SecondMoveInfo.NextMoveStep(LineMoveStep.MO_11_CodeRember);
                        SecondMoveInfo.EndStepWait();
                    }
                }
                else if (CheckIsNeedInStore())
                {
                    SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_08_WaitInStore);
                    //if (LineManager.useTrayCheck.Contains(DeviceID))
                    //{
                    //    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck, IO_VALUE.HIGH));
                    //    LogInfo(SecondMoveInfo.MoveNum + "*************** 托盘【" + currTrayNum + "】,有对应的入库任务,等待料盘检测信号,等待移栽");
                    //}
                    //else
                    //{
                        LogInfo(SecondMoveInfo.MoveNum + "*************** 托盘【" + currTrayNum + "】,有对应的入库任务,等待移栽");
                    //}
                    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.MoveStep.Equals(LineMoveStep.MO_10_TopDown))
            {
                LogInfo(SecondMoveInfo.MoveNum + "*************** 空托盘【" + currTrayNum + "】,顶升已下下降,正在出库中,移栽料盘");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_11_CodeRember);
                SecondMoveInfo.EndStepWait();
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_08_WaitInStore))
            {
                if (MoveInfo.MoveType.Equals(LineMoveType.None))
                {
                    StartInStoreMove(SecondMoveInfo.MoveParam);
                    CheckLog("托盘放行" + SecondMoveInfo.SLog + " ,等待移栽完成后放开阻挡)");
                    SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_09_WaitLetFixtureGo);
                }
                else if (SecondMoveInfo.IsTimeOut(30))
                {
                    string msg = SecondMoveInfo.Name + "[" + SecondMoveInfo.MoveStep + "] 等待开始入库超时 [" + Math.Round(MoveInfo.StepSpan().TotalSeconds, 1) + "]秒";
                    LogUtil.error(msg + ",暂时放托盘离开");
                    SecondMoveInfo.NextMoveStep(LineMoveStep.MO_14_TopDown);
                    InLog("放托盘(放开阻挡): " + MoveInfo.SLog + " 入库超时,放托盘离开,顶升气缸1下降");
                    CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
                }
            }
            #endregion

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

            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MO_15_WaitCanGo))
            {
                MO_16_Stop2Down();
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MO_16_Stop2Down))
            {
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_17_Stop2Check);
                CheckLog("托盘放行" + SecondMoveInfo.SLog + " , 等待StopCylinder_Check2=0");
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check2, IO_VALUE.LOW));
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MO_17_Stop2Check))
            {
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_18_WaitTime);
                CheckLog("托盘放行  " + SecondMoveInfo.SLog + " , 等待2000ms后阻挡2上升");
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MO_18_WaitTime))
            {
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_19_StopCylinder_Back);
                CheckLog("托盘放行" + SecondMoveInfo.SLog + " , 阻挡气缸1-2上升 )");
                IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(100));
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down2, IO_VALUE.LOW));
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MO_19_StopCylinder_Back))
            {
                CheckLog("托盘放行  SecondMove:(托盘放行结束) ");
                // IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
                SecondMoveInfo.EndMove();
            }
            #endregion
        }
        private void MIO_02_FixtureCheck()
        {
            //if (IOValue(IO_Type.StopCylinder_Check1).Equals(IO_VALUE.LOW) || IOValue(IO_Type.StopCylinder_Check2).Equals(IO_VALUE.HIGH))
            //{
            SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_02_FixtureCheck);
            CheckLog("托盘阻挡" + SecondMoveInfo.SLog + "   阻挡气缸1-1上升,等待 阻挡2托盘检测=1)");

            if (DeviceID.Equals(5))
            {
                SecondMoveInfo.TimeOutSeconds = 20;
            }
            //SecondMoveInfo.OneWaitCanEndStep = true;
            IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
            IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
            SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check2, IO_VALUE.HIGH));
            //最多等待30秒
            //SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(30000));
            //}
            //else
            //{
            //    //未检测到信号或阻挡下降失败,结束处理
            //    LogInfo(SecondMoveInfo.SLog + "未等到信号 StopCylinder_Check1=LOW,或 StopCylinder_Check2=HIGH,结束处理 ");
            //    SecondMoveInfo.EndMove();
            //}
        }
        private void MO_16_Stop2Down()
        {
            if (LineManager.Line.Move9CanStop2Down(DeviceID, currTrayNum))
            {
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_16_Stop2Down);
                CheckLog("托盘放行" + SecondMoveInfo.SLog + " ,阻挡气缸1-2下降 ");
                IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH));

            }
            else if (SecondMoveInfo.IsTimeOut(120))
            {
                MoveTimeoutAlarm(SecondMoveInfo, $"等待分流横移1空闲【{LineManager.Line.ShuntWaitTrayNum}】");
                //WarnMsg = SecondMoveInfo.Name + "[" + SecondMoveInfo.MoveType + "][" + SecondMoveInfo.SLog + "]等待分流横移1空闲[" + Math.Round(SecondMoveInfo.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.CheckFixture) && SecondMoveInfo.MoveStep < LineMoveStep.MIO_03_Stop2Down)
                {
                    UpdateTrayNum();
                    LogUtil.info(Name + " EndProcessTray ,结束当前托盘[" + currTrayNum + "]处理【" + SecondMoveInfo.MoveType + "】【" + SecondMoveInfo.MoveStep + "】 ");
                    SecondMoveInfo.EndMove();
                }
            }
        }

        //判断移栽是否正在处理托盘
        internal bool HasTray()
        {
            if (CylinderIsOk(IO_Type.TopCylinder_Down, IO_Type.TopCylinder_UP))
            {
                return true;
            }
            if (SecondMoveInfo.MoveType.Equals(LineMoveType.CheckFixture))
            {
                return true;
            }
            if (IOValue(IO_Type.StopCylinder_Check2).Equals(IO_VALUE.HIGH) )
            {
                return true;
            }
            return false;
        }
        #endregion

    }
}