FeedingEquip.cs 9.9 KB
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 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(); 
            MoveInfo = new LineMoveInfo(DeviceID, "入料-" + DeviceID + "-Move");
            SecondMoveInfo = new LineMoveInfo(DeviceID, "入料-" + DeviceID + "-SecondMove");
            UseAxis = true;
            Config.SetAxisParam();
         
        }

        /// <summary>
        /// 开始运行
        /// </summary>
        public override bool StartRun(bool isDebug = false )
        { 
            mainTimer.Enabled = false;
            MoveInfo.EndMove(); 
            lineStatus = LineStatus.StoreOnline; 
            //TODO 调试时暂时注释
            runStatus = LineRunStatus.HomeMoving;
            bool result = ReturnHome();
            if (result&&isDebug)
            {
                mainTimer.Enabled = true;
            }
            return result;
        }

       
        /// <summary>
        /// 停止运行
        /// </summary>
        public override void StopRun()
        { 
            if (mainTimer != null)
            {
                mainTimer.Enabled = false;
            }
            StopMove();
            //停止运行时,把所有IO 置零
            IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
            IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
            IOMove(IO_Type.TopCylinder_UP, IO_VALUE.LOW);
            IOMove(IO_Type.TopCylinder_Down, IO_VALUE.LOW);
            IOMove(IO_Type.BeforeAfterCylinder_Before, IO_VALUE.LOW);
            IOMove(IO_Type.BeforeAfterCylinder_After, IO_VALUE.LOW);
            IOMove(IO_Type.UpDownCylinder_Up, IO_VALUE.LOW);
            IOMove(IO_Type.UpDownCylinder_Down, IO_VALUE.LOW);
            IOMove(IO_Type.ClampCylinder_Slack, IO_VALUE.LOW);
            IOMove(IO_Type.ClampCylinder_Tighten, IO_VALUE.LOW);
            runStatus = LineRunStatus.Wait;
        }


        public override void TimerProcess()
        {
            if (IOValue(IO_Type.SL_SuddenStop_BTN).Equals(IO_VALUE.LOW))
            {
                WarnMsg = Name + "收到急停信号";
                LogUtil.error(WarnMsg);
                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 (LineManager.Line.CanProcessLine())
                { 
                    StartCheckFixture();
                }
            }
            IOTimeOutProcess();
        }

       

        /// <summary>
        /// 入料装置原点返回
        /// </summary>
        public bool  ReturnHome()
        {
            mainTimer.Stop();
            MoveInfo.EndMove();
            SecondMoveInfo.EndMove();
            if (!RunAxis(true,Config.Batch_Axis))
            {
                return false;
            }
            if (!RunAxis(true, Config.UpDown_Axis))
            {
                return false;
            }

            alarmType = LineAlarmType.None;
            runStatus = LineRunStatus.HomeMoving;
            LogInfo( "开始原点返回:  (上下伺服原点返回,上料伺服原点返回 )开始");
            MoveInfo.NewMove(LineMoveType.ReturnHome);
          
            return true;
        }
        /// <summary>
        /// 入料装置重置
        /// </summary>
        public override bool Reset()
        {
            WarnMsg = ""; 
            MoveInfo.EndMove();
            if (!RunAxis(true, Config.Batch_Axis))
            {
                return false;
            }
            if (!RunAxis(true, Config.UpDown_Axis))
            {
                return false;
            }
            alarmType = LineAlarmType.None; 
            LogInfo("开始重置: (上下伺服原点返回,上料伺服原点返回)开始;");
            runStatus = LineRunStatus.Reset;
            MoveInfo.NewMove(LineMoveType.Reset);
            StartReset();
            return true;
        }
        private void StartReset()
        {
            IOMove(IO_Type.SL_HddLed, IO_VALUE.HIGH);
            MoveInfo.NextMoveStep(LineMoveStep.FR_01_StopCylinderMove);
            ACAxisHomeMove(Config.UpDown_Axis);
            ACAxisHomeMove(Config.Batch_Axis);
            isInPro = false;
        }
        /// <summary>
        /// 重置处理
        /// </summary>
        protected override void ResetProcess()
        {
            ReturnHomeProcess();
        }
        /// <summary>
        /// 原点返回处理
        /// </summary>
        protected  override void ReturnHomeProcess()
        {
            if (MoveInfo.IsInWait)
            {
                CheckWait(MoveInfo);
            } 
            if (!MoveInfo.IsInWait)
            {
                //流水线各装置复原位,夹料气缸状态不变
                //阻挡气缸全部=0
                //上下气缸上升,、
                //上升到位,顶升气缸下降,前后气缸回退
                //复位时夹紧气缸需要发送,不然后面出入库会有问题
                switch (MoveInfo.MoveStep)
                {
                    case LineMoveStep.FR_01_StopCylinderMove:

                        LogInfo(MoveInfo.MoveType + ":开始气缸下降");
                        break;
                    case LineMoveStep.FR_02_LocationCylinderDown:
                        break;
                    case LineMoveStep.FR_03_AxisHomeMove:
                        break;
                    case LineMoveStep.FR_04_AxisToP1:

                        LogInfo("重置完成!");
                        runStatus = LineRunStatus.Runing;
                        MoveInfo.EndMove();
                        break;
                    //TODO 需要继续之前的的出入库处理
                    //ContinueInOutStore();

                    default: break;
                }
            }
        }

        protected override void StopMoveProcess()
        {
            if (MoveInfo.IsInWait)
            {
                CheckWait(MoveInfo);
            }

            if (!MoveInfo.IsInWait)
            {
                switch (MoveInfo.MoveStep)
                { 
                    case LineMoveStep.MH_UpDownCylinder_Up:

                        break;

                    case LineMoveStep.MH_OtherCylinder_Back:

                        break;

                    default: break;
                }
            }
        }
       
        public override void StopMove()
        { 
        } 

        public override bool StartOutStoreMove(InOutParam param)
        {
            return true;
        }

        protected override void OutStoreProcess()
        { 
        } 
        /// <summary>
        /// 是否需要拦截当前托盘进行处理
        /// </summary>
        /// <returns></returns>
        internal bool NeedCurrTray()
        {
            int num = TrayManager.GetNum(Config.Id);
            bool isFull = TrayManager.IsFixTureFull(num);
            if (Config.IsCanOut.Equals(1))
            {
                if (isFull && runStatus.Equals(LineRunStatus.Runing) && MoveInfo.MoveType.Equals(LineMoveType.OutStore))
                {
                    return true;
                }
            }
            else
            {
                if (!isFull && runStatus.Equals(LineRunStatus.Runing) && MoveInfo.MoveType.Equals(LineMoveType.InStore))
                {
                    return true;
                }
            }
            return false;
        }
        /// <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);
            }
        }

    }
}