FeedingEquip.cs 26.8 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
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 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);
            BatchAxis = new AxisBean(config.Batch_Axis);
            MoveInfo = new LineMoveInfo(DeviceID, "入料-" + DeviceID + "-Move");
            SecondMoveInfo = new LineMoveInfo(DeviceID, "入料-" + DeviceID + "-SecondMove");
        }


        /// <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()
        {
            BatchAxisStopCheck();
            ResetClearData();
            lineStatus = LineStatus.ResetMove;
            IOMove(IO_Type.SL_HddLed, IO_VALUE.HIGH);
            MoveInfo.NextMoveStep(LineMoveStep.FR_01_MoveCylinder_Up);
            LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":上料横移机构上升,出口顶升下降,所有阻挡气缸上升");
            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)
            {
                IOMove(IO_Type.FL_StopCylinder_Down1, IO_VALUE.LOW);
                IOMove(IO_Type.FL_StopCylinder_Down2, IO_VALUE.LOW);
                //顶升气缸下降
                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);
            }
            //线体停止
            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);

            //阻挡上升
            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);


            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_MoveCylinder_Up:
                        MoveInfo.NextMoveStep(LineMoveStep.FR_02_BatchAxisHome);
                        MoveInfo.TimeOutSeconds = 120;
                        LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":提升伺服回原点,升降伺服回原点,所有阻挡气缸上升");
                        BatchAxis.HomeMove(MoveInfo);
                        UpdownAxis.HomeMove(MoveInfo);
                        break;
                    case LineMoveStep.FR_02_BatchAxisHome:
                        LogInfo(MoveInfo.MoveType + ":FR_03_BatchAxisToP2:提升伺服下降到P2点,升降伺服上升到待机点");
                        MoveInfo.TimeOutSeconds = 120;
                        MoveInfo.NextMoveStep(LineMoveStep.FR_03_BatchAxisToP2);
                        BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP2, Config.BatchAxis_P2Speed);
                        UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed);
                        break;
                    case LineMoveStep.FR_03_BatchAxisToP2:
                        LogInfo(MoveInfo.MoveType + ":FR_04_LocationCylinder_Down: 放开定位气缸");
                        MoveInfo.NextMoveStep(LineMoveStep.FR_04_LocationCylinder_Down);
                        TrayLCylinderAfter(MoveInfo);
                        break;

                    case LineMoveStep.FR_04_LocationCylinder_Down:
                        LogInfo(MoveInfo.MoveType + ":FR_05_TopCylinderDown:SL1定位气缸下降SOL,出口顶升气缸下降");
                        MoveInfo.NextMoveStep(LineMoveStep.FR_05_TopCylinderDown);
                        CylinderMove(MoveInfo, IO_Type.SL_LocationCylinder_Up, IO_Type.SL_LocationCylinder_Down);

                        CylinderMove(MoveInfo, IO_Type.SL_OutTopCylinder_Up, IO_Type.SL_OutTopCylinder_Down);
                        break;
                    case LineMoveStep.FR_05_TopCylinderDown:

                        //判断定位工位是否有料架
                        if (IOValue(IO_Type.SL_Location_Check).Equals(IO_VALUE.HIGH))
                        {
                            LogInfo(MoveInfo.MoveType + ":FR_06_BatchAxisToP1:定位工位有料架,提升伺服不需要到P1");
                            MoveInfo.NextMoveStep(LineMoveStep.FR_06_BatchAxisToP1);
                           // BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP1, Config.BatchAxis_P1Speed);
                        }
                        else
                        { 
                            LogInfo(MoveInfo.MoveType + ":FR_06_BatchAxisToP1:定位工位无料架,提升伺服上升到P1点");
                            MoveInfo.NextMoveStep(LineMoveStep.FR_06_BatchAxisToP1);
                            BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP1, Config.BatchAxis_P1Speed);
                        }
                        break;
                    case LineMoveStep.FR_06_BatchAxisToP1:
                    //    LogInfo(MoveInfo.MoveType + ":FR_07_MoveCylinder_Up:上料横移机构上升SOL");
                    //    MoveInfo.NextMoveStep(LineMoveStep.FR_07_MoveCylinder_Up);
                    //    CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Down, IO_Type.SL_MoveCylinder_Up);
                    //    break;
                    //case LineMoveStep.FR_07_MoveCylinder_Up:
                    //    LogInfo(MoveInfo.MoveType + ":FR_08_MoveCylinder_Slack:上料气缸放松SOL");
                        MoveInfo.NextMoveStep(LineMoveStep.FR_08_MoveCylinder_Slack);
                        CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Tighten, IO_Type.SL_MoveCylinder_Slack);
                        break;
                    case LineMoveStep.FR_07_MoveCylinder_Up:
                        LogInfo(MoveInfo.MoveType + ":FR_08_MoveCylinder_Slack:上料气缸放松SOL");
                        MoveInfo.NextMoveStep(LineMoveStep.FR_08_MoveCylinder_Slack);
                        CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Tighten, IO_Type.SL_MoveCylinder_Slack);
                        break;
                    case LineMoveStep.FR_08_MoveCylinder_Slack:
                        if (MoveCylineCanTakeOrGive())
                        {
                            LogInfo(MoveInfo.MoveType + ":FR_09_MoveCylinder_Give: 上料横移气缸放料端SOL");
                            MoveInfo.NextMoveStep(LineMoveStep.FR_09_MoveCylinder_Give);
                            CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Take, IO_Type.SL_MoveCylinder_Give);
                        }
                        else
                        {
                            LogInfo(MoveInfo.MoveType + ":FR_07_MoveCylinder_Up:上料横移机构上升SOL");
                            MoveInfo.NextMoveStep(LineMoveStep.FR_07_MoveCylinder_Up);
                            CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Down, IO_Type.SL_MoveCylinder_Up);
                        }
                        break;
                    case LineMoveStep.FR_09_MoveCylinder_Give:
                    //    LogInfo(MoveInfo.MoveType + ":FR_10_OutTopCylinder_Down:  出口顶升下降SOL");
                    //    MoveInfo.NextMoveStep(LineMoveStep.FR_10_OutTopCylinder_Down);
                    //    CylinderMove(MoveInfo, IO_Type.SL_OutTopCylinder_Up, IO_Type.SL_OutTopCylinder_Down);
                    //    break;
                    //case LineMoveStep.FR_10_OutTopCylinder_Down:
                        LogInfo("重置完成!");
                        runStatus = LineRunStatus.Runing;
                        lineStatus = LineStatus.StoreOnline;
                        MoveInfo.EndMove();
                        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()
        {
            if (mainTimer != null)
            {
                mainTimer.Enabled = false;
            }
            StopMove();
            runStatus = LineRunStatus.Wait;
        }


        public override void TimerProcess()
        {
            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 (alarmType.Equals(LineAlarmType.None))
                {
                    if (MoveInfo.MoveType.Equals(LineMoveType.None))
                    {
                        LogUtil.error(Name + "收到复位信号,当前无报警,不需要复位");
                    }
                    else
                    {
                        LogUtil.error(Name + "收到复位信号,当前无报警,正在" + MoveInfo.MoveType + "处理中,不需要复位");
                    }
                }
                else
                {
                    LogUtil.info(Name + "收到复位信号,开始复位");
                    Reset();
                }
                return;
            }
            BusyMoveProcess();
            //判断流水线打开了才可以运行 
            if (MoveInfo.MoveType.Equals(LineMoveType.None))
            {
              
                if ( Config.IsCanOut.Equals(0))
                {
                    StartInStoreP();
                }
            }
            if ( SecondMoveInfo.MoveType.Equals(LineMoveType.None))
            {
                StartCheckFixture();
            }
            IOTimeOutProcess();
        }

        /// <summary>
        /// 下降所有阻挡气缸
        /// </summary>
        internal override void OpenStopCylinder()
        {
            if (Config.SidesWayNum <= 0)
            {
                LogInfo("下降阻挡气缸,下降顶升气缸 ");
                IOMove(IO_Type.FL_StopCylinder_Down1, IO_VALUE.HIGH);
                IOMove(IO_Type.FL_StopCylinder_Down2, IO_VALUE.HIGH);
                //顶升气缸下降
                CylinderMove(null, IO_Type.FL_TopCylinder_Up, IO_Type.FL_TopCylinder_Down);

            }
        }
        internal override void CloseCylinderStop()
        {
            if (Config.SidesWayNum <= 0)
            {
                LogInfo("上升阻挡气缸,关闭 顶升气缸IO");
                IOMove(IO_Type.FL_StopCylinder_Down1, IO_VALUE.LOW);
                IOMove(IO_Type.FL_StopCylinder_Down2, IO_VALUE.LOW);

                //顶升气缸下降
                IOMove(IO_Type.FL_TopCylinder_Up, IO_VALUE.LOW);
                IOMove(IO_Type.FL_TopCylinder_Down, 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)
        {
            IOMove(IO_Type.SL_TrayLocation_After, IO_VALUE.HIGH);
            IOMove(IO_Type.SL_TrayLocation_Before, IO_VALUE.LOW);
            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));
            }
        }

        /// <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 void CheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (IsInProcess) { return; }
            IsInProcess = true;
            if (IOValue(TargetIoType).Equals(TargetIoValue))
            {
                LogUtil.info(Name + "上料轴,检测到 " + TargetIoType + "=" + TargetIoValue + ",可以停止运动");
                BatchAxis.SuddenStop();
                BatchAxisStopCheck();
            }
            IsInProcess = false;
        }


        #endregion

        #region AGV
        private bool ProcessShelfEnter = false;
        private bool ProcessShelfOut = false;
        internal bool ProcessAGVAction(string name, Actions action)
        {
            string logN = name + "收到调度【" + name + "】=【" + action + "】";
            if (name.Equals(Config.AgvInName))
            {
                //状态处理
                if (action.Equals(Asa.Actions.Usable))
                {
                    //判断入口是否可用:入口无料架,缓冲工位无料架,不在入料架处理中
                    bool usable = (runStatus.Equals(LineRunStatus.Runing)
                        && MoveInfo.MoveType.Equals(LineMoveType.None)
                        && ProcessShelfEnter.Equals(false)
                        && IOValue(IO_Type.SL_Entry_Check).Equals(IO_VALUE.LOW)
                        && IOValue(IO_Type.SL_Stop_Check).Equals(IO_VALUE.LOW));

                    LogUtil.info(logN + ":" + usable);
                    return usable;
                }
                else if (action.Equals(Asa.Actions.Arrive))
                {
                    if (IOValue(IO_Type.SL_Entry_Check).Equals(IO_VALUE.LOW))
                    {
                        LogUtil.info(logN + " ,未检测到:SL_Entry_Check,不处理");
                        return false;
                    }
                    //小车到达,开始处理 
                    if (runStatus >= (LineRunStatus.Runing)
                        && MoveInfo.MoveType.Equals(LineMoveType.None)
                       && ProcessShelfEnter.Equals(false)
                       && IOValue(IO_Type.SL_Stop_Check).Equals(IO_VALUE.LOW))
                    {
                        ShelfEnterProcess();
                        return true;
                    }
                }
                else
                {
                    LogUtil.info(name + logN + " ,未找到相关处理");
                }
            }
            else if (name.Equals(Config.AgvOutName))
            {
                if (action.Equals(Asa.Actions.Arrive))
                {
                    if (IOValue(IO_Type.SL_Out_Check).Equals(IO_VALUE.LOW))
                    {
                        LogUtil.info(name + logN + " ,未检测到:SL_Out_Check,不处理");
                        return false;
                    }
                    //小车到达,开始处理 
                    if (runStatus >= (LineRunStatus.Runing) &&
                        MoveInfo.MoveType.Equals(LineMoveType.None) &&
                        ProcessShelfOut.Equals(false) &&
                        IOValue(IO_Type.SL_Out_Check).Equals(IO_VALUE.HIGH))
                    {
                        ShelfOutProcess();
                        return true;
                    }
                }
                else if (action.Equals(Asa.Actions.FinishOut))
                {
                    LogUtil.info(name + logN + " ,停止SL_OutLine_Run");
                    //停止转动 
                    IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.LOW);
                    return true;
                }
                else
                {
                    LogUtil.info(name + logN + " ,未找到相关处理");
                    return false;
                }
            }
            return 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.MayOut(Config.AgvOutName);
                        ProcessShelfOut = true;
                        //出口阻挡下降,出口线体转动 
                        IOMove(IO_Type.SL_Out_StopDown, IO_VALUE.LOW);
                        IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.HIGH);

                        if (WaitIo(IO_Type.SL_Out_Check, IO_VALUE.LOW, 2000))
                        {
                            //等待收到AGV消息
                            WaitUtil.Wait(3000, delegate
                            {
                                return AgvClient.GetAction(Config.AgvOutName).Equals(Actions.FinishOut);
                            }, "等待AGV收到料架");

                            //停止转动 
                            IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.LOW);

                            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()
        {
            //判断料架的编码是否正确
            RFIDData data = TrayManager.GetShelfData(DeviceID);
            if (data.Num <= 0)
            {
                MoveInfo.EndMove();
                runStatus = LineRunStatus.Runing;
                LogUtil.info(" 入料检测有料架,获取不到正确的料架编号,入料结束");
                return   ;
            } 
            //发送料架信息给调度系统
            AgvClient.SendRFID(Config.AgvInName, data.ToData());
            LogUtil.info(Name + "入料口读取到料架:" + data.ToStr());
            Task.Factory.StartNew(delegate
            {
                try
                {
                    if (IOValue(IO_Type.SL_Stop_Check).Equals(IO_VALUE.LOW))
                    {
                        LogUtil.info(Name + "AGV料架进入缓冲工位  开始");
                        AgvClient.MayEnter(Config.AgvInName);
                        ProcessShelfEnter = true;
                        //进料阻挡下降,缓冲阻挡上升
                        IOMove(IO_Type.SL_Entry_StopDown, IO_VALUE.HIGH);
                        IOMove(IO_Type.SL_Buffer_StopDown, IO_VALUE.LOW);
                        //转动线体
                        IOMove(IO_Type.SL_Line_Run, IO_VALUE.HIGH);

                        //等待阻挡检测信号
                        if (WaitIo(IO_Type.SL_Stop_Check, IO_VALUE.HIGH, 3000))
                        {

                            //料架完成进入
                            //AgvClient.FinishEnter(Config.AgvInName);

                            //上升入口阻挡信号
                            IOMove(IO_Type.SL_Entry_StopDown, IO_VALUE.HIGH);

                            //等待200毫秒后停止转动
                            Thread.Sleep(200);
                            IOMove(IO_Type.SL_Line_Run, IO_VALUE.LOW);

                            //料架可离开
                            AgvClient.FinishEnter(Config.AgvInName);

                            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;
                }
            }); 
        }
        #endregion
    }
}