AC_SA_BoxBean_Partial.cs 57.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 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
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace OnlineStore.DeviceLibrary
{
    partial class AC_SA_BoxBean
    {

        #region 自动出入库参数
        /// <summary>
        /// 料仓内所有的位置列表
        /// </summary>
        public List<string> PositionNumList = new List<string>();
        /// <summary>
        /// 入库完成后自动出库,出库完成后自动入库
        /// </summary>
        public bool autoNext = false;
        /// <summary>
        /// 自动出入库间隔
        /// </summary>
        public int autoJiange = 3;
        public int autoPositionIndex = 0;
        public string autoMsg = "";
        public int AutoStartIndex = -1;
        public bool IsInOutStoreAuto = false; //是否开启自动出入库
        public bool Double_Alternate = false;
        public bool hasDoublePlate = false;
        #endregion

        #region 出入库参数
        /// <summary>
        /// 当前出入库的次数,超过配置的数量时,需要自动重置一下,再进行出入库
        /// </summary>
        private int CurrInOutCount = 0;
        private int CurrInOutACount = 0;

        private bool LoadParamPosition(InOutStoreParam param)
        {
            if (param == null)
            {
                return false;
            }
            //加载位置
            if (param.MoveP == null)
            {
                LineMoveP p = new LineMoveP();
                ACStorePosition position = param.GetACPosition();
                if (position == null)
                {
                    LogUtil.error(LOGGER, StoreName + "出入库时发现param中取到的Position=null,没有库位不能执行出入库");
                    return false;
                }

                p.ComPress_P1 = Config.CompressAxis_P1_Position;
                p.InOut_P1 = Config.InOutAxis_P1_Position;
                p.Middle_P1 = Config.MiddleAxis_P1_Position;

                p.InOut_P2 = position.InOutAxis_DoorPosition_P2;
                //p.UpDown_P1 = position.UpDownAxis_DoorOPosition_P1;
                //p.UpDown_P8 = position.UpDownAxis_DoorIBPosition_P8;
                //p.UpDown_P2 = position.UpDownAxis_DoorIPosition_P2;
                //p.UpDown_P7 = position.UpDownAxis_DoorOBPosition_P7;

                //p.InOut_P2 = Config.InOutAxis_DoorPosition_P2;
                p.UpDown_P1 = Config.UpDownAxis_DoorOPosition_P1;
                p.UpDown_P8 = Config.UpDownAxis_DoorIBPosition_P8;
                p.UpDown_P2 = Config.UpDownAxis_DoorIPosition_P2;
                p.UpDown_P7 = Config.UpDownAxis_DoorOBPosition_P7;

                p.ComPress_P2 = position.CompressAxis_Position_P2;
                if (int.TryParse(param.PlateH, out int plateh))
                {
                    var h = Config.GetComP2(plateh);
                    if (h>0)
                        p.ComPress_P2 = h;
                }
                p.ComPress_P3 = position.CompressAxis_CPosition_P3;
                p.InOut_P3 = position.InOutAxis_Position_P3;
                p.Middle_P2 = position.MiddleAxis_Position_P2;
                p.UpDown_P3 = position.UpDownAxis_IHPosition_P3;
                p.UpDown_P4 = position.UpDownAxis_ILPosition_P4;
                p.UpDown_P5 = position.UpDownAxis_OHPosition_P5;
                p.UpDown_P6 = position.UpDownAxis_OLPosition_P6;
                param.MoveP = p;
                return true;
            }
            return true;
        }

        #endregion

        #region 出入库结果验证
        private void InOutBackToP1(int InOut_P1)
        {
            ACAxisMove(Config.InOut_Axis, InOut_P1, Config.InOutAxis_P1_Speed);
            /*
            //判断是否在P1,如果是,不需要运行 
            int outCount = ACServerManager.GetActualtPosition(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue());
            int errorCount = Math.Abs(outCount - InOut_P1);
            //需要判断原点信号
            int org = ACServerManager.GetHomeSingle(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue());
            if (errorCount <= Config.InOut_Axis.CanErrorCountMin && org.Equals(1))
            {
                LogUtil.info("进出轴当前位置:" + outCount + ",已经在P1,不需要再回P1");
            }
            else
            {
                ACAxisMove(Config.InOut_Axis, InOut_P1, Config.InOutAxis_P1_Speed);
                StoreMove.WaitList.Add(WaitResultInfo.WaitAxisOrg(Config.InOut_Axis, IO_VALUE.HIGH));
            }
            //StoreMove.WaitList.Add(WaitResultInfo.WaitAxisOrg(Config.InOut_Axis,IO_VALUE.HIGH));
            */
        }

        private void CheckWait()
        {
            List<WaitResultInfo> list = StoreMove.WaitList;
            //当等待超过一分钟时,需要打印提示 
            TimeSpan span = DateTime.Now - StoreMove.LastSetpTime;
            string NotOkMsg = "";
            if (list.Count <= 0)
            {
                StoreMove.EndStepWait();
                return;
            }
            bool isOk = true;
            if (StoreMove.OneWaitCanEndStep)
            {
                isOk = false;
            }
            foreach (WaitResultInfo wait in list)
            {
                if (wait.IsEnd)
                {
                    continue;
                }
                NotOkMsg = wait.ToStr();
                if (wait.WaitType == 1)
                {
                    string msg = "";
                    if (wait.IsHomeMove)
                    {
                        wait.IsEnd = ACHomeMoveIsEnd(wait.AxisInfo, out msg);
                    }
                    else
                    {
                        wait.IsEnd = ACAxisMoveIsEnd(wait.AxisInfo, wait.TargetPosition, wait.TargetSpeed, out msg);
                    }
                    if (!msg.Equals(""))
                    {
                        isOk = false;
                        //    WarnMsg = msg;
                        Alarm(StoreAlarmType.AxisMoveError, GetAlarmCodeByAxis(wait.AxisInfo).ToString(), StoreMove.MoveType);
                        break;
                    }
                }
                else if (wait.WaitType == 2)
                {
                    wait.IsEnd = IOManager.IOValue(wait.IoType).Equals(wait.IoValue);
                    int timeOutMs = Config.IOSingle_TimerOut;
                    if (StoreMove.MoveStep == StoreMoveStep.SO_15_WaitTake)
                    {
                        timeOutMs = 650000;
                    }
                    
                    if ((!wait.IsEnd) && span.TotalMilliseconds > timeOutMs)
                    {
                        ConfigIO io = Config.getWaitIO(wait.IoType);
                        //WarnMsg = StoreName + " 等待信号" + io.DisplayStr + "=" + wait.IoValue + "超时!";
                        SetWarnMsg(ResourceControl.WaitSingleTimeOut, io.DisplayStr, wait.IoValue.ToString());//1084
                        Alarm(StoreAlarmType.IoSingleTimeOut, io.ElectricalDefinition, StoreMove.MoveType);
                        LogUtil.error(LOGGER, StoreName + wait.IoType + "等待信号(" + io.DisplayStr + "=" + wait.IoValue + ") 超时", 14);
                        isOk = false;
                        break;
                    } 
                }
                else if (wait.WaitType == 3)
                {
                    wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
                }

                else if (wait.WaitType == 5)
                {
                    //string msg = "";
                    //wait.IsEnd = ShuoKeIsEnd(wait, out msg);
                    //   NotOkMsg = NotOkMsg +" "+ msg;
                    wait.IsEnd = false;
                }
                else if (wait.WaitType == 6)
                {
                    IO_VALUE value = (IO_VALUE)ACServerManager.GetHomeSingle(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue());
                    wait.IsEnd = wait.IoValue.Equals(value);
                }
                else if (wait.WaitType == 7)
                {
                    wait.IsEnd = (wait.HeightValue.Equals(GetHeight()));
                    if (wait.IsEnd && (StoreMove.MoveStep == StoreMoveStep.SO_15_WaitTake) && wait.HeightValue.Equals(0))
                    {
                        if (TrayCheck_Door.Equals(IO_VALUE.LOW))
                        {
                            LogUtil.info(StoreMove.MoveStep + " 等待height=" + wait.HeightValue + "完成,且当前TrayCheck_Door=LOW");
                        }
                        else
                        {
                            LogUtil.info(StoreMove.MoveStep + " 等待height=" + wait.HeightValue + "完成,但当前TrayCheck_Door=High,继续等待门口无料盘信号");
                            wait.IsEnd = false;
                        }
                    }
                    if (wait.IsEnd)
                    {
                        LogUtil.debug("等待height=" + wait.HeightValue + "完成");
                    }
                }
                if (wait.IsEnd)
                {
                    if (StoreMove.OneWaitCanEndStep)
                    {
                        isOk = true;
                        break;
                    }
                }
                else
                {
                    if (!StoreMove.OneWaitCanEndStep)
                    {
                        isOk = false;
                        break;
                    }
                }
            }
            if (isOk)
            {
                StoreMove.EndStepWait();
            }
            else if (span.TotalSeconds > StoreMove.TimeOutSeconds)
            {
                //    WarnMsg = StoreName + "【" + StoreMove.MoveType + "】【" + StoreMove.MoveStep + "】等待超时  [" + NotOkMsg
                //      + "]已等待[" + Math.Round(span.TotalSeconds, 1) + "]秒";
                SetWarnMsg(ResourceControl.MoveTimeOut, StoreMove.MoveStep.ToString(), NotOkMsg, Math.Round(span.TotalSeconds, 1) + ""); //1085
                LogUtil.error(LOGGER, WarnObj.WarnMsg, 100);
                Alarm(StoreAlarmType.IoSingleTimeOut, "", StoreMove.MoveType);
            }
        }
        private static DateTime lastComRHomeTime = DateTime.Now;

        #endregion

        #region 入库

        private DateTime startInStoreTime = DateTime.Now;
        /// <summary>
        /// 开始入库移动移动
        /// </summary> 
        public void StartInStoreMove(InOutStoreParam param, bool isNeedCheckIO)
        {
            startInStoreTime = DateTime.Now;
            string posId = param != null ? param.PositionNum : "";
            if (storeRunStatus == StoreRunStatus.Runing)
            {
                if (!LoadParamPosition(param))
                {
                    LogUtil.error(LOGGER, StoreName + " 启动入库【" + posId + "】出错,找不到库位信息");
                    return;
                }
                //if (IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
                //{
                //    LogUtil.error(LOGGER, StoreName + " 启动入库【" + posId + "】出错,叉子料盘检测有料");
                //    return;
                //}
                LogUtil.info(LOGGER, StoreName + " 启动入库【" + posId + "】", storeMoveColor);
                storeRunStatus = StoreRunStatus.Busy;
                storeStatus = StoreStatus.InStoreExecute;
                StoreMove.NewMove(StoreMoveType.InStore, param);
                if (isNeedCheckIO)
                {
                    //料盘检测
                    InStoreLog("  入库:SI_00   检测料盘信号");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_00_TrayCheck);
                    //StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Door, IO_VALUE.HIGH));
                }
                else
                {
                    if (IsHasCompress_Axis || Config.IsHasLocationCylinder.Equals(0))
                    {
                        SI_02_OpenDoor(param.MoveP);
                    }
                    else
                    {
                        InStoreLog("入库:SI_01   定位气缸下降");
                        StoreMove.NextMoveStep(StoreMoveStep.SI_01_LocationCylinderDown);
                        LocationDownAndWait();
                    }
                }
            }
            else
            {
                LogUtil.error(LOGGER, StoreName + " 启动【" + posId + "】入库出错,当前状态,storeStatus=" + storeRunStatus);
            }
        }

        /// <summary>
        /// 开始入库移动移动
        /// </summary> 
        public override void StartInStoreMove(InOutStoreParam param)
        {
            StartInStoreMove(param, false);
        }
        private void SI_02_OpenDoor(LineMoveP moveP)
        {
            InStoreLog("入库:SI_02_  进出轴(叉子)动作至P1, 打开仓门");
            StoreMove.NextMoveStep(StoreMoveStep.SI_02_OpenDoor);
            //StoreMove.WaitList.Add(WaitResultInfo.WaitTime(200));
            OpenDoor();
            InOutBackToP1(moveP.InOut_P1);
            ComMoveToPosition(moveP.ComPress_P3, Config.CompAxis_P3_Speed);
        }
        private void SI_05_DeviceToDoor()
        {
            InStoreLog("入库:SI_05  叉子进入入料口,进出轴至P2(进料口取料点) ");
            StoreMove.NextMoveStep(StoreMoveStep.SI_05_DeviceToDoor);
            ACAxisMove(Config.InOut_Axis, StoreMove.MoveParam.MoveP.InOut_P2, Config.InOutAxis_P2_Speed);
            NeedCheckSafetyLight = 1;
        }
        protected override void InStoreProcess()
        {
            if (!DoorIsClose() && IOManager.IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.LOW))
            {
                SetWarnMsg(ResourceControl.safety_grating_covered, "开门时安全光栅被遮挡,暂停运行");//1086
                return;
            }
            LineMoveP moveP = StoreMove.MoveParam.MoveP;
            if (StoreMove.IsInWait)
            {
                CheckWait();
            }
            if (StoreMove.IsInWait)
            {
                return;
            }
            if (StoreMove.MoveStep == StoreMoveStep.SI_00_TrayCheck)
            {
                if (TrayCheck_Door.Equals(IO_VALUE.LOW))
                {
                    if (StoreMove.IsTimeOut(out _, 20))
                    {
                        SetWarnMsg(ResourceControl.CustAlarm, "Wait TrayCheck_Door=HIGH Timeout");
                    }
                    return;
                }
                
                if (IsHasCompress_Axis || Config.IsHasLocationCylinder.Equals(0))
                {
                    SI_02_OpenDoor(moveP);
                }
                else
                {
                    InStoreLog("入库:SI_01   定位气缸下降");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_01_LocationCylinderDown);
                    LocationDownAndWait();
                }
            }
            if (StoreMove.MoveStep == StoreMoveStep.SI_01_LocationCylinderDown)
            {
                SI_02_OpenDoor(moveP);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_02_OpenDoor)
            {
                if (DoorIsOpen())
                {
                    InStoreLog($"入库:SI_03    所有轴回到待机点,升降轴到P1:{moveP.UpDown_P1},旋转轴到P1:{moveP.Middle_P1},压紧轴至P3 :{moveP.ComPress_P3}");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_03_ReturnHome);
                    ComMoveToPosition(moveP.ComPress_P3, Config.CompAxis_P3_Speed);
                    ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P1, Config.UpDownAxis_P1_Speed);
                    ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
                    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.LOW));
                }
                else
                {
                    SI_02_OpenDoor(moveP);
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_03_ReturnHome)
            {
                if (IsHasCompress_Axis)
                {
                    InStoreLog("入库:SI_04_CompressWare  压紧物品(有压紧轴的才需要此步骤),压紧轴至P3(压紧前点) 开始");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_04_CompressWare);
                    ComMoveToPosition(moveP.ComPress_P3, Config.CompAxis_P3_Speed);                 }
                else
                {
                    SI_05_DeviceToDoor();
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_04_CompressWare)
            { 
                SI_05_DeviceToDoor();
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_05_DeviceToDoor)
            {
                NeedCheckSafetyLight = 0;
                HIKCamera.Current.CameraGrabOne(HIKCamera.Current.GetFixtureStateFilename(StoreMove.MoveParam, StoreMove.MoveType, FixtureState.DoorIn));
                if (TrayCheck_Door.Equals(IO_VALUE.HIGH))
                {
                    InStoreLog("入库:SI_06 拿物品,压紧轴至P2(压紧点)) 升降轴至P7(进料口取料缓冲点) ");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_06_DoorWarToDevice);
                    ComMoveToPosition(moveP.ComPress_P2, Config.CompAxis_P2_Speed);
                    ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P7, Config.UpDownAxis_P7_Speed);                    
                }
                else if (StoreMove.IsTimeOut(out _, 5))
                {
                    InStoreLog("入库:SI_06 未检测到料盘,任务取消 ");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_14_CheckTray);
                    ACAxisMove(Config.InOut_Axis, StoreMove.MoveParam.MoveP.InOut_P1, Config.InOutAxis_P1_Speed);
                    HttpHelper.cancelPutInTask(Name, StoreMove.MoveParam.WareNumber);
                }

            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_06_DoorWarToDevice)
            {
                InStoreLog("入库:SI_07 叉子 从入料口抽出,进出轴至P1(待机点) ");
                StoreMove.NextMoveStep(StoreMoveStep.SI_07_DeviceBackFromDoor);
                //ACAxisMove(Config.InOut_Axis, moveP.InOut_P1, Config.InOutAxis_P1_Speed);
                InOutBackToP1(moveP.InOut_P1);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_07_DeviceBackFromDoor)
            {
                HIKCamera.Current.CameraGrabOne(HIKCamera.Current.GetFixtureStateFilename(StoreMove.MoveParam, StoreMove.MoveType, FixtureState.DoorOut));
                if (Config.IsUse_Tray_Check.Equals(1))
                {
                    InStoreLog("入库:SI_08 检测叉子料盘检测信号 ");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_08_CheckTray);
                    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.HIGH));
                }
                else 
                //if (IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
                {
                    InStoreLog("入库:SI_09 移动到库位点,旋转轴至P2(库位点),升降轴至P3(库位入库前点) ");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_09_MoveToBag);
                    ACAxisMove(Config.Middle_Axis, moveP.Middle_P2, Config.MiddleAxis_P2_Speed);
                    ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P3, Config.UpDownAxis_P3_Speed);
                    //关闭仓门
                    CloseDoor(false);
                }
                //else
                //{
                //    InStoreLog("入库:SI_08 检测叉子料盘检测信号 ");
                //    StoreMove.NextMoveStep(StoreMoveStep.SI_08_CheckTray);
                //    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.HIGH));
                //}
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_08_CheckTray)
            {
                InStoreLog("入库:SI_09 移动到库位点,旋转轴至P2(库位点),升降轴至P3(库位入库前点) ");
                StoreMove.NextMoveStep(StoreMoveStep.SI_09_MoveToBag);
                ACAxisMove(Config.Middle_Axis, moveP.Middle_P2, Config.MiddleAxis_P2_Speed);
                ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P3, Config.UpDownAxis_P3_Speed);
                //关闭仓门 
                CloseDoor(false);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_09_MoveToBag)
            {
                
                if (IsHasCompress_Axis || Config.IsHasLocationCylinder.Equals(0))
                {
                    InStoreLog("入库:SI_11  叉子进入库位中,进出轴至P3(库位取放料点) ");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_11_DeviceToBag);
                    ACAxisMove(Config.InOut_Axis, moveP.InOut_P3, Config.InOutAxis_P3_Speed);
                }
                else
                {
                    InStoreLog("入库:SI_10  定位气缸退回 ");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_10_LocationCylinder_Down);
                    LocationDownAndWait();
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_10_LocationCylinder_Down)
            {
                
                //IOManager.IOMove(IO_Type.LocationCylinder_Down, IO_VALUE.LOW);
                InStoreLog("入库:SI_11 叉子进入库位中,进出轴至P3(库位取放料点) ");
                StoreMove.NextMoveStep(StoreMoveStep.SI_11_DeviceToBag);
                ACAxisMove(Config.InOut_Axis, moveP.InOut_P3, Config.InOutAxis_P3_Speed);

            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_11_DeviceToBag)
            {
                HIKCamera.Current.CameraGrabOne(HIKCamera.Current.GetFixtureStateFilename(StoreMove.MoveParam, StoreMove.MoveType, FixtureState.In));
                InStoreLog("入库:SI_12  放下物品,升降轴至P4(库位入料缓冲点),压紧轴至P3(压紧前点) ");
                // 5= 入仓位完成(料仓Box把料盘放入对应的库位中,装置还未恢复原始状态)   
                string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
                lastPosId = posId;
                lastPosIdStatus = StoreStatus.InStoreEnd;
                storeStatus = StoreStatus.InStoreEnd;
                //手动发给服务器状态,防止没有手动
                //SendLineStatus(StoreID, posId, StoreStatus.InStoreEnd);

                StoreMove.NextMoveStep(StoreMoveStep.SI_12_PutWareToBag);
                ComMoveToPosition(moveP.ComPress_P3, Config.CompAxis_P3_Speed);
                ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P4, Config.UpDownAxis_P4_Speed);

            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_12_PutWareToBag)
            {
                InStoreLog("入库:SI_13  叉子从库位中返回,进出轴动作至P1(待机点) ");

                StoreMove.NextMoveStep(StoreMoveStep.SI_13_DeviceBackFromBag);
                InOutBackToP1(moveP.InOut_P1);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_13_DeviceBackFromBag)
            {
                HIKCamera.Current.CameraGrabOne(HIKCamera.Current.GetFixtureStateFilename(StoreMove.MoveParam, StoreMove.MoveType, FixtureState.Out));
                if (IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.LOW))
                {
                    InStoreLog("入库:SI_15  返回待机点,轴2/轴1/轴4动作至P1(待机点)),关闭仓门");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_15_GoBack);
                    ComMoveToPosition(moveP.ComPress_P1, Config.CompAxis_P1_Speed);
                    ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
                    ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P1, Config.UpDownAxis_P1_Speed);
                    CloseDoor();
                }
                else
                {
                    InStoreLog("入库:SI_14   放料完成,等待TrayCheck_Fixture=LOW");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_14_CheckTray);
                    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.LOW));
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_14_CheckTray)
            {
                InStoreLog("入库:SI_15  返回待机点,轴2/轴1/轴4动作至P1(待机点)),关闭仓门");
                StoreMove.NextMoveStep(StoreMoveStep.SI_15_GoBack);
                ComMoveToPosition(moveP.ComPress_P1, Config.CompAxis_P1_Speed);
                ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
                ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P1, Config.UpDownAxis_P1_Speed);
                CloseDoor();
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_15_GoBack)
            {
                TimeSpan span = DateTime.Now - startInStoreTime;
                string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
                LogUtil.info(LOGGER, StoreName + "  【" + posId + "】 入库结束[" + FormUtil.GetSpanStr(span) + "]", storeMoveColor);
                StoreMove.EndMove();
                storeRunStatus = StoreRunStatus.Runing;
                //设备连接,入库后,BOX恢复原始状态 
                storeStatus = StoreStatus.StoreOnline;
                InOutEndProcess(StoreMoveType.InStore,posId);
            }
            else
            {
                LogUtil.info(LOGGER, StoreName + " 入库,moveStatus=" + StoreMove.MoveStep + ",没有对应的处理!");
            }

        }


        #endregion


        #region 出库
        private DateTime startOutStoreTime = DateTime.Now;
        /// <summary>
        /// 开始出库运动
        /// </summary> 
        public override bool StartOutStoreMove(InOutStoreParam param)
        {
            startOutStoreTime = DateTime.Now;
            string posId = param != null ? param.PositionNum : "";
            if (storeRunStatus == StoreRunStatus.Runing)
            {
                if (!LoadParamPosition(param))
                {
                    LogUtil.error(LOGGER, StoreName + " 启动出库【" + posId + "】出错,找不到库位信息");
                    return false;
                }
                //if (IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
                //{
                //    LogUtil.error(LOGGER, StoreName + " 启动出库【" + posId + "】出错,叉子料盘检测有料");
                //    return false;
                //}
                storeStatus = StoreStatus.OutStoreExecute;
                LogUtil.info(LOGGER, StoreName + "启动出库【" + posId + "】  ", storeMoveColor);
                storeRunStatus = StoreRunStatus.Busy;
                StoreMove.NewMove(StoreMoveType.OutStore, param);
                if (IsHasCompress_Axis || Config.IsHasLocationCylinder.Equals(0))
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_02_DeviceBack);
                    OutStoreLog("出库:SO_02  叉子先运动到P1   开始"); 
                    InOutBackToP1(StoreMove.MoveParam.MoveP.InOut_P1); 
                }
                else
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_01_LocationCylinderDown);
                    OutStoreLog("出库:SO_01 定位气缸下降");
                    LocationDownAndWait();
                }
                return true;
            }
            else
            {
                LogUtil.error(LOGGER, StoreName + " 启动出库出错,当前状态,storeStatus=" + storeRunStatus);
            }
            return false;
        }
        bool fixturestates = false;
        LineMoveP movePfix = new LineMoveP();
        protected override void OutStoreProcess()
        {
            if (!DoorIsClose() && IOManager.IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.LOW))
            {
                return;
            }
            LineMoveP moveP = StoreMove.MoveParam.MoveP;
            if (StoreMove.IsInWait)
            {
                CheckWait();
            }
            if (StoreMove.IsInWait)
            {
                return;
            }
            if (StoreMove.MoveStep == StoreMoveStep.SO_01_LocationCylinderDown)
            {
                StoreMove.NextMoveStep(StoreMoveStep.SO_02_DeviceBack);
                OutStoreLog("出库:SO_02  叉子先运动到P1 ");
                InOutBackToP1(StoreMove.MoveParam.MoveP.InOut_P1);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_02_DeviceBack)
            {
                fixturestates = false;
                StoreMove.NextMoveStep(StoreMoveStep.SO_03_ToBagPosition);
                OutStoreLog("出库:SO_03 走到库位,压紧轴至P3(压紧前点) ,旋转轴至P2(库位点),升降轴至P5(库位出库前点)");
                ComMoveToPosition(moveP.ComPress_P3, Config.CompAxis_P3_Speed);

                ACAxisMove(Config.Middle_Axis, StoreMove.MoveParam.MoveP.Middle_P2, Config.MiddleAxis_P2_Speed);
                ACAxisMove(Config.UpDown_Axis, StoreMove.MoveParam.MoveP.UpDown_P5, Config.UpDownAxis_P5_Speed);
                StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.LOW));
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_03_ToBagPosition)
            {
                StoreMove.NextMoveStep(StoreMoveStep.SO_04_DeviceToBag);
                OutStoreLog("出库:SO_04 叉子进入库位中,  进出轴至P3(库位取放料点) ");
                ACAxisMove(Config.InOut_Axis, moveP.InOut_P3, Config.InOutAxis_P3_Speed);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_04_DeviceToBag)
            {
                HIKCamera.Current.CameraGrabOne(HIKCamera.Current.GetFixtureStateFilename(StoreMove.MoveParam, StoreMove.MoveType, FixtureState.In));
                OutStoreLog("出库:SO_05 拿起物品,升降轴至P6(库位出料缓冲点),压紧轴至P2(压紧点) ");
                StoreMove.NextMoveStep(StoreMoveStep.SO_05_BagWareToDevice);

                ComMoveToPosition(moveP.ComPress_P2, Config.CompAxis_P2_Speed);
                ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P6, Config.UpDownAxis_P6_Speed);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_05_BagWareToDevice)
            {
                StoreMove.NextMoveStep(StoreMoveStep.SO_06_BagDeviceBack);
                OutStoreLog("出库:SO_06 叉子从库位返回,进出轴至P1(待机点) ");
                //ACAxisMove(Config.InOut_Axis, moveP.InOut_P1, Config.InOutAxis_P1_Speed);
                InOutBackToP1(moveP.InOut_P1);
                //把库位的物品放到取到叉子上之后是出仓完成 
                string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
                lastPosId = posId;
                lastPosIdStatus = StoreStatus.OutStoreBoxEnd;
                storeStatus = StoreStatus.OutStoreBoxEnd;

            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_06_BagDeviceBack)
            {
                HIKCamera.Current.CameraGrabOne(HIKCamera.Current.GetFixtureStateFilename(StoreMove.MoveParam, StoreMove.MoveType, FixtureState.Out));
                fixturestates = IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH);

                var fixposid = $"fix#{StoreMove.MoveParam.PlagtW}";
                var fixposition = CSVPositionReader<ACStorePosition>.GetPositon(fixposid);
                OutStoreLog($"出库 获取修正库位置{fixposid}={fixposition}");
                if (fixposition != null)
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_07_CheckFix);
                }
                else
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_08_ToDoorPosition);
                    OutStoreLog("出库:SO_08  走到料门口,旋转轴至P1(待机点)升降轴至P2(进料口出料前点),  ");
                    ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P2, Config.UpDownAxis_P2_Speed);
                    ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_07_CheckFix)
            {
                var fixposid = $"fix#{StoreMove.MoveParam.PlagtW}";
                var fixposition = CSVPositionReader<ACStorePosition>.GetPositon(fixposid);
                OutStoreLog($"出库 获取修正库位置{fixposid}={fixposition}");
                if (fixposition != null)
                {
                    OutStoreLog($"出库  找到对应修正库位 获取修正库位置{fixposid}={fixposition}");
                    
                    movePfix.ComPress_P1 = Config.CompressAxis_P1_Position;
                    movePfix.InOut_P1 = Config.InOutAxis_P1_Position;
                    movePfix.Middle_P1 = Config.MiddleAxis_P1_Position;

                    movePfix.InOut_P2 = fixposition.InOutAxis_DoorPosition_P2;
                    movePfix.UpDown_P1 = Config.UpDownAxis_DoorOPosition_P1;
                    movePfix.UpDown_P8 = Config.UpDownAxis_DoorIBPosition_P8;
                    movePfix.UpDown_P2 = Config.UpDownAxis_DoorIPosition_P2;
                    movePfix.UpDown_P7 = Config.UpDownAxis_DoorOBPosition_P7;

                    movePfix.ComPress_P2 = fixposition.CompressAxis_Position_P2;
                    if (int.TryParse(StoreMove.MoveParam.PlateH, out int plateh))
                    {
                        var h = Config.GetComP2(plateh);
                        if (h > 0)
                            movePfix.ComPress_P2 = h;
                    }
                    movePfix.ComPress_P3 = fixposition.CompressAxis_CPosition_P3;
                    movePfix.InOut_P3 = fixposition.InOutAxis_Position_P3;
                    movePfix.Middle_P2 = fixposition.MiddleAxis_Position_P2;
                    movePfix.UpDown_P3 = fixposition.UpDownAxis_IHPosition_P3;
                    movePfix.UpDown_P4 = fixposition.UpDownAxis_ILPosition_P4;
                    movePfix.UpDown_P5 = fixposition.UpDownAxis_OHPosition_P5;
                    movePfix.UpDown_P6 = fixposition.UpDownAxis_OLPosition_P6;


                    StoreMove.NextMoveStep(StoreMoveStep.SO_07_CheckFix_01);
                }
                else
                {
                    OutStoreLog($"出库  未找到对应修正库位 获取修正库位置{fixposid}");
                    StoreMove.NextMoveStep(StoreMoveStep.SO_07_CheckTray);
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_07_CheckFix_01)
            {
                StoreMove.NextMoveStep(StoreMoveStep.SO_07_CheckFix_02);
                InStoreLog("出库:库位修正,旋转轴至P2(修正库位点),升降轴至P3(修正库位入库前点) ");
                ACAxisMove(Config.Middle_Axis, movePfix.Middle_P2, Config.MiddleAxis_P2_Speed);
                ACAxisMove(Config.UpDown_Axis, movePfix.UpDown_P3, Config.UpDownAxis_P3_Speed);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_07_CheckFix_02)
            {
                StoreMove.NextMoveStep(StoreMoveStep.SO_07_CheckFix_03);
                InStoreLog("出库:库位修正  叉子进入库位中,进出轴至Fix(修正库位取放料点) ");
                int InOutFixPos = 0;
                ACAxisMove(Config.InOut_Axis, movePfix.InOut_P3 + InOutFixPos, Config.InOutAxis_P3_Speed);

            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_07_CheckFix_03)
            {
                StoreMove.NextMoveStep(StoreMoveStep.SO_07_CheckFix_04);
                InStoreLog("出库:库位修正  压紧轴释放,升降轴到P4 ");
                ComMoveToPosition(movePfix.ComPress_P3, Config.CompAxis_P3_Speed);
                ACAxisMove(Config.UpDown_Axis, movePfix.UpDown_P4, Config.UpDownAxis_P4_Speed);
            }
            //else if (StoreMove.MoveStep == StoreMoveStep.SO_07_CheckFix_04_inoutp3)
            //{
            //    StoreMove.NextMoveStep(StoreMoveStep.SO_07_CheckFix_04);
            //    InStoreLog("出库:库位修正  进出轴到P3 ");
            //    ACAxisMove(Config.InOut_Axis, movePfix.InOut_P3, Config.InOutAxis_P3_Speed);
            //}
            else if (StoreMove.MoveStep == StoreMoveStep.SO_07_CheckFix_04)
            {
                StoreMove.NextMoveStep(StoreMoveStep.SO_07_CheckFix_05);
                InStoreLog("出库:库位修正  压紧轴压紧,升降轴到P6 ");
                ComMoveToPosition(movePfix.ComPress_P2, Config.CompAxis_P2_Speed);
                ACAxisMove(Config.UpDown_Axis, movePfix.UpDown_P6, Config.UpDownAxis_P6_Speed);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_07_CheckFix_05)
            {
                StoreMove.NextMoveStep(StoreMoveStep.SO_07_CheckTray);
                InStoreLog("出库:库位修正  进出轴返回P1 ");
                InOutBackToP1(moveP.InOut_P1);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_07_CheckTray)
            {
                StoreMove.NextMoveStep(StoreMoveStep.SO_08_ToDoorPosition);
                OutStoreLog("出库:SO_08  走到料门口,旋转轴至P1(待机点)升降轴至P2(进料口出料前点),  ");
                ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P2, Config.UpDownAxis_P2_Speed);
                ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_08_ToDoorPosition)
            {
                if (IsHasCompress_Axis || Config.IsHasLocationCylinder.Equals(0))
                {
                    SO_091_WaitNoTray();
                }
                else
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_09_LocationCylinder_Down);
                    OutStoreLog("出库:SO_09 定位气缸退回,定位气缸退回   ");
                    LocationDownAndWait();
                }
            }
            //此处需要等待移栽没有工作,才能把盘放入出料口
            else if (StoreMove.MoveStep == StoreMoveStep.SO_09_LocationCylinder_Down)
            {                
                 SO_091_WaitNoTray();
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_091_WaitNoTray)
            {
                if (DoorIsOpen())
                {
                    SO_10_DeviceToDoorPro();
                }
                else
                {
                    SO_091_WaitNoTray();
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_10_DeviceToDoor)
            {
                HIKCamera.Current.CameraGrabOne(HIKCamera.Current.GetFixtureStateFilename(StoreMove.MoveParam, StoreMove.MoveType, FixtureState.DoorIn));
                OutStoreLog($"出库:SO_11 放下物品,升降轴至P8(进料口出料缓冲点){moveP.UpDown_P8},压紧轴到P1{moveP.ComPress_P1} ");
                SetWarnMsg("");
                StoreMove.NextMoveStep(StoreMoveStep.SO_11_DevicePutWare);
                NeedCheckSafetyLight = 0;
                ComMoveToPosition(moveP.ComPress_P1, Config.CompAxis_P1_Speed);
                ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P8, Config.UpDownAxis_P8_Speed);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_11_DevicePutWare)
            {
                StoreMove.NextMoveStep(StoreMoveStep.SO_12_DeviceOutFromDoor);
                OutStoreLog("出库:SO_12 叉子从出料口返回,,进出轴动作至P1(待机点) ");
                InOutBackToP1(moveP.InOut_P1);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_12_DeviceOutFromDoor)
            {
                string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
                lastPosId = posId;
                if (TrayCheck_Door.Equals(IO_VALUE.HIGH))
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_13_CheckTray);
                    OutStoreLog($"出库:检测到料盘 SO_13 等待TrayCheck_Fixture= LOW && TrayCheck_Door=high");

                    lastPosIdStatus = StoreStatus.OutStorEnd;
                    storeStatus = StoreStatus.OutStorEnd;
                    SendLineStatus();
                }
                else if (StoreMove.IsTimeOut(out _,5))
                {

                    lastPosIdStatus = StoreStatus.OutStoreError;
                    storeStatus = StoreStatus.OutStoreError;
                    SendLineStatus();
                    HIKCamera.Current.CameraGrabOne(HIKCamera.Current.GetFixtureStateFilename(StoreMove.MoveParam, StoreMove.MoveType, FixtureState.DoorOut));
                    StoreMove.NextMoveStep(StoreMoveStep.SO_TakeReelFaile);
                    //StoreMove.NextMoveStep(StoreMoveStep.SO_15_WaitTake);
                    //OutStoreLog("出库:出库未检测到料盘,出库失败");
                    //OutStoreLog("出库:SO_12_DeviceOutFromDoor  升降轴返回,轴2至P1(待机点) ,关闭仓门,更改状态为出库完成");
                    //ACAxisMove(Config.UpDown_Axis, StoreMove.MoveParam.MoveP.UpDown_P1, Config.UpDownAxis_P1_Speed);
                    //CloseDoor();
                    SetWarnMsg(ResourceControl.take_out_reel_failure, posId);//1083
                    OutStoreLog($"料叉没有成功取出料盘,请检查库位[{posId}]");

                }
                //改为出库完成 


            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_TakeReelFaile)
            {
                string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
                SetWarnMsg(ResourceControl.take_out_reel_failure, posId); //1083
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_13_CheckTray)
            {
                HIKCamera.Current.CameraGrabOne(HIKCamera.Current.GetFixtureStateFilename(StoreMove.MoveParam, StoreMove.MoveType, FixtureState.DoorOut));
                SO_14_GoBack();
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_14_GoBack)
            {
                HIKCamera.Current.CameraGrabOne(HIKCamera.Current.GetFixtureStateFilename(StoreMove.MoveParam, StoreMove.MoveType, FixtureState.DoorOut));
                StoreMove.NextMoveStep(StoreMoveStep.SO_15_WaitTake);
                if (!autoNext)
                {
                    if (OutStoreWaitSeconds > 0)
                    {
                        int ms = OutStoreWaitSeconds * 1000;
                        OutStoreLog("出库:SO_15_WaitTake 等待拿走物品,最多等待" + OutStoreWaitSeconds + "秒");
                        StoreMove.WaitList.Add(WaitResultInfo.WaitTime(ms));
                        StoreMove.WaitList.Add(WaitResultInfo.WaitHeight(0));
                        if (OutStoreWaitSeconds > 120)
                        {
                            StoreMove.TimeOutSeconds = 120;
                        }
                        else
                        {
                            //StoreMove.TimeOutSeconds = OutStoreWaitSeconds;
                        }
                        StoreMove.OneWaitCanEndStep = true;
                    }
                    else
                    {
                        OutStoreLog("出库:SO_15_WaitTake 等待拿走物品 ");
                        StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Door, IO_VALUE.LOW));
                        StoreMove.WaitList.Add(WaitResultInfo.WaitHeight(0));
                    }
                }
                else
                {
                    OutStoreLog("出库:SO_15_WaitTake 自动出入库中,等待3秒后继续");
                    StoreMove.WaitList.Add(WaitResultInfo.WaitTime(3000));
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_15_WaitTake)
            {
                //如果配置是0,再次验证是否拿走物品
                if (OutStoreWaitSeconds <= 0)
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_16_CheckIsTake);
                    OutStoreLog("出库:SO_16_CheckIsTake 再次等待物品是否已拿走 ");
                    StoreMove.WaitList.Add(WaitResultInfo.WaitTime(200));
                    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Door, IO_VALUE.LOW));
                    StoreMove.WaitList.Add(WaitResultInfo.WaitHeight(0));
                }
                else
                {
                    OutStoreEnd();
                }

            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_16_CheckIsTake)
            {
                OutStoreEnd();
            }
            else
            {
                LogUtil.error(LOGGER, StoreName + " 出库处理,moveStatus=" + StoreMove.MoveStep + ",没有对应的处理!");
            }

        }
        private void SO_091_WaitNoTray()
        {
            if (IOManager.IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.HIGH) &&
                TrayCheck_Door.Equals(IO_VALUE.LOW))
            {
                StoreMove.NextMoveStep(StoreMoveStep.SO_091_WaitNoTray);
                OutStoreLog("出库:SO_091 打开仓门,等待门口无料盘 ");
                StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Door, IO_VALUE.LOW));
                StoreMove.WaitList.Add(WaitResultInfo.WaitHeight(0));
                OpenDoor();
            }
            else if (StoreMove.IsTimeOut(out double timeout)) {
                if (TrayCheck_Door.Equals(IO_VALUE.HIGH))
                {
                    SetWarnMsg(ResourceControl.MoveTimeOut, StoreMove.MoveStep + "", IO_Type.TrayCheck_Door.ToString() + "=LOW", timeout.ToString("f1")+"s"); //1085
                    LogUtil.error(LOGGER, WarnObj.WarnMsg, 100);
                }
                else if(IOManager.IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.LOW))
                {
                    SetWarnMsg(ResourceControl.MoveTimeOut, StoreMove.MoveStep + "", IO_Type.SafetyLightCurtains.ToString()+"=HIGH", timeout.ToString("f1") + "s"); //1085
                    LogUtil.error(LOGGER, WarnObj.WarnMsg, 100);
                } 
            }
        }
        private void OutStoreEnd()
        {
            TimeSpan span = DateTime.Now - startOutStoreTime;
            string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
            storeStatus = StoreStatus.StoreOnline;
            LogUtil.info(LOGGER, StoreName + " 【" + posId + "】出库结束[" + FormUtil.GetSpanStr(span) + "]", storeMoveColor);
            StoreMove.EndMove();
            storeRunStatus = StoreRunStatus.Runing;
            InOutEndProcess(StoreMoveType.OutStore,posId);
        }
        private void SO_14_GoBack()
        {
            StoreMove.NextMoveStep(StoreMoveStep.SO_14_GoBack);
            OutStoreLog("出库:SO_14 升降轴返回,轴2至P1(待机点) ,关闭仓门,更改状态为出库完成");
            ACAxisMove(Config.UpDown_Axis, StoreMove.MoveParam.MoveP.UpDown_P1, Config.UpDownAxis_P1_Speed);
            CloseDoor();


        }
        private void SO_10_DeviceToDoorPro()
        {
            LineMoveP moveP = StoreMove.MoveParam.MoveP;
            StoreMove.NextMoveStep(StoreMoveStep.SO_10_DeviceToDoor);
            OutStoreLog("出库:SO_10  叉子进出料口,进出轴至P2(进料口取料点) ");
            ACAxisMove(Config.InOut_Axis, moveP.InOut_P2, Config.InOutAxis_P2_Speed);
            NeedCheckSafetyLight = 1;
        }
        public bool InOutAxisCanMove()
        {
            if (StoreManager.Store.Config.IsHasLocationCylinder.Equals(0))
            {
                return true;
            }
            return true;
            //if (IOManager.IOValue(IO_Type.LocationCylinder_Down).Equals(IO_VALUE.HIGH)
            //    && IOManager.IOValue(IO_Type.LocationCylinder_Up).Equals(IO_VALUE.LOW)
            //    && IOManager.IOValue(IO_Type.LocationCylinder2_Down).Equals(IO_VALUE.HIGH)
            //    && IOManager.IOValue(IO_Type.LocationCylinder2_Up).Equals(IO_VALUE.LOW))
            //{
            //    return true;
            //}
            //return false;
        }
        private void LocationUpAndWait()
        {
            //if (Config.IsHasLocationCylinder>=1)
            //{
            //    IOManager.IOMove(IO_Type.LocationCylinder_Up, IO_VALUE.HIGH);
            //    IOManager.IOMove(IO_Type.LocationCylinder_Down, IO_VALUE.LOW);
            //    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LocationCylinder_Up, IO_VALUE.HIGH));
            //    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LocationCylinder_Down, IO_VALUE.LOW));
            //    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LocationCylinder2_Up, IO_VALUE.HIGH));
            //    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LocationCylinder2_Down, IO_VALUE.LOW));
            //}
        }
        private void LocationDownAndWait()
        {
            //if (Config.IsHasLocationCylinder>=1)
            //{
            //    IOManager.IOMove(IO_Type.LocationCylinder_Down, IO_VALUE.HIGH);
            //    IOManager.IOMove(IO_Type.LocationCylinder_Up, IO_VALUE.LOW);
            //    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LocationCylinder_Down, IO_VALUE.HIGH));
            //    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LocationCylinder_Up, IO_VALUE.LOW));
            //    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LocationCylinder2_Down, IO_VALUE.HIGH));
            //    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.LocationCylinder2_Up, IO_VALUE.LOW));
            //}
        }
        #endregion
        public List<FixtureCodeInfo> waitOutStoreList = new List<FixtureCodeInfo>();
        public object waitOutListLock = "";
        

        public void AddWaitOutInfo(FixtureCodeInfo code)
        {
            lock (waitOutListLock)
            {
                var x = waitOutStoreList.FindAll((fx) => { return fx.PosId == code.PosId; });
                if (x.Count==0)
                    waitOutStoreList.Add(code);
            }
        }
        /// <summary>
        /// PosId, InOut,isSuccess
        /// </summary>
        public event Action<string,StoreMoveType,bool> InOutEndProcessEvent;
        private string AutoOut { get => ResourceControl.GetString("自动出库:"); }
        private string AutoIn { get => ResourceControl.GetString("自动入库:"); }
        public bool Alternate = true;
        private void InOutEndProcess(StoreMoveType storeMoveType,string current_posid)
        {
            try
            {
                CurrInOutCount++;
                CurrInOutACount++;
                LogUtil.info(LOGGER, "自动出入库状态:"+ autoNext.ToString());
                InOutEndProcessEvent?.Invoke(current_posid, storeMoveType, true);
                //是否自动进入出库状态
                if (!autoNext)
                {
                    return;
                }
                LogUtil.info(LOGGER, "开始自动出入库计算");
                if (storeMoveType.Equals(StoreMoveType.InStore) && Double_Alternate && !hasDoublePlate)
                {
                    string posid = PositionNumList[autoPositionIndex-1];
                    LogUtil.info(LOGGER, StoreName + "自动进入双盘下一个入库:posid=" + posid);
                    hasDoublePlate = true;
                    autoMsg = "自动入库:" + posid;
                    StartInStoreMove(new InOutStoreParam("AAAA", posid));
                    return;
                }



                if (storeMoveType.Equals(StoreMoveType.InStore))
                {
                    if (Double_Alternate && Alternate)
                    {
                        autoPositionIndex += 2;
                        Alternate = false;
                    }
                    else if (Double_Alternate && !Alternate)
                    {
                        autoPositionIndex--;
                           Alternate = true;
                    }

                        //    autoPositionIndex = newIndex;
                        string posid = PositionNumList[autoPositionIndex];
                    //判断是否需要重置
                    if (CurrInOutACount >= Config.Box_ResetACount)
                    {
                        LogUtil.info(LOGGER, StoreName + $"自动进入下一个出库:{autoPositionIndex} posid=" + posid + ",当时已经出入库" + CurrInOutACount + "次,需要重置BOX,先把出库信息存入排队列表中");
                        Reset(false);
                        autoMsg = AutoOut + posid;
                        AddWaitOutInfo(new FixtureCodeInfo(0, "", posid));
                    }
                    else
                    {
                        LogUtil.info(LOGGER, StoreName + $"自动进入下一个出库:{autoPositionIndex} posid=" + posid);
                        autoMsg = AutoOut + posid;
                        StartOutStoreMove(new InOutStoreParam("", posid));
                    }
                }
                else if (storeMoveType.Equals(StoreMoveType.OutStore))
                {
                    int newIndex = autoPositionIndex - autoJiange;
                    if (newIndex < 0)
                    {
                        //if (AutoStartIndex >= 0 && AutoStartIndex < PositionNumList.Count)
                        //{
                        //    newIndex = AutoStartIndex;
                        //    LogUtil.info(LOGGER, StoreName + "下一个索引不存在,重新开始自动出入库,索引【" + AutoStartIndex + "】");
                        //}
                        //else
                        {
                            autoNext = false;
                            autoMsg = "自动出入库结束!";
                            LogUtil.info(LOGGER, StoreName + "下一个索引不存在,自动 出入库结束!");
                        }
                    }
                    if (autoNext)
                    {
                        autoPositionIndex = newIndex;
                        string posid = PositionNumList[autoPositionIndex];
                        //判断是否需要重置
                        if (CurrInOutACount >= Config.Box_ResetACount)
                        {
                            LogUtil.info(LOGGER, StoreName + $"自动进入下一个入库:{autoPositionIndex} posid=" + posid + ",当时已经出入库" + CurrInOutACount + "次,需要重置BOX,先把入库信息存入排队列表中");
                            Reset(false);
                            autoMsg = AutoIn + posid;
                            AddWaitOutInfo(new FixtureCodeInfo(0, "AAAA", posid));
                        }
                        else
                        {
                            LogUtil.info(LOGGER, StoreName + $"自动进入下一个入库:{autoPositionIndex} posid=" + posid);
                            autoMsg = AutoIn + posid;
                            StartInStoreMove(new InOutStoreParam("AAAA", posid));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(LOGGER, ex.ToString());
            }
        }
        private void InStoreLog(string msg)
        {
            string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
            LogUtil.info(LOGGER, "【" + posId + "】" + msg, storeMoveColor);
        }
        private void OutStoreLog(string msg)
        {
            string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
            LogUtil.info(LOGGER, "【" + posId + "】" + msg, storeMoveColor);
        }


        public bool NeedShowBtn()
        {
            if (alarmType.Equals(StoreAlarmType.IoSingleTimeOut))
            {
                if (StoreMove.MoveType.Equals(StoreMoveType.OutStore) && StoreMove.MoveStep.Equals(StoreMoveStep.SO_07_CheckTray))
                {
                    return true;
                }
                else if (StoreMove.MoveType.Equals(StoreMoveType.InStore) && StoreMove.MoveStep.Equals(StoreMoveStep.SI_08_CheckTray))
                { 
                    return true;
                }
            }
            return false;
        }


        public bool BtnNextPro()
        {
            if (alarmType.Equals(StoreAlarmType.IoSingleTimeOut))
            {
                if (StoreMove.MoveType.Equals(StoreMoveType.OutStore) && StoreMove.MoveStep.Equals(StoreMoveStep.SO_07_CheckTray))
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_07_CheckTray);
                    StoreMove.WaitList.Add(WaitResultInfo.WaitTime(100));
                    InStoreLog("出库:SO_07 等待TrayCheck_Fixture=High,BtnNextPro 忽略夹爪检测信号 ");
                    return true;
                }
                else if (StoreMove.MoveType.Equals(StoreMoveType.InStore) && StoreMove.MoveStep.Equals(StoreMoveStep.SI_08_CheckTray))
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SI_08_CheckTray);
                    StoreMove.WaitList.Add(WaitResultInfo.WaitTime(100));
                    InStoreLog("入库:SI_08 检测叉子料盘检测信号,BtnNextPro 忽略夹爪检测信号 ");
                    return true;
                }
            }
            return false;
        }
    }
}