DischargeLine.cs 13.4 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 DischargeLine : EquipBase
    {

        public DischargeLine_Config Config;
  
        public DischargeLine(string cid, DischargeLine_Config config)
        {
            baseConfig = config;
            this.DeviceID = config.Id;
            this.Config = config;
            IsDebug = config.IsDebug.Equals(1);
            baseConfig = config;
            Name = (" " + "_出料皮带线_" + DeviceID % 100 + " ").ToUpper(); 
            Init();
            UseAxis = false;
            MoveInfo = new LineMoveInfo(DeviceID, "出料皮带线-" + DeviceID + "-MoveInfo");
            SecondMoveInfo = new LineMoveInfo(DeviceID, "出料皮带线-" + DeviceID + "-SecondMoveInfo"); 
        }

        /// <summary>
        /// 开始运行
        /// </summary>
        public override bool StartRun(bool isDebug = false)
        {
            preTrayNum = 0;
            currMoveTrayNum = 0;
            mainTimer.Enabled = false;
            MoveInfo.EndMove();
            SecondMoveInfo.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()
        {
            //  preTrayNum = 0;
            //   currMoveTrayNum = 0;
            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 (isInPro)
            {
                return;
            }
            isInPro = true;
            try
            {
                if (IsDebug)
                {
                    isInPro = false;
                    return;
                }

                BusyMoveProcess();
                //判断流水线打开了才可以运行 
                if (SecondMoveInfo.MoveType.Equals(LineMoveType.None))
                {
                    LineBean lineBean = LineManager.Line;
                    if (lineBean.isCanProcessLine() && IOManager.IOValue(IO_Type.DriveMotor_Run, 0).Equals(IO_VALUE.HIGH) && lineBean.runStatus >= LineRunStatus.Runing && lineBean.IsSleep.Equals(false))
                    {
                        StartCheckFixture();
                    }
                }
                IOTimeOutProcess();
            }
            catch (Exception ex)
            {
                LogUtil.error(Name + "TimerProcess出错:" + ex.ToString());
            }

            isInPro = false;
        }

     

        /// <summary>
        /// 出料装置原点返回
        /// </summary>
        public bool ReturnHome()
        {
            mainTimer.Stop();

            alarmType = LineAlarmType.None;
            runStatus = LineRunStatus.HomeMoving;
            LogInfo("开始原点返回:  (上下气缸回原点,阻挡气缸输入=0  )开始");
            MoveInfo.NewMove(LineMoveType.ReturnHome);
            //移载装置原点状态:顶升气缸下降端,前后气缸后退端,上下气缸上升端,夹料气缸放松端,阻挡气缸输入=0     

            CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
            if (IsDebug)
            {
                IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
                IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
            }
            else
            {
                IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
                IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
            }
            return true;
        }
        /// <summary>
        /// 出料装置重置
        /// </summary>
        public override bool Reset()
        {
            WarnMsg = "";

            //如果正在出库中,需要减去托盘号
            if (MoveInfo.MoveType.Equals(LineMoveType.OutStore))
            {
                //LogInfo("重置之前发现在出库执行中,减去托盘数;");
                //减去需要的盘数
                //TrayManager.DelNeedEmptyTrayNum();
                MoveInfo.EndMove();
            }

            alarmType = LineAlarmType.None;
            //重置时清理盘号,从头开始判断
            //    preTrayNum = 0;
            //   currMoveTrayNum = 0;
            LogInfo("开始重置:清零上一个托盘号,(上下气缸回原点,阻挡气缸输入=0  )开始;");
            runStatus = LineRunStatus.Reset;
            SecondMoveInfo.EndMove();
            MoveInfo.NewMove(LineMoveType.Reset);

            CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
            if (IsDebug)
            {
                IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
                IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
            }
            else
            {
                IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
                IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
            }
            isInPro = false;
            return true;
        }

        /// <summary>
        /// 重置处理
        /// </summary>
        protected override void ResetProcess()
        {
            if (MoveInfo.IsInWait)
            {
                CheckWait(MoveInfo);
            }
            else if (SecondMoveInfo.IsInWait)
            {
                CheckWait(SecondMoveInfo);
            }
            if (!MoveInfo.IsInWait && !SecondMoveInfo.IsInWait)
            {
                //流水线各装置复原位,夹料气缸状态不变
                //阻挡气缸全部=0
                //上下气缸上升,、
                //上升到位,顶升气缸下降,前后气缸回退
                //复位时夹紧气缸需要发送,不然后面出入库会有问题
                switch (MoveInfo.MoveStep)
                {
                    case LineMoveStep.MH_UpDownHomeMove:
                        MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
                        LogInfo("重置:  (上下轴原点返回完成,上下轴走到待机点  )开始");
                        //  UpdownUpMove();
                        break;
                    case LineMoveStep.MH_UpDownCylinder_Up:

                        MoveInfo.NextMoveStep(LineMoveStep.MH_OtherCylinder_Back);
                        LogInfo("重置:  (上升到位,顶升气缸下降,前后气缸回退  )开始");
                        CylinderMove(MoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
                        CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
                        CylinderMove(MoveInfo, IO_Type.ClampCylinder_Slack, IO_Type.ClampCylinder_Tighten);
                        break;

                    case LineMoveStep.MH_OtherCylinder_Back:

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

                    default: break;
                }
            }
        }
        /// <summary>
        /// 原点返回处理
        /// </summary>
        protected override void ReturnHomeProcess()
        {
            if (MoveInfo.IsInWait)
            {
                CheckWait(MoveInfo);
            }
            if (SecondMoveInfo.IsInWait)
            {
                CheckWait(SecondMoveInfo);
            }
            if (!MoveInfo.IsInWait && !SecondMoveInfo.IsInWait)
            {
                switch (MoveInfo.MoveStep)
                {
                    case LineMoveStep.MH_UpDownHomeMove:
                        MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
                        LogInfo("原点返回:  (上下轴原点返回完成,上下轴走到待机点  )开始");
                        // UpdownUpMove();
                        break;
                    case LineMoveStep.MH_UpDownCylinder_Up:

                        LogInfo("原点返回:(上升到位,顶升气缸下降,前后气缸回退  )开始");
                        MoveInfo.NextMoveStep(LineMoveStep.MH_OtherCylinder_Back);
                        CylinderMove(MoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
                        CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
                        CylinderMove(MoveInfo, IO_Type.ClampCylinder_Slack, IO_Type.ClampCylinder_Tighten);

                        break;
                    case LineMoveStep.MH_OtherCylinder_Back:

                        MoveInfo.EndMove();
                        SecondMoveInfo.EndMove();
                        LogInfo("原点返回完成!");
                        runStatus = LineRunStatus.Runing;
                        //如果是调试模式,出料装置两个阻挡气缸落下,并且不再移动
                        if (IsDebug)
                        {
                            lineStatus = LineStatus.Debugging;
                        }
                        else
                        {

                            lineStatus = LineStatus.StoreOnline;
                        }
                        break;
                    default: break;
                }
            }
        }

        protected override void StopMoveProcess()
        {
            if (MoveInfo.IsInWait)
            {
                CheckWait(MoveInfo);
            }
            if (SecondMoveInfo.IsInWait)
            {
                CheckWait(SecondMoveInfo);
            }
            if (!MoveInfo.IsInWait && !SecondMoveInfo.IsInWait)
            {
                switch (MoveInfo.MoveStep)
                {
                    //流水线各装置复原位,夹料气缸状态不变                //阻挡气缸全部=0                //上下气缸上升,、                //上升到位,顶升气缸下降,前后气缸回退
                    case LineMoveStep.MH_UpDownCylinder_Up:
                        {
                            MoveInfo.NextMoveStep(LineMoveStep.MH_OtherCylinder_Back);
                            LogInfo("停止运动:  (上升到位,顶升气缸下降,前后气缸回退  )开始");
                            IOMove(IO_Type.UpDownCylinder_Up, IO_VALUE.LOW);

                            CylinderMove(MoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
                            CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
                            break;
                        }
                    case LineMoveStep.MH_OtherCylinder_Back:
                        {
                            LogInfo("停止运行完成!");
                            runStatus = LineRunStatus.Runing;
                            MoveInfo.EndMove();
                            break;
                        }
                    default: break;
                }
            }
        }
        /// <summary>
        /// 停止运动
        /// </summary>
        public override void StopMove()
        {
            //如果正在出库中,需要减去托盘号
            if (MoveInfo.MoveType.Equals(LineMoveType.OutStore))
            {
                LogInfo("停止运动时出库执行中,减去托盘数;");
                //减去需要的盘数
                //   TrayManager.DelNeedEmptyTrayNum();
                MoveInfo.EndMove();
            }
            runStatus = LineRunStatus.Busy;
            SecondMoveInfo.EndMove();

            LogInfo("停止运动:(上下气缸上升端,阻挡气缸输入=0  )开始 ");

            MoveInfo.NewMove(LineMoveType.StopMove);
            MoveInfo.NextMoveStep(LineMoveStep.MH_UpDownCylinder_Up);
            // UpdownUpMove();
            IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
            IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);

        }
 

        public override void  StartInStoreMove(InOutParam param)
        {
            
        }

        protected override void InStoreProcess()
        { 
        }
         
    }
}