BoxBean.cs 26.2 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

using Asa;
using DeviceLib;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
    /// <summary>
    /// 流水线自动料仓-Box类
    /// </summary>
    public partial class BoxBean : KTK_Store
    { 
        private   bool IsIntSlvBlock = false;
        public AutoInoutInfo AutoInout = new AutoInoutInfo();
        public string CID = "";
        public BOX_Config Config;
        public string lastPosId = "";
        public StoreStatus lastPosIdStatus = StoreStatus.StoreOnline;
        public List<ConfigMoveAxis> moveAxisList = new List<ConfigMoveAxis>();
 
        public List<string> PositionNumList = new List<string>();
      
        public HumitureBean humBean = null;
       
        private int logType = 1000;

        public AxisBean UpdownAxis = null;
        public AxisBean MiddleAxis = null;
        public AxisBean ComAxis = null;
        public AxisBean InoutAxis = null;

        /// <summary>
        /// 出料口最后一盘料信息,0=暂无,1=单盘出库料亮绿灯,2=入库NG料亮红灯
        /// </summary>
        public int OutDoorReelType = 0;
         
        public BoxBean(BOX_Config config)
        {
            Init();
            baseConfig = config;
            CID = config.CID;

            IoCheckTimer.Elapsed += IoCheckTimer_Elapsed;
            serverConnectTimer.Elapsed += server_connect_timer_Tick;
            logType = 1000 * config.Id;
            //添加调试 
            IsDebug = config.IsInDebug.Equals(1);
            Name = (" BOX_" + config.Id + " ").ToUpper();
            MoveInfo = new StoreMoveInfo(ID, Name);
            this.ID = config.Id; ;
            this.Config = config;  
            //温湿度
            humBean = new HumitureBean(config.Humiture_Port, Name);
          
            MoveAxisConfig();
            List<ACBoxPosition> positionList = CSVPositionReader<ACBoxPosition>.getPositionList();
            PositionNumList = new List<string>();
            foreach (ACBoxPosition position in positionList)
            {
                if (position.StoreId.Equals(ID) && ACBoxPosition.CheckPosition(position, Config))
                {
                    PositionNumList.Add(position.PositionNum);
                }
            }
            InoutAxis = new AxisBean(config.InOut_Axis, Name);
            MiddleAxis = new AxisBean(config.Middle_Axis, Name);
            UpdownAxis = new AxisBean(config.UpDown_Axis, Name);
            ComAxis = new AxisBean(config.Comp_Axis, Name);
            mainTimer.Enabled = false;
            int isAuto = ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun);
            if (isAuto == 1)
            {
                mainTimer.Enabled = true;
            }
        }

        private void IoCheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            //判断急停 
            if (storeRunStatus >= StoreRunStatus.HomeMoving)
            {
                if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
                {
                    if (isInSuddenDown.Equals(false))
                    {
                        isInSuddenDown = true;
                        LogUtil.error(Name + "收到急停信号,报警急停");
                        WarnMsg = Name + "收到急停信号,报警急停";

                        //报警时会关闭所有轴
                        Alarm(AlarmType.SuddenStop, "1", WarnMsg, MoveType.None);
                    }
                }
            }
        }
        /// <summary>
        /// 配置速度,加减速时间
        /// </summary>
        public void MoveAxisConfig()
        {
            Config.UpDown_Axis.BreakOnDO = IO_Type.UpdownAxis_Break;
            moveAxisList = new List<ConfigMoveAxis>(); 
            moveAxisList.Add(Config.Middle_Axis);
            moveAxisList.Add(Config.UpDown_Axis);
            moveAxisList.Add(Config.InOut_Axis);
            moveAxisList.Add(Config.Comp_Axis);
        }
        /// <summary>
        /// 开始运行
        /// </summary>
        public override bool StartRun(bool isDebug = false)
        {
            if (!StoreManager.Store.canStart)
            {
                WarnMsg = "启动失败:设备未初始化完成";
                LogUtil.error(Name + "启动失败:设备未初始化完成");
                return false;
            }
            LogInfo("开始启动,启动时间:" + StartTime.ToString()); 
            AutoInout.StopAuto();
            mainTimer.Enabled = false;
            alarmType = AlarmType.None;

            //急停按钮和气压检测需要一起判断
            IO_VALUE suddenBtn = IOValue(IO_Type.SuddenStop_BTN);
            IO_VALUE airCheck = IOValue(IO_Type.Airpressure_Check);

            if (suddenBtn.Equals(IO_VALUE.HIGH) && (airCheck.Equals(IO_VALUE.HIGH)))
            {
                //lastAirValue = airCheck;
                lastAirCloseTime = DateTime.Now;
                if (!OpenAllAxis(true))
                {
                    return false;
                }

                //TODO 启动时先所有轴远点返回,测试暂时关闭 
                storeRunStatus = StoreRunStatus.HomeMoving;
                storeStatus = StoreStatus.ResetMove;
                //启动温湿度服务器 
                HumitureController.Init(Config.Humiture_Port);

                ReturnHome();
                StartTime = DateTime.Now;
                mainTimer.Enabled = true;
                IoCheckTimer.Enabled = true;
                serverConnectTimer.Enabled = true;

                return true;
            }
            else
            {
                if (suddenBtn.Equals(IO_VALUE.LOW))
                {
                    WarnMsg = "启动失败:急停没开";
                    LogUtil.error(" (" + Name + ")启动失败:急停没开!");
                }
                else
                {
                    WarnMsg = "启动失败:没有气压信号";
                    LogUtil.error(" (" + Name + ")启动失败:没有气压信号!");
                }
                return false;
            }
        }

      

        #region 原点返回和复位处理
        private void ReturnHome()
        { 
            lastPosId = "";
            lastPosIdStatus = StoreStatus.ResetMove;
            AutoInout.ClearCount();
            storeRunStatus = StoreRunStatus.HomeMoving;
            MoveInfo.NewMove(MoveType.ReturnHome);
            InoutStartReset();
        }

        public override void Reset(bool isNeedClearAuto = true)
        {
            AutoInout.ClearCount();
            //复位之前先停止运行
            if (isNeedClearAuto)
            {
                AutoInout.StopAuto();
            }
            storeRunStatus = StoreRunStatus.Reset;
            storeStatus = StoreStatus.ResetMove;
            MoveInfo.NewMove(MoveType.StoreReset);

            if (!OpenAllAxis(true))
            {
                LogInfo("复位时打开轴失败,需要再次复位,直接报警停止复位");
                return;
            }
            InoutStartReset();
            isInPro = false;
        }
        private void InoutStartReset()
        {
            //清理报警
            WarnMsg = "";
            isInSuddenDown = false;
            isNoAirCheck = false;
            alarmType = AlarmType.None; 

            //开始复位动作
            MoveInfo.NextMoveStep(StoreMoveStep.BOX_H01_InOutBack);

            LogInfo(MoveInfo.MoveType + ": 开始料架入库,线体停止,进出轴先原点返回 ");
            MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
            LineStop();
            InoutAxis.HomeMove(MoveInfo);
        }
      
        protected override void ResetProcess()
        {
            if (MoveInfo.IsInWait)
            {
                CheckWait();
            }
            if (MoveInfo.IsInWait)
            {
                return;
            }
            switch (MoveInfo.MoveStep)
            {
                case StoreMoveStep.BOX_H01_InOutBack: 
                    MoveInfo.NextMoveStep(StoreMoveStep.BOX_H02_InoutToP1);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                    LogInfo(MoveInfo.MoveType + ":   ,进出轴到待机点P1,关闭仓门"); 
                    InoutAxis.AbsMove(MoveInfo, Config.InOutAxis_P1, Config.InOutAxis_P1_Speed); 
                    CylinderMove(MoveInfo, IO_Type.OutDoor_Up, IO_Type.OutDoor_Down); 
                    break;

                case StoreMoveStep.BOX_H02_InoutToP1:
                    LineStop();
                    //如果此时轴三还在报警,需要提示错误并等待 
                    if (ACServerManager.GetAlarmStatus(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue()) > 0)
                    {
                        LogUtil.error(Name + MoveInfo.MoveType + "复位失败:  " + Config.InOut_Axis.Explain + "报警");
                        WarnMsg = Name + "复位失败:  " + Config.InOut_Axis.Explain + "报警";
                        Alarm(AlarmType.AxisAlarm );
                        return;
                    }
                    //复位和回原点要等轴3进出轴ORG亮了以后才能返回其他轴
                    LogInfo(MoveInfo.MoveType + ":  ,  压紧轴,旋转轴,上下轴开始 原点返回");
                    MoveInfo.NextMoveStep(StoreMoveStep.BOX_H03_OtherAxisHome);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
                    ComAxis.HomeMove(MoveInfo);
                    MiddleAxis.HomeMove(MoveInfo);
                    UpdownAxis.HomeMove(MoveInfo);
                    break;
                case StoreMoveStep.BOX_H03_OtherAxisHome:
                    MoveInfo.NextMoveStep(StoreMoveStep.BOX_H04_OtherAxisBack);
                    MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(2000));
                    LogInfo(MoveInfo.MoveType + ": 旋转轴运动到P1,上下轴走到P1,压紧轴到P1 ");
                    MiddleAxis.AbsMove(MoveInfo, Config.MiddleAxis_P1, Config.MiddleAxis_P1_Speed);
                    UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxis_P1, Config.UpDownAxis_P1_Speed);
                    ComAxis.AbsMove(MoveInfo, Config.CompAxis_P1, Config.CompAxis_P1_Speed);
                    break;
                case StoreMoveStep.BOX_H04_OtherAxisBack:
                    LogInfo(MoveInfo.MoveType + ": 完成");
                    MoveEndToRuningStatus();
                    break;

             

                default: break;
            }
        }


        #endregion

        public bool OpenAllAxis(bool isCheck)
        {
            return RunMultiAxis(true, IO_Type.Axis_Run, IO_Type.UpdownAxis_Break, new AxisBean[] { MiddleAxis,UpdownAxis,InoutAxis,ComAxis}); 
        } 
        public void CloseAllAxis()
        {
            LogUtil.info(Name + "关闭刹车,关闭伺服");
            CloseMultiAxis(IO_Type.Axis_Run, IO_Type.UpdownAxis_Break, new AxisBean[] { MiddleAxis, UpdownAxis, InoutAxis, ComAxis });

        } 

        /// <summary>
        /// 停止运行
        /// </summary>
        public override void StopRun()
        { 
            lastPosId = "";
            lastPosIdStatus = StoreStatus.StoreOnline;
            WarnMsg = "";
            AutoInout.StopAuto();
            IoCheckTimer.Enabled = false;
            serverConnectTimer.Enabled = false;
            StopMove();

            storeRunStatus = StoreRunStatus.Wait;
            mainTimer.Enabled = false;
            TimeSpan span = DateTime.Now - StartTime;
            LogInfo(",停止运行,总运行时间:" + span.ToString());
        }
        public DateTime LastAlarmTime = DateTime.Now;
        public override void Alarm(AlarmType alarmType, string alarmDetial = "", string alarmMsg = "", MoveType storeMoveType = MoveType.None)
        {
            if (alarmType.Equals(AlarmType.None).Equals(false))
            {
                LastAlarmTime = DateTime.Now;
            }
            SaveAlarmInfo(alarmType, alarmDetial, alarmMsg, storeMoveType);
            AutoInout.StopAuto();

            if (this.alarmType.Equals(alarmType) && alarmType != AlarmType.SuddenStop && alarmType != AlarmType.NoAirCheck)
            {
                return;
            }
            LogUtil.error(Name + " 报警,报警类型:" + alarmType);

            this.alarmType = alarmType;
            if (alarmType.Equals(AlarmType.AxisAlarm) | alarmType.Equals(AlarmType.AxisMoveError))
            {
                LogUtil.error(Name + "轴报警, 停止运动, 打开报警灯");

                StopMove();
            }
            else if (alarmType == AlarmType.SuddenStop)
            {
                isInSuddenDown = true;
                LogUtil.error(Name + "收到急停信号,停止运动, 打开报警灯 ");
                StopMove();
                storeStatus = StoreStatus.SuddenStop;
            }
            else if (alarmType.Equals(AlarmType.NoAirCheck))
            {
                isNoAirCheck = true;
                LogUtil.error(Name + " 未检测到气压信号 ,停止运动, 打开报警灯 ");
                StopMove();
                storeStatus = StoreStatus.SuddenStop;
            }
        }
        private bool InProcess = false; 
        private bool IsChongfu = false;
        private Stopwatch stopwatch = new Stopwatch();
        protected override void timersTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (InProcess)
            {
                //TimeSpan span = DateTime.Now - preProcessTime;
                if (stopwatch.Elapsed.TotalSeconds < 10)
                {
                    return;
                }
                else
                {
                    LogUtil.error("主定时器:InProcess已等待" + stopwatch.Elapsed.ToString() + "重新处理");
                    IsChongfu = true;
                }
            }
            try
            {
                InProcess = true;
                //preProcessTime = DateTime.Now;
                stopwatch.Restart();
                IoCheckProcess();
                ShowTimeLog("IoCheckProcess");
                TimerProcess();
                ShowTimeLog("TimerProcess");
                //检查运动轴报警
                if (storeRunStatus > StoreRunStatus.Wait && (!isInSuddenDown) && (!isNoAirCheck))
                {
                    ShowTimeLog("开始检测轴报警");
                    CheckAxisAlarm();
                    ShowTimeLog("轴报警检测完成");
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(Name + "定时处理出错:" + ex.ToString());
            }
            IsChongfu = false;
            InProcess = false;
        }
        private IO_VALUE preAirValue = IO_VALUE.HIGH;
        private void AirCheckProcess()
        {

            IO_VALUE currAirValue = IOValue(IO_Type.Airpressure_Check);
            if (isInSuddenDown)
            {
                return;
            }
            if (isNoAirCheck)
            {
                return;
            }
            if (currAirValue.Equals(IO_VALUE.LOW))
            {
                //判断是否持续了3秒
                if (preAirValue.Equals(IO_VALUE.LOW))
                {
                    TimeSpan span = DateTime.Now - lastAirCloseTime;
                    if (span.TotalSeconds > StoreManager.Config.AirCheckSeconds)
                    {
                        WarnMsg = "未检测到气压信号";
                        preAirValue = IO_VALUE.LOW;
                        LogUtil.info("已持续【" + FormUtil.GetSpanStr(span) + "】未检测到气压信号,报警");
                        Alarm(AlarmType.NoAirCheck, "2", WarnMsg, MoveType.None);
                        return;
                    }
                }
                else
                {
                    lastAirCloseTime = DateTime.Now;
                    isNoAirCheck = false;
                }
            }
            else
            {
                isNoAirCheck = false;
            }
            preAirValue = currAirValue;
        }
        private void ShowTimeLog(string info)
        {
            if (IsChongfu)
            {
                LogUtil.info( Name+"【" + info + "】 处理完成,耗时:" + stopwatch.Elapsed.ToString());
            }
        }

        private IO_VALUE lastAutoRun = IO_VALUE.LOW;
        public void IoCheckProcess()
        {
            DateTime time = DateTime.Now;
            if (storeRunStatus.Equals(StoreRunStatus.Wait))
            {
                //取新的Io状态
                IO_VALUE autoSingle = IOValue(IO_Type.Reset_BTN);
                if (ConfigAppSettings.GetIntValue(Setting_Init.App_AutoRun).Equals(1))
                {
                    if (autoSingle.Equals(IO_VALUE.HIGH) && lastAutoRun.Equals(IO_VALUE.LOW))
                    {
                        //没有启动时收到复位按钮,相当于启动按钮
                        LogInfo("没有启动时收到复位按钮,相当于启动按钮,开始调用启动方法!");
                        bool result = StartRun();
                        if (result.Equals(false))
                        {
                            LogUtil.error(Name + "料仓启动失败,继续等待下次启动!");
                            mainTimer.Enabled = true;
                        }
                    }
                    lastAutoRun = autoSingle;
                    return;
                }
                lastAutoRun = autoSingle;
            }
            //判断急停 
            else if (storeRunStatus >= StoreRunStatus.HomeMoving)
            {
                ////取新的Io状态 
                //IO_VALUE suddenBtn = IOValue(IO_Type.SuddenStop_BTN);
                //IO_VALUE resetBtn = IOValue(IO_Type.Reset_BTN);

                //急停按钮 
                if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
                {
                    return;
                }
                else if (IOValue(IO_Type.Reset_BTN).Equals(IO_VALUE.HIGH))
                {
                    //收到复位信号,若报警直接复位,若不报警且无操作,回到待机点
                    if (alarmType.Equals(AlarmType.None) && isInSuddenDown.Equals(false) && isNoAirCheck.Equals(false))
                    {
                        if (MoveInfo.MoveType.Equals(MoveType.None))
                        {
                            LogUtil.info(Name + "收到复位信号,当前无报警,且空闲中,暂不处理"); 
                        }
                        else
                        {
                            LogUtil.info(Name + "收到复位信号,当前无报警, 在" + MoveInfo.MoveType + "处理中,不处理复位");
                        }
                    }
                    else
                    {
                        //收到复位信号
                        LogUtil.info("收到复位信号,自动复位");
                        WarnMsg = "收到复位信号,自动复位";
                        Reset();
                    }
                }
                AirCheckProcess();
            }
        }


        public void TimerProcess()
        {
            try
            {
                DateTime time = DateTime.Now;
                if (MoveInfo.MoveType != MoveType.None)
                {
                    BusyMoveProcess();
                    ShowTimeLog("BusyMoveProcess");
                }
                else if (storeRunStatus.Equals(StoreRunStatus.Runing))
                {
                    ShowTimeLog("判断是否需要出入库");
                    AutoResetProcess();
                    ShowTimeLog("AutoResetProcess");
                    IOTimeOutProcess();
                    ShowTimeLog("IOTimeOutProcess");
                     
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(Name + "定时处理出错" + ex.ToString());
            }
        }

        private DateTime preIoTimerOutTime = DateTime.Now;
        /// <summary>
        /// io检测异常
        /// </summary>
        private void IOTimeOutProcess()
        {
            try
            {
                TimeSpan span = DateTime.Now - preIoTimerOutTime;
                if (span.TotalSeconds > 1)
                {
                    preIoTimerOutTime = DateTime.Now;
                    if (!alarmType.Equals(AlarmType.IoSingleTimeOut))
                    {
                        return;
                    }
                    if (storeRunStatus < StoreRunStatus.Runing || isInSuddenDown || isNoAirCheck)
                    {
                        return;
                    }
                    //若BOX和移栽都没有在等待Io的过程中则此Io超时异常可能已经处理过
                    if (MoveInfo.IsInWait == false)
                    {
                        LogUtil.info(Name + "之前有IO超时异常【" + alarmInfo.alarmDetail + "】,但是当前已经没有在等待中,清理信号超时异常!");
                        alarmType = AlarmType.None;
                        WarnMsg = "";
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(Name + "IOTimeOutProcess出错:" + ex.ToString());
            }
        }

        /// <summary> 
        /// 超过配置次数时需要复位
        /// </summary>
        private void AutoResetProcess()
        {
            try
            {
                bool noInStore = true;
                if (AutoInout.CurrInOutACount >= StoreManager.Config.Box_ResetACount && noInStore)
                {
                    if (storeRunStatus < StoreRunStatus.Runing || MoveInfo.MoveType == MoveType.InStore || MoveInfo.MoveType == MoveType.OutStore)
                    {
                    //    LogInfo("已经累计出入库" + AutoInout.CurrInOutACount + "次,当时当前正在忙碌中暂不复位");
                    }
                    else
                    {
                        LogInfo("已经累计出入库" + AutoInout.CurrInOutACount + "次,需要复位一下");
                        Reset();
                    }
                    return;
                }
                else if (waitOutStoreList.Count > 0)
                {
                    InOutParam param = null;
                    bool result = waitOutStoreList.TryDequeue(out param);
                    if (result && param != null)
                    {  
                        LogInfo("执行排队的出库【" + param.ToStr() + "】");
                        StartExecuctOut(param); 
                    }
                }
            }
            catch (Exception ex)
            {
                LogUtil.error(Name + "处理出入库排队列表出错:" + ex.ToString());
            }
        }
        

        /// <summary>
        /// 判断是否报警,返回 true表示报警  报警检测2秒钟检测一次
        /// </summary>
        /// <returns></returns>
        private DateTime checkAlarmTime = DateTime.Now;
        public bool CheckAxisAlarm()
        {
            if (alarmType.Equals(AlarmType.AxisAlarm) || alarmType.Equals(AlarmType.AxisMoveError))
            {
                return true;
            }
            TimeSpan span = DateTime.Now - checkAlarmTime;
            //在回原点,复位,出入库时,检测报警间隔减小
            if ((storeRunStatus.Equals(StoreRunStatus.Runing) && span.TotalSeconds < 3) || span.TotalSeconds < 1)
            {
                return false;
            }
            checkAlarmTime = DateTime.Now;
            bool isInAlarm = false;

            foreach (ConfigMoveAxis axisInfo in moveAxisList)
            {
                short axis = axisInfo.GetAxisValue();
                string deviceName = axisInfo.GetNameStr();

                if (ACServerManager.GetAlarmStatus(deviceName, axis) == 1)
                {
                    WarnMsg = Name + " 运动轴" + axisInfo.Explain + "报警";
                    Alarm(AlarmType.AxisAlarm, GetAlarmCodeByAxis(axisInfo).ToString(), WarnMsg, MoveType.None);
                    isInAlarm = true;
                }
            }
            //判断报警状态
            return isInAlarm;
        }

        /// <summary>
        /// 停止所有运行
        /// </summary>
        public override void StopMove()
        {  
            IOMove(IO_Type.UpdownAxis_Break, IO_VALUE.LOW);
            MoveInfo.EndMove();
            IOMove(IO_Type.UpdownAxis_Break, IO_VALUE.LOW);
            //运动版停止 
            ACServerManager.SuddenStop(Config.Middle_Axis.DeviceName, Config.Middle_Axis.GetAxisValue());
            ACServerManager.SuddenStop(Config.UpDown_Axis.DeviceName, Config.UpDown_Axis.GetAxisValue());
            ACServerManager.SuddenStop(Config.InOut_Axis.DeviceName, Config.InOut_Axis.GetAxisValue());
            ACServerManager.SuddenStop(Config.Comp_Axis.DeviceName, Config.Comp_Axis.GetAxisValue());
            CloseAllAxis();
            LogInfo("StopMove");
            isInPro = false;
        }
         
        private void MoveEndToRuningStatus()
        { 
            MoveInfo.EndMove();
            storeRunStatus = StoreRunStatus.Runing;
            storeStatus = StoreStatus.StoreOnline;
            if (alarmType.Equals(AlarmType.None))
            {
                WarnMsg = "";
            }
        }
    
        public void LineRun()
        {
            IOMove(IO_Type.Line_BackRun, IO_VALUE.LOW);
            IOMove(IO_Type.Line_Run, IO_VALUE.HIGH);
        }
        public void LineBackRun()
        {
            IOMove(IO_Type.Line_Run, IO_VALUE.LOW);
            IOMove(IO_Type.Line_BackRun, IO_VALUE.HIGH);
        }
        public void LineStop()
        {
            IOMove(IO_Type.Line_BackRun, IO_VALUE.LOW);
            IOMove(IO_Type.Line_Run, IO_VALUE.LOW);
        }
        public string GetMoveStr()
        {
            string msg = "";
            msg += "状态: " + storeRunStatus + "   " + storeStatus + "\n";
            //  msg += "lineS: " + storeStatus + "\n";
            msg += "报警:  " + alarmType + "\n";
            msg += MoveInfo.MoveType + " " + MoveInfo.SLog + "\n"; 
            return msg;
        }
    }
}