AC_SA_BoxBean_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 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
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;

namespace OnlineStore.DeviceLibrary
{
    partial class AC_SA_BoxBean
    {
        static AxisManager ACServerManager = AxisManager.instance;

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

        //private static StoreMoveType lastMoveType = StoreMoveType.None;

        #endregion

        #region 出入库参数 

        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();
                AutoStorePosition position = param.GetPosition();
                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.UpDown_Door_P7 = Config.UpDownAxis_Door_P7;
                p.UpDown_OutHigh_P2 = Config.UpDownAxis_OutHigh_P2;
                p.UpDown_OutLow_P8 = Config.UpDownAxis_OutLow_P8;
                p.InOut_P2 = position.InOutAxis_Batch_P2;
                p.InOut_P4 = position.InOutAxis_DoorOutPosition_P4;

                p.UpDown_P1 = Config.GetUpDownP1(param.PlateH);

                p.ComPress_P2 = position.CompressAxis_Position_P2;
                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;
            }

            int com2Value = Config.GetComP2(param.PlateH);
            if (com2Value.Equals(-1).Equals(false))
            {
                param.MoveP.ComPress_P2 = com2Value;
                //LogUtil.debug("【" + param.PositionNum + "】高度【" + param.PlateH + "】压紧点2位置【" + param.MoveP.ComPress_P2 + "】");
            }
            //出库时批量上下料轴需要下降的高度 
            param.MoveP.BatchAxis_DownValue = AutomaticBaiting.AxisChangeValue * param.PlateH + Config.BatchAxis_OutDownPosition;
            //LogUtil.debug("【" + param.PositionNum + "】高度【" + param.PlateH + "】批量上下料轴需要下降【" + param.MoveP.BatchAxis_DownValue + "】");
            param.MoveP.UpDown_P1 = Config.GetUpDownP1(param.PlateH);
            LogUtil.debug("【" + param.PositionNum + "】高【" + param.PlateH + "】升降轴P1【" + param.MoveP.UpDown_P1 + "】压紧轴P2【" + param.MoveP.ComPress_P2 + "】批量上下料轴需要下降【" + param.MoveP.BatchAxis_DownValue + "】");
            return true;
        }

        #endregion

        #region 出入库结果验证

        private bool InOutBackToP1(int InOut_P1)
        {
            //判断是否在P1,如果是,不需要运行 
            int outCount = ACServerManager.GetActualtPosition(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue());
            int errorCount = Math.Abs(outCount - InOut_P1);
            if (errorCount <= Config.InOut_Axis.CanErrorCountMin)
            {
                LogUtil.debug("进出轴当前位置:" + outCount + ",已经在P1,不需要再回P1");
                return false;
            }
            else
            {
                ACAxisMove(Config.InOut_Axis, InOut_P1, Config.InOutAxis_P1_Speed);
                return true;
            }
        }
        private DateTime preRWTime = DateTime.Now;
        private void CheckWait()
        {
            List<WaitResultInfo> list = StoreMove.WaitList;
            //当等待超过一分钟时,需要打印提示 
            TimeSpan span = DateTime.Now - StoreMove.LastSetpTime;
            string NotOkMsg = "";
            int waitType = 0;
            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();
                waitType = wait.WaitType;
                if (wait.WaitType == (int)Wait_Type.AxisMove_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;
                        //LogUtil.info(msg);
                        Alarm(StoreAlarmType.AxisMoveError, GetAlarmCodeByAxis(wait.AxisInfo).ToString(), WarnObj.WarnMsg, StoreMove.MoveType);
                        return;
                        break;
                    }
                }
                else if (wait.WaitType == (int)Wait_Type.IOMove_2)
                {
                    wait.IsEnd = IOManager.IOValue(wait.IoType).Equals(wait.IoValue);
                    int timeOutMs = Config.IOSingle_TimerOut;
                    if (StoreMove.MoveStep == StoreMoveStep.SO_14_WaitTake)
                    {
                        timeOutMs = 650000;
                    }
                    TimeSpan rwSpan = DateTime.Now - preRWTime;
                    if (wait.IsEnd.Equals(false) && rwSpan.TotalSeconds > 5 && span.TotalSeconds > 6 && span.TotalSeconds < 30 && Config.DOList.ContainsKey(wait.IoType))
                    {
                        preRWTime = DateTime.Now;
                        string msg = " [" + StoreMove.MoveType + "][" + StoreMove.MoveStep + "] " + NotOkMsg + "已等待 " + Math.Round(span.TotalSeconds, 1) + "秒,重写DO:";
                        bool isLog = false;
                        foreach (WaitResultInfo ww in list)
                        {
                            if (ww != null && ww.WaitType.Equals(2) && Config.DOList.ContainsKey(ww.IoType))
                            {
                                if (IOManager.DOValue(ww.IoType).Equals(ww.IoValue).Equals(false))
                                {
                                    isLog = true;
                                    IOManager.IOMove(ww.IoType, ww.IoValue);
                                    msg += ww.ToStr() + ",";
                                }
                            }
                        }
                        if (isLog)
                        {
                            LogUtil.error(StoreName + msg);
                        }
                    }
                    if ((!wait.IsEnd) && span.TotalMilliseconds > timeOutMs)
                    {
                        ConfigIO io = Config.getWaitIO(wait.IoType);
                        //  WarnMsg = StoreName + ResourceControl.GetString(ResourceControl.WaitSingle, " 等待信号") + io.DisplayStr + "=" + wait.IoValue + ResourceControl.GetString(ResourceControl.TimeOut, "超时!");
                        SetWarnMsg(ResourceControl.WaitSingleTimeOut, io.ElectricalDefinition + "_" + io.ProName, wait.IoValue + "");
                        Alarm(StoreAlarmType.IoSingleTimeOut, io.ElectricalDefinition, WarnObj.WarnMsg, StoreMove.MoveType);
                        LogUtil.error(WarnObj.WarnMsg, 14);
                        isOk = false;
                        return;
                        break;
                    }
                }
                else if (wait.WaitType == (int)Wait_Type.Time_3)
                {
                    wait.IsEnd = (span.TotalMilliseconds >= wait.TimeMSeconds);
                }
                else if (wait.WaitType == (int)Wait_Type.WaitHeight_7)
                {
                    //wait.IsEnd = (wait.HeightValue.Equals(GetHeight())); 
                }
                else if (wait.WaitType == (int)Wait_Type.TakeTrayGo_12)
                {
                    wait.IsEnd = AutomaticBaiting.IsGetTrayGo;
                }
                else if (wait.WaitType == (int)Wait_Type.BatchAxisMove_10)
                {
                    if (!wait.IsEnd)
                    {
                        wait.IsEnd = AutomaticBaiting.BatchAxisIsEnd(wait, span);
                    }
                    //if (!wait.IsEnd)
                    //{
                    //    bool MoveEnd = ACServerManager.GetBusyStatus(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue()).Equals(0);
                    //    int outCount = ACServerManager.GetActualtPosition(wait.AxisInfo.DeviceName, wait.AxisInfo.GetAxisValue());
                    //    int errorCount = Math.Abs(outCount - wait.TargetPosition);
                    //    if (MoveEnd && errorCount < wait.AxisInfo.CanErrorCountMax)
                    //    {
                    //        wait.IsEnd = true;
                    //    }
                    //}
                    if (wait.IsEnd)
                    {
                        BatchAxisController.StopCheck();
                    }
                }
                else if (wait.WaitType == (int)Wait_Type.ShuoKe_5)
                {
                    //string msg = "";
                    //wait.IsEnd = ShuoKeIsEnd(wait, out msg);
                    //NotOkMsg = NotOkMsg + " " + msg;
                }
                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)
            {
                string p1 = "[" + StoreMove.MoveStep + "]";
                string p2 = "[" + NotOkMsg + "]";
                string p3 = "[" + Math.Round(span.TotalSeconds, 1) + "]";
                string msg = ResourceControl.GetString(ResourceControl.MoveTimeOut, p1 + ResourceControl.GetString(ResourceControl.TimeOut, "超时") + p2 + p3, p1, p2, p3);
                string newType = ResourceControl.MoveTimeOut;
                SetWaitWarnMsg(msg, newType, p1, p2, p3);
                LogUtil.error(WarnObj.WarnMsg, 15);
                Alarm(StoreAlarmType.IoSingleTimeOut, "", WarnObj.WarnMsg, StoreMove.MoveType);
            }
        }

        #endregion

        #region 入库
        private Stopwatch InOutWatch = new Stopwatch();

        /// <summary>
        /// 开始入库移动移动
        /// </summary>
        /// <param name="param">入库参数</param>
        /// <param name="IsBatchWork">是否批量出库</param>
        /// <param name="isNeedInStore">是否需要入库,不需要入库时直接等待拿走料盘</param>
        /// <returns></returns>
        public bool StartInStoreMove(InOutStoreParam param, bool IsBatchWork = true, bool isNeedInStore = true)
        {
            InOutWatch.Restart();
            string posId = param != null ? param.PositionNum : "";
            string logMsg = IsBatchWork ? " 启动批量入库【" + posId + "】" : "  启动入库【" + posId + "】";
            if (!AutomaticBaiting.DoorCloseOK())
            {
                UpdateInOutMsg(logMsg + "失败,门锁未关闭");
                return false;
            }
            if (IsBatchWork && (!SupportBatch(posId)))
            {
                UpdateInOutMsg(logMsg + "失败,此库位不支持批量操作");
                return false;
            }
            if (storeRunStatus == StoreRunStatus.Runing)
            {
                if (!LoadParamPosition(param))
                {
                    UpdateInOutMsg(logMsg + "失败,找不到库位信息");
                    return false;
                }
                if (IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
                {
                    UpdateInOutMsg(logMsg + "失败,叉子料盘检测有料");
                    return false;
                }
                LogUtil.info(LOGGER, StoreName + logMsg);
                storeRunStatus = StoreRunStatus.Busy;
                storeStatus = StoreStatus.InStoreExecute;
                StoreMove.NewMove(StoreMoveType.InStore, param);
                //lastMoveType = StoreMoveType.InStore;
                StoreMove.IsBatchInOutStore = IsBatchWork;
                StoreMove.IsNeedInStore = isNeedInStore;
                if (IsHasCompress_Axis || Config.IsHasLocationCylinder.Equals(0))
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SI_01_LocationCylinderDown);
                }
                else
                {
                    InStoreLog("入库:SI_01   定位气缸下降");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_01_LocationCylinderDown);
                    //LocationDownAndWait();
                }
                return true;
            }
            else
            {
                UpdateInOutMsg(logMsg + "失败,当前状态:" + storeRunStatus);
                return false;
            }
        }
        private void SI_03_AxisToP1(LineMoveP moveP)
        {
            InStoreLog($"入库:SI_03    所有轴回待机点,轴2({moveP.UpDown_P1})、轴1({moveP.Middle_P1}) 到P1, 轴4({moveP.ComPress_P3})到P3,吸盘在上升端");
            StoreMove.NextMoveStep(StoreMoveStep.SI_03_ReturnHome);
            bool needMove = false;
            if (!ACServerManager.isInPosition(Config.Comp_Axis, moveP.ComPress_P3))
            {
                needMove = true;
                ComMoveToPosition(moveP.ComPress_P3, Config.CompAxis_P3_Speed);
            }
            if (!ACServerManager.isInPosition(Config.UpDown_Axis, moveP.UpDown_P1))
            {
                needMove = true;
                ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P1, Config.UpDownAxis_P1_Speed);
            }
            if (!ACServerManager.isInPosition(Config.Middle_Axis, moveP.Middle_P1))
            {
                needMove = true;
                ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
            }
            StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampingDisc_Up, IO_VALUE.HIGH));
            StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampingDisc_Down, IO_VALUE.LOW));
            //如果不需要回待机点,直接到下一个步骤
            if (!needMove && IOManager.IOValue(IO_Type.ClampingDisc_Down).Equals(IO_VALUE.LOW) && IOManager.IOValue(IO_Type.ClampingDisc_Up).Equals(IO_VALUE.HIGH))
            {
                SI_04_DeviceToDoor();
            }
        }
        private void SI_02_Move(LineMoveP moveP)
        {
            InStoreLog($"入库:SI_02_  进出轴至P1({moveP.InOut_P1})");
            StoreMove.NextMoveStep(StoreMoveStep.SI_02_InOutAxisHome);
            bool result = InOutBackToP1(moveP.InOut_P1);
            if (!result && StoreMove.IsBatchInOutStore.Equals(true))
            {
                SI_03_AxisToP1(moveP);
            }
        }
        private void SI_04_DeviceToDoor()
        {
            InStoreLog($"入库:SI_04  叉子进入入料口,进出轴至P2({StoreMove.MoveParam.MoveP.InOut_P2}) ");
            StoreMove.NextMoveStep(StoreMoveStep.SI_04_DeviceToDoor);
            ACAxisMove(Config.InOut_Axis, StoreMove.MoveParam.MoveP.InOut_P2, Config.InOutAxis_P2_Speed);
        }
        protected override void InStoreProcess()
        {
            if (StoreMove.IsInWait)
            {
                CheckWait();
            }
            if (StoreMove.IsInWait)
            {
                return;
            }
            LineMoveP moveP = StoreMove.MoveParam.MoveP;
            if (StoreMove.MoveStep >= StoreMoveStep.SIS_31_ToDoor)
            {
                SingleInStoreProcess();
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_01_LocationCylinderDown)
            {
                SI_02_Move(moveP);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_02_InOutAxisHome)
            {
                if (StoreMove.IsBatchInOutStore)
                {
                    SI_03_AxisToP1(moveP);
                }
                else
                {
                    int updownPosition = moveP.UpDown_Door_P7 - Config.UpdownAxis_UpPosition;
                    InStoreLog("入库:SIS_31  单盘入库:旋转轴待机点P1,升降轴走到仓门位置P7下方位置  " + updownPosition);
                    StoreMove.NextMoveStep(StoreMoveStep.SIS_31_ToDoor);
                    ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
                    ACAxisMove(Config.UpDown_Axis, updownPosition, Config.UpDownAxis_P7_Speed);
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_03_ReturnHome)
            {
                SI_04_DeviceToDoor();
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_04_DeviceToDoor)
            {
                InStoreLog($"入库:SI_05  等待吸盘放下物品");
                InStoreLog(StoreManager.GetAllAxisPos());
                StoreMove.NextMoveStep(StoreMoveStep.SI_05_DoorWarToDevice);
                //  IOManager.IOMove(IO_Type.SuckingDisc_Work, IO_VALUE.LOW);
                //  StoreMove.WaitList.Add(WaitResultInfo.WaitTime(1000));
                // StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SuckingDisc_Air, IO_VALUE.LOW));

                AutomaticBaiting.CylinderMove(IO_Type.Clamping_Work, IO_Type.Clamping_Relax, StoreMove);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_05_DoorWarToDevice)
            {
                if (!StoreMove.IsNeedInStore)
                {
                    InStoreLog("送出料盘:SI_21 ,升降轴到门口位置P7 ");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_21_DeviceToDoor);
                    ACAxisMove(Config.UpDown_Axis, moveP.UpDown_Door_P7, Config.UpDownAxis_P7_Speed);
                }
                else
                {
                    if (IsHasCompress_Axis)
                    {
                        int targetPosition = moveP.UpDown_P1 - Config.UpDownAxis_DownValue;
                        InStoreLog("入库:SI_06 压紧轴压紧,压紧轴到P2,升降轴下降【" + Config.UpDownAxis_DownValue + "】目标【" + targetPosition + "】 ");
                        StoreMove.NextMoveStep(StoreMoveStep.SI_06_CompressWork);
                        ComMoveToPosition(moveP.ComPress_P2, Config.CompAxis_P2_Speed);
                        ACAxisMove(Config.UpDown_Axis, targetPosition, Config.UpDownAxis_P4_Speed);
                    }
                    else
                    {
                        InStoreLog("入库:SI_07  叉子返回,进出轴至P1,检测料仓料盘检测信号 ");
                        StoreMove.NextMoveStep(StoreMoveStep.SI_07_InoutToP1);
                        InOutBackToP1(moveP.InOut_P1);
                        StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.HIGH));
                    }
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_06_CompressWork)
            {
                InStoreLog("入库:SI_07  叉子返回,进出轴至P1 ");
                StoreMove.NextMoveStep(StoreMoveStep.SI_07_InoutToP1);
                InOutBackToP1(moveP.InOut_P1);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_07_InoutToP1)
            {
                if (Config.IsUse_Tray_Check.Equals(1))
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SI_071_CheckFixture);
                    InStoreLog("入库:SI_071_CheckFixture 进出轴到P1后,判断是否拿到物料 ");
                    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.HIGH));
                }
                else
                {
                    if (IsHasCompress_Axis || Config.IsHasLocationCylinder.Equals(0))
                    {
                        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);
                    }
                    else
                    {
                        InStoreLog("入库:SI_08  定位气缸伸出 ");
                        StoreMove.NextMoveStep(StoreMoveStep.SI_08_LocationCylinder_Up);
                        //LocationUpAndWait();
                    }
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_071_CheckFixture)
            {
                if (IsHasCompress_Axis || Config.IsHasLocationCylinder.Equals(0))
                {
                    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);
                }
                else
                {
                    InStoreLog("入库:SI_08  定位气缸伸出 ");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_08_LocationCylinder_Up);
                    //LocationUpAndWait();
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_08_LocationCylinder_Up)
            {
                InStoreLog("入库:SI_09  移动到库位点,旋转轴至P2(库位点),升降轴至P3(库位入库前点))  ");
                StoreMove.NextMoveStep(StoreMoveStep.SI_09_MoveToBag);
                ACAxisMove(Config.Middle_Axis, moveP.Middle_P2, Config.MiddleAxis_P1_Speed);
                ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P3, Config.UpDownAxis_P3_Speed);
            }
            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)
            {
                InStoreLog("入库:SI_12  放下物品,升降轴至P4(库位入料缓冲点),压紧轴至P3(压紧前点) ");
                // 5= 入仓位完成(料仓Box把料盘放入对应的库位中,装置还未恢复原始状态)   
                string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
                lastPosId = posId;
                lastPosIdStatus = StoreStatus.InStoreEnd;
                storeStatus = StoreStatus.InStoreEnd;
                //手动发给服务器状态,防止没有手动 
                //Task.Factory.StartNew(delegate { SendLineStatus(); });

                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);
                Thread.Sleep(100);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_12_PutWareToBag)
            {
                InStoreLog("入库:SI_13  叉子从库位返回,进出轴至P1(待机点) ");

                StoreMove.NextMoveStep(StoreMoveStep.SI_13_InoutBack);
                InOutBackToP1(moveP.InOut_P1);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_13_InoutBack)
            {
                InStoreLog("入库:SI_14  返回待机点,轴2/轴1到P1,轴4到P3");
                StoreMove.NextMoveStep(StoreMoveStep.SI_14_GoBack);
                ComMoveToPosition(moveP.ComPress_P3, Config.CompAxis_P3_Speed);
                ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
                ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P1, Config.UpDownAxis_P1_Speed);
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_14_GoBack)
            {
                preProTime = DateTime.Now.AddSeconds(-5);
                string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
                LogUtil.info(LOGGER, "  【" + posId + "】 入库结束,耗时【" + FormUtil.GetSpanStr(InOutWatch.Elapsed) + "】!");
                StoreMove.EndMove();
                storeRunStatus = StoreRunStatus.Runing;
                //设备连接,入库后,BOX恢复原始状态 
                storeStatus = StoreStatus.StoreOnline;
                InOutEndProcess(StoreMoveType.InStore);
            }
            #region 送出料盘处理
            else if (StoreMove.MoveStep == StoreMoveStep.SI_21_DeviceToDoor)
            {
                InStoreLog("送出料盘:SI_21 ,进出轴到仓门出料点P4 ");
                StoreMove.NextMoveStep(StoreMoveStep.SI_22_InoutToDoor);
                ACAxisMove(Config.InOut_Axis, moveP.InOut_P4, Config.InOutAxis_P2_Speed);
                StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SafetyLightCurtains, IO_VALUE.HIGH));

            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SI_22_InoutToDoor))
            {
                InStoreLog("送出料盘:SI_22 ,压紧轴到压紧前点 ");
                StoreMove.NextMoveStep(StoreMoveStep.SI_23_ComToP3);
                ComMoveToPosition(moveP.ComPress_P3, Config.CompAxis_P3_Speed);
                //if (IOManager.IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.HIGH))
                //{
                //    InStoreLog("送出料盘:SI_22 ,打开仓门 ");
                //    StoreMove.NextMoveStep(StoreMoveStep.SI_24_OpenDoor);
                //    OpenDoorAndWait();
                //}
            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SI_23_ComToP3))
            {
                if (IOManager.IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.HIGH))
                {
                    InStoreLog("送出料盘:SI_23 ,打开仓门 ");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_24_OpenDoor);
                    OpenDoorAndWait();
                }
            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SI_24_OpenDoor))
            {
                InStoreLog("送出料盘:SI_24 ,等待操作人员拿走料盘 ");
                StoreMove.NextMoveStep(StoreMoveStep.SI_25_WaitTrayGo);
                StoreMove.TimeOutSeconds = 120;
                AutomaticBaiting.IsGetTrayGo = false;
                AutomaticBaiting.IsWaitTragGo = true;
                StoreMove.WaitList.Add(WaitResultInfo.WaitTakeTray());
                AutomaticBaiting.WaitIoValue = IO_VALUE.LOW;
                StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Door, IO_VALUE.LOW));
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SI_25_WaitTrayGo)
            {
                if (IOManager.IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.HIGH))
                {
                    InStoreLog("送出料盘:SI_13  叉子从库位返回,进出轴到P1(待机点) ");
                    CodeOrInoutMsg = "";
                    // 5= 入仓位完成(料仓Box把料盘放入对应的库位中,装置还未恢复原始状态)   
                    string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
                    lastPosId = "";
                    lastPosIdStatus = StoreStatus.InStoreEnd;
                    storeStatus = StoreStatus.InStoreEnd;
                    StoreMove.NextMoveStep(StoreMoveStep.SI_13_InoutBack);
                    InOutBackToP1(moveP.InOut_P1);
                    CloseDoorAndWait();
                }
            }

            #endregion
            else
            {
                LogUtil.info(LOGGER, StoreName + " 入库,moveStatus=" + StoreMove.MoveStep + ",没有对应的处理!");
            }
        }

        protected void SingleInStoreProcess()
        {
            LineMoveP moveP = StoreMove.MoveParam.MoveP;
            if (StoreMove.MoveStep.Equals(StoreMoveStep.SIS_31_ToDoor))
            {
                InStoreLog("入库:SIS_32  单盘入库:叉子走到门口位置P4, 打开仓门 ,压紧轴到P3");
                StoreMove.NextMoveStep(StoreMoveStep.SIS_32_InoutToDoor);
                ACAxisMove(Config.InOut_Axis, moveP.InOut_P4, Config.InOutAxis_P2_Speed);
                ComMoveToPosition(moveP.ComPress_P3, Config.CompAxis_P3_Speed);
                OpenDoorAndWait();
            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SIS_32_InoutToDoor))
            {
                InStoreLog("入库:SIS_33 等待操作人员放入料盘  ");
                StoreMove.NextMoveStep(StoreMoveStep.SIS_33_WaitTray);
                StoreMove.TimeOutSeconds = 120;
                AutomaticBaiting.IsGetTrayGo = false;
                AutomaticBaiting.IsWaitTragGo = true;
                StoreMove.WaitList.Add(WaitResultInfo.WaitTakeTray());
                AutomaticBaiting.WaitIoValue = IO_VALUE.HIGH;
                // StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Door, IO_VALUE.HIGH));
            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SIS_33_WaitTray))
            {
                //判断是否放入料盘
                if (IOManager.IOValue(IO_Type.TrayCheck_Door).Equals(IO_VALUE.LOW))
                {
                    InStoreLog("入库:SI_13  单盘入库未放入料盘,关闭仓门,进出轴至P1(待机点) ");
                    StoreMove.NextMoveStep(StoreMoveStep.SI_13_InoutBack);
                    CloseDoorAndWait();
                    InOutBackToP1(moveP.InOut_P1);
                }
                else
                {
                    InStoreLog("入库:SIS_34  确认放入料盘,关闭仓门,升降轴走门口P7,压紧轴压紧  ");
                    StoreMove.NextMoveStep(StoreMoveStep.SIS_34_GetTray);
                    CloseDoorAndWait();
                    ACAxisMove(Config.UpDown_Axis, Config.UpDownAxis_Door_P7, Config.UpDownAxis_P4_Speed);
                    ComMoveToPosition(moveP.ComPress_P2, Config.CompAxis_P2_Speed);
                }
            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SIS_34_GetTray))
            {
                InStoreLog("入库:SIS_35  确认放入料盘,关闭仓门,进出轴后退到P1  ");
                StoreMove.NextMoveStep(StoreMoveStep.SIS_35_InoutBack);
                ACAxisMove(Config.InOut_Axis, moveP.InOut_P1, Config.InOutAxis_P1_Speed);
            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SIS_35_InoutBack))
            {
                InStoreLog("入库:SIS_36  升降轴下降到扫码位置P2  ");
                StoreMove.NextMoveStep(StoreMoveStep.SIS_36_UpdownDown);
                ACAxisMove(Config.UpDown_Axis, moveP.UpDown_OutHigh_P2, Config.UpDownAxis_P2_Speed);
            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SIS_36_UpdownDown))
            {
                InStoreLog("入库:SIS_37  轴3( 叉子) 至P2( 进料口取料点)  ");
                StoreMove.NextMoveStep(StoreMoveStep.SIS_37_InoutToP2);
                ACAxisMove(Config.InOut_Axis, moveP.InOut_P2, Config.InOutAxis_P2_Speed);
            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SIS_37_InoutToP2))
            {
                InStoreLog("入库:SIS_38 ,清理扫码信息,开始扫码,最多等待6000  ");
                AutomaticBaiting.ClearInStoreInfo();
                StoreMove.NextMoveStep(StoreMoveStep.SIS_38_ScanCode);
                StoreMove.WaitList.Add(WaitResultInfo.WaitCodeOK());
                StoreMove.WaitList.Add(WaitResultInfo.WaitTime(9000));
                StoreMove.OneWaitCanEndStep = true;
                AutomaticBaiting.GetCameraCode();
            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SIS_38_ScanCode))
            {
                if (AutomaticBaiting.LastCode.Equals(""))
                {
                    SingleSendOut("未扫到二维码");
                }
                else
                {
                    InStoreLog("入库:SIS_39  获取入库库位号  ");
                    StoreMove.NextMoveStep(StoreMoveStep.SIS_39_GetPosId);
                    StoreMove.WaitList.Add(WaitResultInfo.WaitTime(10000));//最多等待十秒
                    InOutStoreParam param = AutomaticBaiting.GetInStoreParam("单盘入库", AutomaticBaiting.ProcessMsg());
                    if (param == null)
                    {
                        SingleSendOut("从服务器获取入库信息失败");
                    }
                    else if (!LoadParamPosition(param))
                    {
                        SingleSendOut("加载入库" + param.PositionNum + "参数失败");
                    }
                    else
                    {
                        //更改当前入库参数  
                        storeRunStatus = StoreRunStatus.Busy;
                        storeStatus = StoreStatus.InStoreExecute;
                        StoreMove.MoveParam = param;
                        moveP = StoreMove.MoveParam.MoveP;
                        //lastMoveType = StoreMoveType.InStore;
                        StoreMove.IsBatchInOutStore = true;
                        StoreMove.IsNeedInStore = true;

                        LogUtil.info("单盘入库获取库位号成功:" + param.ToStr() + ",叉子后退,压紧轴压紧[" + moveP.ComPress_P2 + "],开始入库");
                        StoreMove.NextMoveStep(StoreMoveStep.SI_07_InoutToP1);
                        ACAxisMove(Config.InOut_Axis, moveP.InOut_P1, Config.InOutAxis_P1_Position);
                        ComMoveToPosition(moveP.ComPress_P2, Config.CompAxis_P2_Speed);
                    }
                }
            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SIS_39_GetPosId))
            {
                SingleSendOut("启动入库超时 ");
            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SIS_40_StartInStore))
            {
                InStoreLog("入库:SIS_41  开始送出料盘 ,叉子后退 ");
                StoreMove.NextMoveStep(StoreMoveStep.SIS_41_StartSendTrayOut);
                ACAxisMove(Config.InOut_Axis, moveP.InOut_P1, Config.InOutAxis_P1_Position);
            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SIS_41_StartSendTrayOut))
            {
                StoreMove.IsNeedInStore = false;
                InStoreLog("送出料盘:SI_21 ,升降轴到门口位置P7 ");
                StoreMove.NextMoveStep(StoreMoveStep.SI_21_DeviceToDoor);
                ACAxisMove(Config.UpDown_Axis, moveP.UpDown_Door_P7, Config.UpDownAxis_P7_Speed);
            }
        }

        private void SingleSendOut(string msg)
        {
            StoreMove.IsBatchInOutStore = true;
            StoreMove.IsNeedInStore = false;
            InStoreLog(msg + ",将料盘送出,叉子后退");
            StoreMove.NextMoveStep(StoreMoveStep.SIS_41_StartSendTrayOut);
            ACAxisMove(Config.InOut_Axis, StoreMove.MoveParam.MoveP.InOut_P1, Config.InOutAxis_P1_Position);
        }


        #endregion


        #region 出库 
        /// <summary>
        /// 开始出库运动
        /// </summary> 
        public bool StartOutStoreMove(InOutStoreParam param, bool IsBatchWork)
        {
            InOutWatch.Restart();
            string posId = param != null ? param.PositionNum : "";
            string logMsg = IsBatchWork ? " 启动批量出库【" + posId + "】" : "  启动出库【" + posId + "】";
            if (!AutomaticBaiting.DoorCloseOK())
            {
                UpdateInOutMsg(logMsg + "失败,门锁未关闭");
                //LogUtil.error(LOGGER, StoreName + logMsg + " 出错,门锁未关闭");
                return false;
            }
            if (IsBatchWork && (!SupportBatch(posId)))
            {
                UpdateInOutMsg(logMsg + "失败,此库位不支持批量操作");
                return false;
            }
            if (storeRunStatus == StoreRunStatus.Runing)
            {
                if (!LoadParamPosition(param))
                {
                    UpdateInOutMsg(logMsg + "失败,找不到库位信息");
                    return false;
                }
                if (IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
                {
                    UpdateInOutMsg(logMsg + "失败,叉子料盘检测有料");
                    return false;
                }
                //若自动上料机构正在入库中,不可以出库
                if (!AutomaticBaiting.AutoBaitingStatus.Equals(StoreRunStatus.Runing))
                {
                    UpdateInOutMsg(logMsg + "失败,批量上下料机构不在空闲中");
                    return false;
                }
                //判断批量上下料机构是否已经满 
                if (IOManager.IOValue(IO_Type.TrayCheck_LoadMaterial).Equals(IO_VALUE.HIGH) && IsBatchWork)
                {
                    int currBatchValue = ACServerManager.GetActualtPosition(Config.Batch_Axis.DeviceName, Config.Batch_Axis.GetAxisValue());
                    if (currBatchValue - param.MoveP.BatchAxis_DownValue < 1000)
                    {
                        UpdateInOutMsg(logMsg + "失败,批量上下料机构已满,请先拿出料盘");
                        return false;
                    }
                }
                int height = param.GetPosition().BagHeight;
                if (AutomaticBaiting.BatchOutStoreHeight >= Config.BatchAxis_MaxHeight)
                {
                    LogUtil.error(LOGGER, StoreName + logMsg + " 出错,当前高【" + AutomaticBaiting.BatchOutStoreHeight + "】出库料盘高【" + height + "】,最大高【" + Config.BatchAxis_MaxHeight + "】");
                    UpdateInOutMsg(logMsg + "失败,批量上下料机构已满,请先拿出料盘");
                    return false;
                }

                storeStatus = StoreStatus.OutStoreExecute;
                LogUtil.info(LOGGER, StoreName + logMsg);
                storeRunStatus = StoreRunStatus.Busy;
                StoreMove.NewMove(StoreMoveType.OutStore, param);
                //lastMoveType = StoreMoveType.OutStore;
                StoreMove.IsBatchInOutStore = IsBatchWork;
                if (IsHasCompress_Axis || Config.IsHasLocationCylinder.Equals(0))
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_01_LocationCylinderDown);
                    //SO_02_DeviceBack();
                }
                else
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_01_LocationCylinderDown);
                    OutStoreLog("出库:SO_01 定位气缸下降");
                    //LocationDownAndWait();
                }
                CodeOrInoutMsg = "";
                return true;
            }
            else
            {
                UpdateInOutMsg(logMsg + "失败,当前状态:" + storeRunStatus);
                //LogUtil.error(LOGGER, StoreName + logMsg+ "出错,当前storeStatus=" + storeRunStatus);
                return false;
            }
        }
        protected override void OutStoreProcess()
        {
            LineMoveP moveP = StoreMove.MoveParam.MoveP;
            if (StoreMove.IsInWait)
            {
                CheckWait();
            }
            if (StoreMove.IsInWait)
            {
                return;
            }
            if (StoreMove.MoveStep == StoreMoveStep.SO_01_LocationCylinderDown)
            {
                SO_02_DeviceBack();
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_02_DeviceBack)
            {
                StoreMove.NextMoveStep(StoreMoveStep.SO_03_ToBagPosition);
                bool BatchNeedMove = false;
                int targetValue = -1;
                int outDownPosition = StoreMove.MoveParam.MoveP.BatchAxis_DownValue;

                if (StoreMove.IsBatchInOutStore)
                {  //如果料盘检测信号不亮,不需要下降这么多
                   //判断是否在P1点 
                    int acPosition = ACServerManager.GetActualtPosition(Config.Batch_Axis);
                    bool isIn = Math.Abs(acPosition - Config.BatchAxis_P1) < Config.Batch_Axis.CanErrorCountMax;
                    if (IOManager.IOValue(IO_Type.TrayCheck_LoadMaterial).Equals(IO_VALUE.LOW) && outDownPosition > Config.BatchAxis_OutDownPosition && isIn)
                    {
                        outDownPosition = outDownPosition - Config.BatchAxis_OutDownPosition;
                    }
                    //如果检测信号亮,需要多下降
                    if (IOManager.IOValue(IO_Type.TrayCheck_LoadMaterial).Equals(IO_VALUE.HIGH))
                    {
                        outDownPosition = outDownPosition + Config.BatchAxis_DownPosition2;
                    }
                    //上下料机构下降的距离=料盘最低高度+默认的高度 
                    targetValue = GetBatchTargetValue(outDownPosition);
                    if (targetValue >= 1000)
                    {
                        BatchNeedMove = true;
                    }
                    else
                    {
                        AutomaticBaiting.BatchOutStoreCount++;
                        AutomaticBaiting.BatchOutStoreHeight = 1000;
                        OutStoreLog("出库:SO_03批量上下料轴需下降【" + outDownPosition + "】目标【" + targetValue + "】,实时位置【" + ACServerManager.GetActualtPosition(StoreManager.Config.Batch_Axis) + "】 ,请检查料盘是否已满");
                        //停止出库
                        string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
                        storeStatus = StoreStatus.StoreOnline;
                        LogUtil.error(LOGGER, StoreName + " 【" + posId + "】 出库中断,请检查料盘是否已满,耗时【" + FormUtil.GetSpanStr(InOutWatch.Elapsed) + "】!");
                        StoreMove.EndMove();
                        storeRunStatus = StoreRunStatus.Runing;
                        InOutEndProcess(StoreMoveType.OutStore);
                        return;
                    }
                }
                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);
                Thread.Sleep(100);
                if (BatchNeedMove)
                {
                    StoreMove.TimeOutSeconds = 120;
                    Thread.Sleep(1000);
                    ACAxisMove(Config.Batch_Axis, targetValue, Config.BatchAxis_P1_Speed);
                    OutStoreLog("出库:SO_03  批量轴下降【" + outDownPosition + "】目标【" + targetValue + "】 ");
                    Thread.Sleep(100);
                }
            }
            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)
            {
                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;
                //手动发给服务器状态,防止没有手动
                //Task.Factory.StartNew(delegate { SendLineStatus(); }); 
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_06_BagDeviceBack)
            {
                if (IOManager.IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.LOW))
                {
                    string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
                    LogUtil.error("出库【" + posId + "】取料完成后,未检测到叉子料盘信号 ");
                }
                if (IsHasCompress_Axis || Config.IsHasLocationCylinder.Equals(0))
                {
                    SO_08_ToDoorPosition();
                }
                else
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_07_LocationCylinder_Up);
                    OutStoreLog("出库:SO_07 定位气缸伸出 ");
                    //LocationUpAndWait();
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_07_LocationCylinder_Up)
            {
                SO_08_ToDoorPosition();
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_08_ToDoorPosition)
            {
                if (Config.IsUse_Tray_Check.Equals(1))
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_09_CheckFixture);
                    OutStoreLog("出库:SO_09_CheckFixture  等待叉子料盘检测信号");
                    StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Fixture, IO_VALUE.HIGH));
                }
                else
                {
                    if (IsHasCompress_Axis || Config.IsHasLocationCylinder.Equals(0))
                    {
                        SO_11_DeviceToDoorPro();
                    }
                    else
                    {
                        StoreMove.NextMoveStep(StoreMoveStep.SO_10_LocationCylinder_Down);
                        OutStoreLog("出库:SO_10 定位气缸退回   ");
                        //LocationDownAndWait();
                    }
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_09_CheckFixture)
            {
                if (IsHasCompress_Axis || Config.IsHasLocationCylinder.Equals(0))
                {
                    SO_11_DeviceToDoorPro();
                }
                else
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_10_LocationCylinder_Down);
                    OutStoreLog("出库:SO_10 定位气缸退回   ");
                    //LocationDownAndWait();
                }
            }
            //此处需要等待移栽没有工作,才能把盘放入出料口
            else if (StoreMove.MoveStep == StoreMoveStep.SO_10_LocationCylinder_Down)
            {
                SO_11_DeviceToDoorPro();
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_11_DeviceToDoor)
            {
                if (StoreMove.IsBatchInOutStore)
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_12_PutTray);
                    OutStoreLog("出库:SO_12_PutTray  放下料盘,升降轴到P8(出库低点),压紧轴至P3(压紧前点)");
                    ComMoveToPosition(StoreMove.MoveParam.MoveP.ComPress_P3, Config.CompAxis_P3_Speed);
                    ACAxisMove(Config.UpDown_Axis, StoreMove.MoveParam.MoveP.UpDown_OutLow_P8, Config.UpDownAxis_P8_Speed);
                    AutomaticBaiting.BatchOutStoreHeight += StoreMove.MoveParam.PlateH;
                    AutomaticBaiting.BatchOutStoreCount++;
                    Thread.Sleep(100);
                }
                else if (IOManager.IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.HIGH))
                {
                    StoreMove.NextMoveStep(StoreMoveStep.SO_21_OpenDoor);
                    OutStoreLog("出库:SO_21打开仓门,压紧轴至P3(压紧前点),定位气缸下降");
                    ComMoveToPosition(StoreMove.MoveParam.MoveP.ComPress_P3, Config.CompAxis_P3_Speed);
                    OpenDoorAndWait();
                    //LocationDownAndWait();
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_21_OpenDoor)
            {
                StoreMove.NextMoveStep(StoreMoveStep.SO_22_WaitTrayGo);
                OutStoreLog("出库:SO_22  等待操作人员拿走料盘 ");
                StoreMove.TimeOutSeconds = 120;
                AutomaticBaiting.IsWaitTragGo = true;
                AutomaticBaiting.IsGetTrayGo = false;
                StoreMove.WaitList.Add(WaitResultInfo.WaitTakeTray());
                //需要检测是否已拿走
                AutomaticBaiting.WaitIoValue = IO_VALUE.LOW;
                StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.TrayCheck_Door, IO_VALUE.LOW));
            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SO_22_WaitTrayGo))
            {
                if (IOManager.IOValue(IO_Type.SafetyLightCurtains).Equals(IO_VALUE.HIGH))
                {
                    SO_13_InoutBack();
                    CloseDoorAndWait();
                }
            }
            else if (StoreMove.MoveStep == StoreMoveStep.SO_12_PutTray)
            {
                SO_13_InoutBack();
            }
            else if (StoreMove.MoveStep.Equals(StoreMoveStep.SO_13_InoutBack))
            {
                string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
                storeStatus = StoreStatus.StoreOnline;
                LogUtil.info(LOGGER, "【" + posId + "】出库结束,耗时【" + FormUtil.GetSpanStr(InOutWatch.Elapsed) + "】累积出库: " + AutomaticBaiting.BatchOutStoreCount + "盘共" + AutomaticBaiting.BatchOutStoreHeight + "mm");
                StoreMove.EndMove();
                storeRunStatus = StoreRunStatus.Runing;
                InOutEndProcess(StoreMoveType.OutStore);
            }
            else
            {
                LogUtil.error(LOGGER, StoreName + " 出库 moveStatus=" + StoreMove.MoveStep + ",没有对应的处理!");
            }
        }
        private void SO_02_DeviceBack()
        {
            StoreMove.NextMoveStep(StoreMoveStep.SO_02_DeviceBack);
            OutStoreLog("出库:SO_02  叉子运动到P1 ");
            InOutBackToP1(StoreMove.MoveParam.MoveP.InOut_P1);
            if (StoreMove.IsBatchInOutStore)
            {

                //如果可以直接下降,则不需要匀速上升  
                int targetValue = GetBatchTargetValue(StoreMove.MoveParam.MoveP.BatchAxis_DownValue);
                if (targetValue >= 300000)
                {
                    OutStoreLog("出库:SO_02  批量上下料轴直接下降后目标位置【" + targetValue + "】不需要匀速上升 ");
                }
                //如果批量能未检测到料盘,需要把批量轴走到能检测到料盘的位置
                else if (IOManager.IOValue(IO_Type.TrayCheck_LoadMaterial).Equals(IO_VALUE.LOW))
                {
                    StoreMove.TimeOutSeconds = 120;
                    //ACAxisMove(Config.Batch_Axis, Config.BatchAxis_P1, Config.BatchAxis_P1_Speed);
                    StoreMove.WaitList.Add(WaitResultInfo.WaitBatchAxisStop(Config.Batch_Axis, Config.BatchAxis_P1, IO_Type.TrayCheck_LoadMaterial));
                    BatchAxisController.StartCheck(IO_Type.TrayCheck_LoadMaterial);
                    Config.Batch_Axis.TargetPosition = Config.BatchAxis_P1;
                    int speed = Config.BatchAxis_P1_Speed;
                    if (AutomaticBaiting.BatchOutStoreHeight > 0)
                    {
                        speed = Config.BatchAxis_SlowSpeed * 2;
                    }
                    ACServerManager.AbsMove(Config.Batch_Axis.DeviceName, Config.Batch_Axis.GetAxisValue(), Config.BatchAxis_P1, speed, Config.Batch_Axis.AddSpeed, Config.Batch_Axis.DelSpeed);
                    OutStoreLog("出库:SO_02  批量上下料轴到P1点【" + Config.BatchAxis_P1 + "】速度【" + speed + "】 ");
                }

                //第一盘料先上升盘高,若检测信号不亮,则可以出库
                //拿盘的同时 批量轴上升到检测信号亮,计算可用盘高=(位置-待机位)/系数
                //批量轴下降指定的高度,开始放盘

                //第二盘以后的料,若信号亮,先下降到信号不亮
                //信号不亮,批量轴下降指定的位置


            }
        }
        private int GetBatchTargetValue(int downValue)
        {
            int currPosition = ACServerManager.GetActualtPosition(StoreManager.Config.Batch_Axis);
            if (currPosition.Equals(-1))
            {
                currPosition = ACServerManager.GetActualtPosition(StoreManager.Config.Batch_Axis);
            }
            int targetValue = currPosition - downValue;
            return targetValue;
        }
        //private void BatchAxisUpTrayHeight()
        //{
        //    int targetValue = GetBatchTargetValue(StoreMove.MoveParam.MoveP.BatchAxis_DownValue);
        //    //记录高度
        //    AutomaticBaiting.BatchOutStoreCount++;
        //    AutomaticBaiting.BatchOutStoreHeight += StoreMove.MoveParam.GetACPosition().BagHeight;
        //    OutStoreLog(" 批量上下料轴下降【" + StoreMove.MoveParam.MoveP.BatchAxis_DownValue + "】,目标位置【" + targetValue + "】");
        //    //判断盘满后,需要报警? 
        //    if (targetValue <= 0)
        //    {
        //        //TODO
        //        WarnMsg = "库已满,请先拿走!";
        //    }
        //    else
        //    {
        //        ACAxisMove(StoreManager.Config.Batch_Axis, targetValue, StoreManager.Config.Batch_Axis.TargetSpeed);
        //    }
        //}
        private void SO_13_InoutBack()
        {
            StoreMove.NextMoveStep(StoreMoveStep.SO_13_InoutBack);
            OutStoreLog("出库:SO_13 叉子返回");
            ACAxisMove(Config.InOut_Axis, StoreMove.MoveParam.MoveP.InOut_P1, Config.InOutAxis_P1_Speed);
            if (IsHasCompress_Axis)
            {
                ComMoveToPosition(StoreMove.MoveParam.MoveP.ComPress_P3, Config.CompAxis_P3_Speed);
            }
        }
        /// <summary>
        /// 出库:SO_08 走到料门口,旋转轴至P1(待机点)升降轴至P2(进料口出料前点)
        /// </summary>
        private void SO_08_ToDoorPosition()
        {
            LineMoveP moveP = StoreMove.MoveParam.MoveP;
            StoreMove.NextMoveStep(StoreMoveStep.SO_08_ToDoorPosition);
            if (StoreMove.IsBatchInOutStore)
            {
                OutStoreLog("出库:SO_08 升降轴到出料高点P2,旋转轴至P1(待机点),等待吸盘处于上升端");
                ACAxisMove(Config.UpDown_Axis, moveP.UpDown_OutHigh_P2, Config.UpDownAxis_P2_Speed);
                ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
                //BatchAxisUpTrayHeight(); 
            }
            else
            {
                OutStoreLog("出库:SO_08 走到料门口,旋转轴至P1(待机点)升降轴至P2(进料口出料前点),等待吸盘处于上升端 ");
                ACAxisMove(Config.UpDown_Axis, moveP.UpDown_Door_P7, Config.UpDownAxis_P7_Speed);
                ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
            }
            //此处需要等待吸盘在上升位置
            IOManager.IOMove(IO_Type.ClampingDisc_Up, IO_VALUE.HIGH);
            IOManager.IOMove(IO_Type.ClampingDisc_Down, IO_VALUE.LOW);
            StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampingDisc_Up, IO_VALUE.HIGH));
            StoreMove.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.ClampingDisc_Down, IO_VALUE.LOW));
        }
        private void SO_11_DeviceToDoorPro()
        {
            LineMoveP moveP = StoreMove.MoveParam.MoveP;
            StoreMove.NextMoveStep(StoreMoveStep.SO_11_DeviceToDoor);
            if (StoreMove.IsBatchInOutStore)
            {
                OutStoreLog("出库:SO_11  叉子进出料口,进出轴至P2(进料口吸盘取料点) ");
                ACAxisMove(Config.InOut_Axis, moveP.InOut_P2, Config.InOutAxis_P2_Speed);
            }
            else
            {
                OutStoreLog("出库:SO_11  叉子进出料口,进出轴至P4(仓门出料点) ");
                ACAxisMove(Config.InOut_Axis, moveP.InOut_P4, Config.InOutAxis_P2_Speed);
            }
        }
        #endregion

        public bool SupportBatch(string posId)
        {
            AutoStorePosition position = CSVPositionReader<AutoStorePosition>.GetPositon(posId);
            if (position != null && position.SupportBatch.Equals(1))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public void UpdateInOutMsg(string Msg)
        {
            CodeOrInoutMsg = Msg;
            //WarnMsg = Msg;
            LogUtil.error(Msg);
        }
        public List<FixtureCodeInfo> waitOutStoreList = new List<FixtureCodeInfo>();
        public object waitOutListLock = "";

        public void AddWaitOutInfo(FixtureCodeInfo code)
        {
            lock (waitOutListLock)
            {//判断已经有此库位号的出库信息,直接抛弃不处理
                List<FixtureCodeInfo> list = (from m in waitOutStoreList where m.PosId.Equals(code.PosId) select m).ToList<FixtureCodeInfo>();
                if (list.Count > 0)
                {
                    LogUtil.info("【" + code.ToStr() + "】 加入等待队列失败,【" + code.PosId + "】已在出库队列中");
                }
                else
                {
                    waitOutStoreList.Add(code);
                }
            }
        }

        #region 自动出入库循环代码
        public string GetAutoPosid(bool isNext)
        {
            string posid = "";
            if (autoNext)
            {
                if (PositionNumList.Count > autoPositionIndex)
                {
                    posid = PositionNumList[autoPositionIndex];
                    autoMsg = ResourceControl.GetString("自动入库", "自动入库") + ":" + posid;
                    //到下一个库位
                    if (isNext)
                    {
                        int newIndex = autoPositionIndex - autoJiange;
                        if (newIndex < 0)
                        {
                            newIndex = AutoStartIndex;
                        }
                        autoPositionIndex = newIndex;
                    }
                }
            }
            return posid;
        }
        private void InOutEndProcess(StoreMoveType storeMoveType)
        {
            try
            {
                CurrInOutCount++;
                CurrInOutACount++;

                if (CycleOut && storeMoveType.Equals(StoreMoveType.OutStore))
                {
                    AutomaticBaiting.ClearOutStoreInfo();
                    FixtureCodeInfo currInOutFixture = new FixtureCodeInfo(0, "", CyclePosId);
                    AddWaitOutInfo(currInOutFixture);
                    LogUtil.info("循环出库结束,将库位号【" + currInOutFixture.ToStr() + "】加入出库等待中");
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(LOGGER, ex.ToString());
            }
        }
        #endregion

        private void InStoreLog(string msg)
        {
            string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
            string isBatchMsg = StoreMove.IsBatchInOutStore ? "批量" : "";
            LogUtil.info(LOGGER, isBatchMsg + "【" + posId + "】" + msg);
        }
        private void OutStoreLog(string msg)
        {
            string posId = StoreMove.MoveParam != null ? StoreMove.MoveParam.PositionNum : "";
            string isBatchMsg = StoreMove.IsBatchInOutStore ? "批量" : "";
            LogUtil.info(LOGGER, isBatchMsg + "【" + posId + "】" + msg);
        }


        #region 循环出入库功能
        public bool CycleOut = false;
        public string CyclePosId = "";
        #endregion
    }
}