FeedingEquip.cs 32.7 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
using Asa;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
    /// <summary>
    /// 流水线自动料仓-入料装置类
    /// </summary>
    public partial class FeedingEquip : EquipBase
    {
        public FeedingEquip_Config Config;
        public bool OutEndSendShelfOut = false;
        public string CurrShelfId = "";//当前的料架ID
        public AxisBean BatchAxis = null;
        public FeedingEquip(string cid, FeedingEquip_Config config)
        {
            this.DeviceID = config.Id;
            baseConfig = config;
            this.Config = config;
            IsDebug = config.IsDebug.Equals(1);
            Name = (" " + "_入料_" + DeviceID % 100 + " ").ToUpper();
            Init();
            UseAxis = true;
            Config.SetAxisParam();
            UpdownAxis = new AxisBean( config.UpDown_Axis,Name);
            BatchAxis = new AxisBean( config.Batch_Axis,Name);
            MoveInfo = new LineMoveInfo(DeviceID, "[" + Name.Trim() + "-Move]");
            SecondMoveInfo = new LineMoveInfo(DeviceID, "[" + Name.Trim() + "-SMove]");
        }


        /// <summary>
        /// 开始运行
        /// </summary>
        public override bool StartRun(bool isDebug = false)
        { 
            if (CanStartRun().Equals(false))
            {
                return false;
            }
            //if (isDebug)
            //{      //连接AGV调度
            //    if (!AgvClient.ISConnected())
            //    {
            //        AgvClient.Init();
            //    }
            //}
            if (IOValue(IO_Type.SL_SuddenStop_BTN).Equals(IO_VALUE.LOW))
            {
                SetWarnMsg(Name + "启动失败:急停未开");
                return false;
            }
            if (RunAxis(true, BatchAxis) && RunAxis(true, UpdownAxis))
            {
                mainTimer.Enabled = false;
                MoveInfo.EndMove();
                SecondMoveInfo.EndMove();
                lineStatus = LineStatus.StoreOnline;
                runStatus = LineRunStatus.HomeMoving;

                LogInfo("开始原点返回: ");
                MoveInfo.NewMove(LineMoveType.ReturnHome);

                StartReset();

                if (isDebug)
                {
                    LogInfo("开始调试,启动定时器 ");
                    mainTimer.Start();
                }
                return true;
            }
            return false;
        }
         
        public override bool Reset()
        {
            StopMove();
            if (RunAxis(true, BatchAxis) && RunAxis(true, UpdownAxis))
            {
                alarmType = LineAlarmType.None;
                LogInfo("开始重置: ");
                runStatus = LineRunStatus.Reset;
                MoveInfo.NewMove(LineMoveType.Reset);
                StartReset();
                return true;
            }
            return false;
        }

        private void StartReset()
        {
            if (OutStoreHeight > 0)
            {
                LogInfo("复位前,清理出库高度:" + OutStoreHeight);
            }

            OutStoreHeight = -1;
            //OutStoreCount = 0;
            BatchAxisStopCheck();
            ResetClearData();
            lineStatus = LineStatus.ResetMove;
            IOMove(IO_Type.SL_HddLed, IO_VALUE.HIGH);
            MoveInfo.NextMoveStep(LineMoveStep.FR_01_StopUp);

            IOMove(IO_Type.SL_Entry_StopDown, IO_VALUE.LOW);
            IOMove(IO_Type.SL_Buffer_StopDown, IO_VALUE.LOW);
            IOMove(IO_Type.SL_Out_StopDown, IO_VALUE.LOW);
            if (Config.SidesWayNum <= 0)
            {
                CheckAndMove(IO_Type.FL_StopCylinder_Down1, IO_VALUE.LOW);
                CheckAndMove(IO_Type.FL_StopCylinder_Down2, IO_VALUE.LOW);
                //顶升气缸下降
                CylinderMove(null, IO_Type.FL_TopCylinder_Up, IO_Type.FL_TopCylinder_Down);
            }
            else if (LineManager.Line.runStatus <= LineRunStatus.Wait)
            {
                CylinderMove(null, IO_Type.SW_LocationCylinder_Up, IO_Type.SW_LocationCylinder_Down);
                CylinderMove(null, IO_Type.SW_TopCylinder_Up, IO_Type.SW_TopCylinder_Down);
            }
            MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Entry_StopDown, IO_VALUE.LOW));
            MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Buffer_StopDown, IO_VALUE.LOW));
            MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Out_StopDown, IO_VALUE.LOW));
            isInPro = false;
        }
        //复位时,应该先提升伺服回原点,然后提升伺服下降到P2点,放开定位气缸,顶升气缸下降,提升伺服在上升到P1点。
        protected override void ResetProcess()
        {
            if (MoveInfo.IsInWait)
            {
                CheckWait(MoveInfo);
            }
            if (!MoveInfo.IsInWait)
            {
                switch (MoveInfo.MoveStep)
                {
                    case LineMoveStep.Wait:
                        StartReset();
                        break;
                    case LineMoveStep.FR_01_StopUp:
                        MoveInfo.NextMoveStep(LineMoveStep.FR_02_LineRun);
                        //阻挡上升
                        if (IOValue(IO_Type.SL_Location_Check).Equals(IO_VALUE.HIGH))
                        {
                            LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":开始复位,放料顶升下降, 所有阻挡上升,检测到定位工位有信号,不转动链条");
                        }
                        else
                        {
                            LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":开始复位,放料顶升下降, 所有阻挡上升,链条先转动3秒钟 ");
                            MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(3000));
                            //线体开始转动
                            IOMove(IO_Type.SL_Line_Run, IO_VALUE.HIGH);
                            IOMove(IO_Type.SL_LocationSideWay_Run, IO_VALUE.HIGH);
                            IOMove(IO_Type.SL_OutSideWay_Run, IO_VALUE.HIGH);
                            MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Location_Check, IO_VALUE.HIGH));
                            MoveInfo.OneWaitCanEndStep = true;
                        }
                        break;
                    case LineMoveStep.FR_02_LineRun:
                        MoveInfo.NextMoveStep(LineMoveStep.FR_03_CylinderUp);
                        LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":链条停止转动,上料横移机构上升,出口顶升下降,所有阻挡气缸上升");
                        //线体停止
                        IOMove(IO_Type.SL_Line_Run, IO_VALUE.LOW);
                        IOMove(IO_Type.SL_LocationSideWay_Run, IO_VALUE.LOW);
                        IOMove(IO_Type.SL_OutSideWay_Run, IO_VALUE.LOW);
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_Line_Run, IO_VALUE.LOW));
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_LocationSideWay_Run, IO_VALUE.LOW));
                        MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_OutSideWay_Run, IO_VALUE.LOW));
                        CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Down, IO_Type.SL_MoveCylinder_Up);
                        CylinderMove(MoveInfo, IO_Type.SL_OutTopCylinder_Up, IO_Type.SL_OutTopCylinder_Down);
                        if (Config.SidesWayNum <= 0)
                        {
                            //顶升气缸下降
                            CylinderMove(MoveInfo, IO_Type.FL_TopCylinder_Up, IO_Type.FL_TopCylinder_Down);
                        }
                        else if (LineManager.Line.runStatus <= LineRunStatus.Wait)
                        {
                            CylinderMove(MoveInfo, IO_Type.SW_LocationCylinder_Up, IO_Type.SW_LocationCylinder_Down);
                            CylinderMove(MoveInfo, IO_Type.SW_TopCylinder_Up, IO_Type.SW_TopCylinder_Down);
                        }
                        break;
                    case LineMoveStep.FR_03_CylinderUp: 
                        MoveInfo.NextMoveStep(LineMoveStep.FR_04_UpdownAxisHome); 
                        LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ": 升降伺服回原点"); 
                        UpdownAxis.HomeMove(MoveInfo);
                        break;

                    case LineMoveStep.FR_04_UpdownAxisHome:
                        MoveInfo.NextMoveStep(LineMoveStep.FR_05_UpdownAxis_P1);
                        LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ": 升降伺服到P1");
                        UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed); 
                        break;
                    case LineMoveStep.FR_05_UpdownAxis_P1:
                        if (MoveCylineCanTakeOrGive())
                        {

                            MoveInfo.NextMoveStep(LineMoveStep.FR_06_CylinderGive);
                            if (Config.IsCanOut.Equals(1))
                            {
                                LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ": 上料横移气缸取料端SOL");
                                CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Give, IO_Type.SL_MoveCylinder_Take);
                            }
                            else
                            {
                                LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ": 上料横移气缸放料端SOL");
                                CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Take, IO_Type.SL_MoveCylinder_Give);
                            }
                        }
                        else
                        {
                            MoveInfo.NextMoveStep(LineMoveStep.FR_05_UpdownAxis_P1);
                            LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":上料横移机构上升SOL");
                            CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Down, IO_Type.SL_MoveCylinder_Up);
                        }
                        break;
                    case LineMoveStep.FR_06_CylinderGive:
                        MoveInfo.NextMoveStep(LineMoveStep.FR_11_BatchAxisHome);
                        MoveInfo.TimeOutSeconds = 120;
                        LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":提升伺服回原点");
                        BatchAxis.HomeMove(MoveInfo);
                        break; 
                    case LineMoveStep.FR_11_BatchAxisHome:
                        MoveInfo.NextMoveStep(LineMoveStep.FR_12_BatchAxisToP2);
                        LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":提升伺服下降到P2点,");
                        MoveInfo.TimeOutSeconds = 120;
                        BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP2, Config.BatchAxis_P2Speed);
                        break;
                    case LineMoveStep.FR_12_BatchAxisToP2:
                        MoveInfo.NextMoveStep(LineMoveStep.FR_13_LocationDown); 
                        LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ": 放开定位气缸,升降伺服到P1");
                        TrayLCylinderAfter(MoveInfo);
                        Thread.Sleep(50);
                        UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed);
                        break;

                    case LineMoveStep.FR_13_LocationDown:
                        MoveInfo.NextMoveStep(LineMoveStep.FR_14_TopDown);
                        LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":SL1定位气缸下降SOL,出口顶升气缸下降,夹紧气缸放松");
                        CylinderMove(MoveInfo, IO_Type.SL_LocationCylinder_Up, IO_Type.SL_LocationCylinder_Down); 
                        CylinderMove(MoveInfo, IO_Type.SL_OutTopCylinder_Up, IO_Type.SL_OutTopCylinder_Down); 
                        CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Tighten, IO_Type.SL_MoveCylinder_Slack);
                        break;
                    case LineMoveStep.FR_14_TopDown:

                        MoveInfo.NextMoveStep(LineMoveStep.FR_15_BatchAxisToP1);
                        //判断定位工位是否有料架
                        if (IOValue(IO_Type.SL_Location_Check).Equals(IO_VALUE.HIGH))
                        {
                            LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":定位工位有料架,提升伺服不需要到P1"); 
                        }
                        else
                        { 
                            LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":定位工位无料架,提升伺服上升到P1点");
                            BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP1, Config.BatchAxis_P1Speed);
                        }
                        break;
                    case LineMoveStep.FR_15_BatchAxisToP1:  
                        LogInfo("重置完成!");
                        if (IOValue(IO_Type.SL_Out_Check).Equals(IO_VALUE.HIGH))
                        {
                            LogInfo("重置完成,出口检测到有料架,调用 "+Config.AgvOutName+" AgvClient.NeedLeave");
                            AgvClient.NeedLeave(Config.AgvOutName);
                        }
                        MoveEndS();
                        break;
                    default: break;
                }
            }
        }

        internal override void StopMove()
        {
            MoveInfo.EndMove();
            SecondMoveInfo.EndMove();
            BatchAxisStopCheck();
            BatchAxis.SuddenStop();
            UpdownAxis.SuddenStop();

            CloseAxis(BatchAxis);
            CloseAxis(UpdownAxis);
            if (Config.SidesWayNum <= 0)
            {
                IOMove(IO_Type.FL_StopCylinder_Down1, IO_VALUE.LOW);
                IOMove(IO_Type.FL_StopCylinder_Down2, IO_VALUE.LOW);
                IOMove(IO_Type.FL_TopCylinder_Down, IO_VALUE.LOW);
                IOMove(IO_Type.FL_TopCylinder_Up, IO_VALUE.LOW);
            }
            IOMove(IO_Type.SL_Line_Run, IO_VALUE.LOW);
            IOMove(IO_Type.SL_LocationSideWay_Run, IO_VALUE.LOW);
            IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.LOW);

            IOMove(IO_Type.SL_Entry_StopDown, IO_VALUE.LOW);
            IOMove(IO_Type.SL_Buffer_StopDown, IO_VALUE.LOW);
            IOMove(IO_Type.SL_Out_StopDown, IO_VALUE.LOW);
        }

        /// <summary>
        /// 停止运行
        /// </summary>
        public override void StopRun()
        {
            runStatus = LineRunStatus.Wait;
            lineStatus = LineStatus.StoreOnline;
            if (mainTimer != null)
            {
                mainTimer.Enabled = false;
            }
            StopMove();
           
        }


        protected override void BaseTimerProcess()
        {
            if (IOValue(IO_Type.SL_SuddenStop_BTN).Equals(IO_VALUE.LOW))
            {
                if (isInSuddenDown.Equals(false))
                {
                    SetWarnMsg(Name + "收到急停信号");
                    Alarm(LineAlarmType.SuddenStop);
                }
                return;
            }
        
            if (IOValue(IO_Type.SL_Reset_BTN).Equals(IO_VALUE.HIGH))
            {
                if (NoAlarm())
                {
                    if (MoveInfo.MoveType.Equals(LineMoveType.None))
                    {
                        LogUtil.error(Name + "收到复位信号,当前无报警,不需要复位");
                    }
                    else
                    {
                        LogUtil.error(Name + "收到复位信号,当前无报警,正在" + MoveInfo.MoveType + "处理中,不需要复位");
                    }
                }
                else
                {
                    LogUtil.info(Name + "收到复位信号,开始复位");
                    Reset();
                }
                return;
            }
            if (isInSuddenDown || isNoAirCheck)
            {
                return;
            }
            BusyMoveProcess();
            //判断流水线打开了才可以运行 
            if (MoveInfo.MoveType.Equals(LineMoveType.None)&&NoErrorAlarm())
            { 
                if ( Config.IsCanOut.Equals(0))
                {
                    StartInStoreP();
                }
                else
                {
                    StartOutStoreP();
                }
            }
            if (SecondMoveInfo.MoveType.Equals(LineMoveType.None) && NoErrorAlarm())
            {
                if (Config.IsCanOut.Equals(0))
                {
                    StartCheckFixture();
                }else if (LineManager.Line.runStatus <= LineRunStatus.Wait)
                {
                    StartCheckFixture();
                }
            }
            if (NoErrorAlarm())
            {
                if (IOValue(IO_Type.SL_Out_Check).Equals(IO_VALUE.HIGH))
                {
                    //线体出口检测到料架,需要通知AGV小车
                    AgvClient.NeedLeave(Config.AgvOutName);
                    // SendShelfToAGV();
                }
                else
                {
                    AgvClient.SetToNone(Config.AgvOutName);
                }
                //入口无料架,mayEnter
                if (IOValue(IO_Type.SL_Entry_Check).Equals(IO_VALUE.LOW))
                {
                    AgvClient.NeedEnter(Config.AgvInName);
                }
                else
                {
                    AgvClient.SetToNone(Config.AgvInName);
                }

            }
            IOTimeOutProcess();
        }

        /// <summary>
        /// 下降所有阻挡气缸
        /// </summary>
        internal override void OpenStopCylinder()
        {
            if (Config.SidesWayNum <= 0)
            {
                LogInfo("下降放料阻挡12 ,下降FL顶升气缸,上升横移机构 ");
                CheckAndMove(IO_Type.FL_StopCylinder_Down1, IO_VALUE.HIGH);
                CheckAndMove(IO_Type.FL_StopCylinder_Down2, IO_VALUE.HIGH);
                //顶升气缸下降
                CylinderMove(null, IO_Type.FL_TopCylinder_Up, IO_Type.FL_TopCylinder_Down);
            }
            else
            { 
                LogInfo(" 上升横移机构 ");
            }
            CylinderMove(null, IO_Type.SL_MoveCylinder_Down, IO_Type.SL_MoveCylinder_Up);
        }
        internal override void CloseCylinderStop()
        {
            if (Config.SidesWayNum <= 0)
            {
                LogInfo("上升放料阻挡12,关闭顶升气缸,关闭横移上下气缸");
                CheckAndMove(IO_Type.FL_StopCylinder_Down1, IO_VALUE.LOW);
                CheckAndMove(IO_Type.FL_StopCylinder_Down2, IO_VALUE.LOW);

                //顶升气缸下降
                CheckAndMove(IO_Type.FL_TopCylinder_Up, IO_VALUE.LOW);
                CheckAndMove(IO_Type.FL_TopCylinder_Down, IO_VALUE.LOW);
            }
            else
            {
                LogInfo(" 关闭横移上下气缸");
            }
            CheckAndMove(IO_Type.SL_MoveCylinder_Down, IO_VALUE.LOW);
            CheckAndMove(IO_Type.SL_MoveCylinder_Up, IO_VALUE.LOW);
        }

        /// <summary>
        /// 升降盘定位气缸前进
        /// </summary> 
        public void TrayLCylinderBefore(LineMoveInfo moveinfo = null)
        {
            IOMove(IO_Type.SL_TrayLocation_After, IO_VALUE.LOW);
            IOMove(IO_Type.SL_TrayLocation_Before, IO_VALUE.HIGH);
            if (moveinfo != null)
            {
                moveinfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_TrayLocation1_After, IO_VALUE.LOW));
                moveinfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_TrayLocation1_Before, IO_VALUE.HIGH));
                moveinfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_TrayLocation2_After, IO_VALUE.LOW));
                moveinfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_TrayLocation2_Before, IO_VALUE.HIGH));
            }
        }
        /// <summary>
        /// 升降盘定位气缸后退
        /// </summary> 
        public void TrayLCylinderAfter(LineMoveInfo moveinfo = null)
        {
            if (TrayLCylinderCanAfter())
            {
                IOMove(IO_Type.SL_TrayLocation_After, IO_VALUE.HIGH);
                IOMove(IO_Type.SL_TrayLocation_Before, IO_VALUE.LOW);
            }
            else
            {
                if (IOValue(IO_Type.SL_TrayLocation1_After).Equals(IO_VALUE.HIGH) &&
                    IOValue(IO_Type.SL_TrayLocation1_Before).Equals(IO_VALUE.LOW) &&
                    IOValue(IO_Type.SL_TrayLocation2_After).Equals(IO_VALUE.HIGH) &&
                    IOValue(IO_Type.SL_TrayLocation2_Before).Equals(IO_VALUE.LOW))
                {

                }
                else
                {
                    WarnMsg = Name + "TrayLCylinderAfter:提升轴当前不在下降位置P2,不后退定位气缸";
                    Alarm(LineAlarmType.IoSingleTimeOut);
                    LogUtil.error(Name + "TrayLCylinderAfter:提升轴当前不在下降位置P2,不后退定位气缸");
                }
            }
            if (moveinfo != null)
            {
                moveinfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_TrayLocation1_After, IO_VALUE.HIGH));
                moveinfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_TrayLocation1_Before, IO_VALUE.LOW));
                moveinfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_TrayLocation2_After, IO_VALUE.HIGH));
                moveinfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.SL_TrayLocation2_Before, IO_VALUE.LOW));
            }
        }

        public bool TrayLCylinderCanAfter()
        {
            int currP = BatchAxis.GetAclPosition();
            int chaz = Config.BatchAxisP2 - currP;
            if ((Math.Abs(chaz) < Math.Abs(Config.Height_ChangeValue * 2)))
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 升降盘是否在后退端
        /// </summary>
        public bool  IsTrayLCylinderAfter( )
        {
           
            if (IOValue(IO_Type.SL_TrayLocation1_After).Equals(IO_VALUE.HIGH) &&
                IOValue(IO_Type.SL_TrayLocation1_Before).Equals(IO_VALUE.LOW) &&
                IOValue(IO_Type.SL_TrayLocation2_After).Equals(IO_VALUE.HIGH) &&
                IOValue(IO_Type.SL_TrayLocation2_Before).Equals(IO_VALUE.LOW)  )
            {
                return true;
            }return false;
        }

        /// <summary>
        /// 判断上料横移机构是否可以横移运动
        /// </summary>
        /// <returns></returns>
        public bool MoveCylineCanTakeOrGive()
        {
            if (IOValue(IO_Type.SL_MoveCylinder_Down).Equals(IO_VALUE.LOW) && IOValue(IO_Type.SL_MoveCylinder_Up).Equals(IO_VALUE.HIGH))
            {
                return true;
            }
            return false;
        }

        #region 提升轴匀速上升处理 
        private System.Timers.Timer axisCheckTimer = null;
        private string TargetIoType = IO_Type.SL_AxisLocationCheck;
        private IO_VALUE TargetIoValue = IO_VALUE.HIGH;
        private bool BatchAxisStartCheck(string targetIo = "", IO_VALUE value = IO_VALUE.HIGH)
        {
            if (String.IsNullOrEmpty(targetIo))
            {
                targetIo = IO_Type.SL_AxisLocationCheck;
            }
            if (axisCheckTimer == null)
            {
                axisCheckTimer = new System.Timers.Timer();
                axisCheckTimer.AutoReset = true;
                axisCheckTimer.Interval += 30;
                axisCheckTimer.Elapsed += CheckTimer_Elapsed;
                axisCheckTimer.Enabled = false;
            }
            TargetIoValue = value;
            TargetIoType = targetIo;
            axisCheckTimer.Start();
            return true;
        }

        private bool BatchAxisStopCheck()
        { 
            if (!(axisCheckTimer == null))
            {
                axisCheckTimer.Stop();
            }
            return true;
        }
        private bool IsInProcess = false; 
        private DateTime lastOkTime = DateTime.Now;
        private void CheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            TimeSpan pan = DateTime.Now - lastOkTime;
            if (IsInProcess && pan.TotalMilliseconds < 300) { return; }
            try
            {
               
                IsInProcess = true;
                lastOkTime = DateTime.Now;
                if (IOValue(TargetIoType).Equals(TargetIoValue))
                {
                    LogUtil.debug(Name + "上料轴,检测到 " + TargetIoType + "=" + TargetIoValue + ",可以停止运动");
                    BatchAxis.SuddenStop();
                    BatchAxisStopCheck();
                }
            }catch(Exception ex)
            {
                LogUtil.error("CheckTimer_Elapsed出错:",ex);
            }
            finally
            {
                IsInProcess = false;
            }
        }


        #endregion

        #region AGV 
        internal bool  AgvCanEnter(string nodeId, RFIDData data)
        {
            string logN = Name + "收到 AgvCanEnter 事件 [" + nodeId + "] [" + data.ToData() + "] ";
            bool usable = false;
            if (nodeId.Equals(Config.AgvInName))
            {
                if (isInSuddenDown || isNoAirCheck)
                {
                    usable = false;
                }
                else
                {        
                    //入料口无料架即可进入
                    usable = (runStatus >= LineRunStatus.Runing
                         && ProcessShelfEnter.Equals(false)
                        && IOValue(IO_Type.SL_Entry_Check).Equals(IO_VALUE.LOW));
                }
            }
            else if (nodeId.Equals(Config.AgvOutName))
            {
                //出口有料架才可以进入
                usable = (runStatus >= LineRunStatus.Runing
                   && ProcessShelfOut.Equals(false)
                    && IOValue(IO_Type.SL_Out_Check).Equals(IO_VALUE.HIGH));
            }
            LogUtil.info(logN + ":" + usable);
            return usable;
        }

        internal void AgvArrive(string nodeId, RFIDData data)
        {
            string logN = Name + "收到 AgvArrive 事件 [" + nodeId + "] [" + data.ToData() + "] ";
            if (nodeId.Equals(Config.AgvInName))
            {
            }
            else if (nodeId.Equals(Config.AgvOutName))
            {
            }
            LogUtil.info(logN + ":" + "暂无处理"); 
        }

        internal void AgvReady(string nodeId, RFIDData data)
        {
            string logN = Name + "收到 AgvReady 事件 [" + nodeId + "] [" + data.ToData() + "] ";

            if (nodeId.Equals(Config.AgvInName))
            {
                if (IOValue(IO_Type.SL_Entry_Check).Equals(IO_VALUE.HIGH))
                {
                    LogUtil.info(logN + " ,入口有料架,暂不处理");
                }
                ShelfEnterProcess();

            }
            else if (nodeId.Equals(Config.AgvOutName))
            {
                if (IOValue(IO_Type.SL_Out_Check).Equals(IO_VALUE.LOW))
                {
                    LogUtil.info(logN + " ,未检测到出口有料架,暂不处理");
                }
                ShelfOutProcess();
            } 
        }
        private bool ProcessShelfEnter = false;
        private bool ProcessShelfOut = false;
      
        internal void ShelfOutProcess()
        { 
            //AGV已到达,将料架送入AGV中
            Task.Factory.StartNew(delegate
            {
                try
                {
                    if (IOValue(IO_Type.SL_Out_Check).Equals(IO_VALUE.HIGH))
                    {
                        LogUtil.info(Name + "料架送入AGV  开始");
                        AgvClient.MayLeave(Config.AgvOutName);
                        ProcessShelfOut = true;
                        //出口阻挡下降,出口线体转动 
                        IOMove(IO_Type.SL_Out_StopDown, IO_VALUE.HIGH);
                        IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.HIGH);

                        if (WaitIo(IO_Type.SL_Out_Check, IO_VALUE.LOW, 6000))
                        { 
                            //再转动2000
                            Thread.Sleep(3000);
                            //停止转动 ,阻挡上升
                            IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.LOW);
                            IOMove(IO_Type.SL_Out_StopDown, IO_VALUE.LOW);
                            AgvClient.SetStatus(Config.AgvOutName,"",ClientAction.FinishLeave);
                            Task.Factory.StartNew(delegate
                            {
                                Thread.Sleep(2000);
                                AgvClient.SetStatus(Config.AgvOutName, "", ClientAction.None);
                            });
                            ProcessShelfOut = false;
                            LogUtil.info(Name + "料架送入AGV  结束");
                          
                        }
                        else
                        { 
                            LogUtil.info(Name + "料架送入AGV  等待SL_Out_Check=LOW超时");
                        } 
                    }
                }
                catch (TimeoutException te)
                {
                    LogUtil.error("料架送入AGV 超时:" + te);
                }
                catch (Exception ex)
                {
                    LogUtil.error("料架送入AGV 出错:", ex);
                }
                finally
                {
                    IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.LOW);
                    ProcessShelfOut = false;
                }
            }); 
        }
        internal void  ShelfEnterProcess()
        { 
            Task.Factory.StartNew(delegate
            {
                try
                {
                    if (IOValue(IO_Type.SL_Entry_Check).Equals(IO_VALUE.LOW))
                    {
                        LogUtil.info(Name + "AGV料架进入  开始");
                        AgvClient.MayEnter(Config.AgvInName);
                        ProcessShelfEnter = true;
                        ////进料阻挡上升
                        //IOMove(IO_Type.SL_Entry_StopDown, IO_VALUE.LOW);
                     
                        //转动线体
                        IOMove(IO_Type.SL_Line_Run, IO_VALUE.HIGH);

                        //等待进料检测信号
                        if (WaitIo(IO_Type.SL_Entry_Check, IO_VALUE.HIGH, 5000))
                        {

                            //等待200毫秒后停止转动
                            Thread.Sleep(3000);
                            IOMove(IO_Type.SL_Line_Run, IO_VALUE.LOW);
                            //料架可离开
                            AgvClient.FinishEnter(Config.AgvInName);
                            Task.Factory.StartNew(delegate
                            { 
                                Thread.Sleep(2000); 
                                AgvClient.SetStatus(Config.AgvInName, "", ClientAction.None);
                            });
                            ProcessShelfEnter = false;
                            LogUtil.info(Name + "AGV料架进入  结束");
                        }
                        else
                        {
                            LogUtil.info(Name + "AGV料架进入  等待SL_Stop_Check=High超时");
                        }
                      
                    }
                }
                catch (TimeoutException te)
                {
                    LogUtil.error("AGV料架进入  超时:" + te);
                }
                catch (Exception ex)
                {
                    LogUtil.error("AGV料架进入  出错:" ,ex);
                }
                finally
                {
                    IOMove(IO_Type.SL_Line_Run, IO_VALUE.LOW);
                    ProcessShelfEnter = false;
                }
            }); 
        } 

        private bool UpdateShelfId()
        {
            try
            {
                //判断料架的编码是否正确
                RFIDData rfidD = RFIDManager.GetShelfId(DeviceID);
                CurrShelfId = rfidD.NumStr();

                //发送料架信息给调度系统
              //  AgvClient.SendRFID(Config.AgvInName, CurrShelfId);
                LogUtil.info(Name + "读取到料架编号:" + CurrShelfId);
            }
            catch (Exception ex)
            {
                LogUtil.error(Name + "UpdateShelfId出错:", ex);
            }
            return true;
        }
        #endregion
    }
}