ProvidingEquip_Partial.cs 17.2 KB
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
    partial class ProvidingEquip
    {
        #region 托盘检测

        protected override bool CheckWaitResult(WaitResultInfo wait)
        {
            if (wait.WaitType.Equals(WaitEnum.W201_ProvidingCanOut))
            {
                if (MoveInfo.MoveType.Equals(LineMoveType.None))
                {
                    return true;
                }
            }
            else if (wait.WaitType.Equals(WaitEnum.W202_DLineCanOut))
            { 
                bool result = LineManager.Line.DLineStartOut(Config.DLineEquipNum, Config.DLineLineNum); 
                wait.IsEnd = result;
            }
            return false;
        }
      
        private void StartCheckFixture()
        {
            int num = TrayManager.GetTrayNum(DeviceID);
            if (IOValue(IO_Type.StopCylinder_Check2).Equals(IO_VALUE.HIGH))
            {
                //托盘在两个阻挡内
                if (num > 0&& LineManager.Line.SwNoProcess(Config.SidesWayNum))
                {
                    TrayManager.UpdateSWState(Config.SidesWayNum, 2);
                    SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
                    CheckLog("托盘检测(流水线阻挡)SecondMove:(MIO_03_StopCylinder2Down  阻挡气缸1-1上升)");
                    SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_03_StopCylinder2Down);
                    IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
                    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.LOW));
                } 
            }
            else if (IOValue(IO_Type.StopCylinder_Check1).Equals(IO_VALUE.HIGH) && LineManager.Line.SwNoProcess(Config.SidesWayNum))
            {
                //托盘在第一个阻挡处
                SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_01_StopCylinder1Down);
                TrayManager.UpdateSWState(Config.SidesWayNum, 2);
                CheckLog(" 托盘检测:料盘检测 SecondMove(MIO_01_StopCylinder1Down阻挡气缸1-1下降 ,最多等待1秒)");
                IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH));
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1500));
            }
        }
        private bool CheckIsNeedOutStore()
        {
           //TODO 判断是否是需要移栽出料的料盘
            return false;
        }
        protected override void CheckFixtureProcess()
        {
            if (!LineManager.Line.LineCanRun())
            {
                return;
            }
            if (SecondMoveInfo.IsInWait)
            {
                CheckWait(SecondMoveInfo);
            }
            if (SecondMoveInfo.IsInWait)
            {
                return;
            }

            #region 托盘检测
            if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_01_StopCylinder1Down))
            {
                CheckLog("托盘检测(流水线阻挡)SecondMove:(MIO_02_FixtureCheck  阻挡气缸1-1上升,等待 阻挡2托盘检测=1)");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_03_StopCylinder2Down);
                IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.LOW));
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check2, IO_VALUE.HIGH));
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_02_FixtureCheck))
            {
                CheckLog("托盘检测(流水线阻挡)SecondMove:(MIO_03_StopCylinder2Down  阻挡气缸1-1上升)");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_03_StopCylinder2Down);
                IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.LOW);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down1, IO_VALUE.LOW));
                // SecondMoveInfo.EndStepWait();
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_03_StopCylinder2Down))
            {
                CheckLog("托盘检测(流水线阻挡)SecondMove:(MIO_04_Wait ,等待编码信号稳定)");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_04_Wait);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_04_Wait))
            {
                //此处先对托盘号进行验证
                currMoveTrayNum = TrayManager.GetTrayNum(DeviceID);
                bool isFull = TrayManager.IsFixTureFull(currMoveTrayNum);
                if (TrayManager.RightTrayCode(currMoveTrayNum, preTrayNum, false))
                {
                    if (TrayManager.ErrorStoreId.Equals(DeviceID))
                    {
                        TrayManager.UpdateTrayNumError(-1, "");
                    }
                    //出料中,需要拦盘
                    if (CheckIsNeedOutStore())
                    {
                        TrayInfo trayInfo = TrayManager.GetTrayInfo(currMoveTrayNum);
                        InOutParam param = new InOutParam(currMoveTrayNum, trayInfo.WareCode, trayInfo.PosId, trayInfo.PlateH, trayInfo.PlateW);
                        CheckLog("托盘检测(流水线阻挡)是需要出库" + param.ToStr() + ":(MIO_05_WaitTime 等待1秒后顶升上升 )");
                        SecondMoveInfo.MoveParam = param;
                        SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_05_WaitTime);
                        SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                        SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitProvidingEquipCanOut());//等待

                        return;
                    }
                    else
                    {
                        LogInfo(SecondMoveInfo.MoveNum + "***************上个托盘号【" + preTrayNum + "】,当前" + (isFull ? "有料托盘" : "空托盘") + "【" + currMoveTrayNum + "】没有出入料任务,放盘通过~");

                        CheckLog("托盘放行  SecondMove:(MO_14_WaitCanGo ,移栽2,需要判断是否可以放盘通过,最多等待10000)");
                        SecondMoveInfo.NextMoveStep(LineMoveStep.MO_15_WaitCanGo);
                    }
                }
                else
                {
                    string msg = Name + " 托盘顺序错乱,上个托盘号【" + preTrayNum + "】当前托盘号 【" + currMoveTrayNum + "】最大盘号【" + TrayManager.MaxTrayNum + "】";
                    TrayManager.UpdateTrayNumError(DeviceID, msg);
                    LogUtil.error(msg);
                    return;
                } 
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_05_WaitTime))
            {
                CheckLog("托盘检测(流水线阻挡)SecondMove:(MIO_06_TopCylinderUp 顶升气缸上 升 )");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_06_TopCylinderUp);
                CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_Down, IO_Type.TopCylinder_UP);

                //移栽开始出库
                LogInfo("开始新的出库任务~" + SecondMoveInfo.MoveParam.ToStr());
                bool result = StartOutStoreMove(SecondMoveInfo.MoveParam);
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_06_TopCylinderUp))
            {
                SecondMoveInfo.MoveParam = new InOutParam(currMoveTrayNum);
                LogInfo(SecondMoveInfo.MoveNum + "  托盘号【" + currMoveTrayNum + "】等待移栽料盘");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_11_CodeRember);
                SecondMoveInfo.EndStepWait();
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_08_WaitInStore) && MoveInfo.MoveType.Equals(LineMoveType.None))
            {
                CheckLog("托盘放行 SecondMove:(MIO_09_WaitLetFixtureGo ,等待移栽完成后放开阻挡)");
                StartOutStoreMove(SecondMoveInfo.MoveParam);
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_09_WaitLetFixtureGo);
            }
            #endregion

            #region 不需要出出料,直接放行
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MO_14_TopCylinder_Down))
            {
                CheckLog("托盘放行  SecondMove:(MO_14_WaitCanGo ,移栽2,需要判断是否可以放盘通过,最多等待10000)");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_15_WaitCanGo);
                //更新横移托盘已处理完成
                TrayManager.UpdateSWState(Config.SidesWayNum, 1);

            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MO_15_WaitCanGo))
            {
                CheckLog("托盘放行  SecondMove:(MO_15_StopCylinder2_Down ,阻挡气缸1-2下降)");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_16_StopCylinder2_Down);
                IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down2, IO_VALUE.HIGH));
                //  SecondMoveInfo.EndStepWait();
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MO_16_StopCylinder2_Down))
            {
                CheckLog("托盘放行  SecondMove:(MO_16_Tray_Check , 阻挡2托盘检测=0), 延时2秒)");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_17_Tray_Check);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check2, IO_VALUE.LOW));
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MO_17_Tray_Check))
            {
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_18_StopCylinder_Back);
                CheckLog("托盘放行  SecondMove:(MO_17_StopCylinder_Back , 阻挡气缸1-2上升 )");
                IOMove(IO_Type.StopCylinder_Down2, IO_VALUE.LOW);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Down2, IO_VALUE.LOW));
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MO_18_StopCylinder_Back))
            {
                preTrayNum = currMoveTrayNum;
                CheckLog("托盘放行  SecondMove:(托盘放行结束) ");
                // IOMove(IO_Type.StopCylinder_Down1, IO_VALUE.HIGH);
                SecondMoveInfo.EndMove();
            }
            #endregion
        }

        #endregion

        #region 料盘移栽处理
        public override bool StartOutStoreMove(InOutParam param)
        {
            string posId = param != null ? param.PosId : "";
            //调试模式移栽装置不需要有操作
            if (IsDebug)
            {
                LogInfo("需要出料【" + posId + "】处于调试模式,暂时不再进行出出料操作");
                return false;
            }
            if (runStatus.Equals(LineRunStatus.Runing))
            {
                runStatus = LineRunStatus.Busy;
                lineStatus = LineStatus.OutStoreExecute;
                MoveInfo.MoveParam = param;
                MoveInfo.NewMove(LineMoveType.OutStore);
                LogInfo("出料【" + posId + "】处理(移栽):(PO_01_UpDownCylinderDown,上下气缸1下降)");
                MoveInfo.NextMoveStep(LineMoveStep.PO_01_UpDownCylinderDown);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
                CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Up, IO_Type.UpDownCylinder_Down);
                return true;
            }
            else
            {
                LogUtil.error(Name + " 启动出料【" + posId + "】 失败,当前 storeStatus=" + runStatus);
                return false;
            }
        }

        protected override void OutStoreProcess()
        {
            if (MoveInfo.IsInWait)
            {
                CheckWait(MoveInfo);
            }
            if (SecondMoveInfo.IsInWait)
            {
                CheckWait(SecondMoveInfo);
            }
            if (MoveInfo.IsInWait)
            {
                return;
            }
            string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosId : "";
            if (MoveInfo.MoveStep.Equals(LineMoveStep.PO_01_UpDownCylinderDown))
            {
                InStoreLog("出料:(PO_02_UpDownCylinderDownWait,  上下气缸1下降后等待0.3秒再夹紧");
                MoveInfo.NextMoveStep(LineMoveStep.PO_02_UpDownCylinderDownWait);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(300));
            }
            //只有当BOX可以进行出出料时,移栽物品,防止卡住
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.PO_02_UpDownCylinderDownWait))
            {
                InStoreLog("出料:(PO_02_UpDownCylinderDownWait,夹料气缸夹紧)");
                MoveInfo.NextMoveStep(LineMoveStep.PO_03_ClampCylinderSlack);
                CylinderMove(MoveInfo, IO_Type.ClampCylinder_Tighten, IO_Type.ClampCylinder_Slack);
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.PO_03_ClampCylinderSlack))
            {
                InStoreLog("出料:(PO_04_UpDownCylinderUp,上下气缸上升)");
                MoveInfo.NextMoveStep(LineMoveStep.PO_04_UpDownCylinderUp);
                CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.PO_04_UpDownCylinderUp))
            {
                int num = MoveInfo.MoveParam.TrayNumber;
                MoveInfo.NextMoveStep(LineMoveStep.PO_05_WaitBox);
                LogInfo("出料PO_05_WaitBox【" + posId + "】处理(等待可以移栽) 更新盘号【" + num + "】为空盘");
                MoveInfo.WaitList.Add(WaitResultInfo.WaitBoxCanReviceTray());
                TrayManager.UpdateTrayInfo(num );

                //阻挡气缸移动
                InStoreLog("放托盘(放开阻挡):SecondMoveInfo=MO_13_TopCylinder_Down   物品已移走,顶升气缸1下降)");
                SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_14_TopCylinder_Down);
                if (Config.SidesWayNum <= 0)
                {
                    CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
                }
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.PO_05_WaitBox))
            {
                InStoreLog("出料:(PO_06_BeforeAfterCylinderBefore,前后气缸前进)");
                MoveInfo.NextMoveStep(LineMoveStep.PO_06_BeforeAfterCylinderBefore);
                CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_After, IO_Type.BeforeAfterCylinder_Before);
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.PO_06_BeforeAfterCylinderBefore))
            {
                InStoreLog("出料:(PO_07_UpDownCylinderDown ,上下气缸下降)");
                MoveInfo.NextMoveStep(LineMoveStep.PO_07_UpDownCylinderDown);
                CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Up, IO_Type.UpDownCylinder_Down);
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.PO_07_UpDownCylinderDown))
            {
                InStoreLog("出料:  (PO_08_ClampCylinderTighten,夹料气缸放松)");
                MoveInfo.NextMoveStep(LineMoveStep.PO_08_ClampCylinderTighten);
                CylinderMove(MoveInfo, IO_Type.ClampCylinder_Slack, IO_Type.ClampCylinder_Tighten);
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.PO_08_ClampCylinderTighten))
            {
                InStoreLog("出料:(PO_09_UpdownCylinderUp,上下气缸上升)");
                MoveInfo.NextMoveStep(LineMoveStep.PO_09_UpdownCylinderUp);
                CylinderMove(MoveInfo, IO_Type.UpDownCylinder_Down, IO_Type.UpDownCylinder_Up);
            }
            else if (MoveInfo.MoveStep.Equals(LineMoveStep.PO_09_UpdownCylinderUp))
            {
                InStoreLog("出料:(PO_10_BeforeAfterCylinderAfter,前后气缸后退,等待4000 )");
                MoveInfo.NextMoveStep(LineMoveStep.PO_10_BeforeAfterCylinderAfter);
                CylinderMove(MoveInfo, IO_Type.BeforeAfterCylinder_Before, IO_Type.BeforeAfterCylinder_After);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(4000));

                //出料皮带线停止出库
                LineManager.Line.DLineStopOut(Config.DLineEquipNum, Config.DLineLineNum);
            }
         else  if( MoveInfo.MoveStep.Equals(LineMoveStep.PO_10_BeforeAfterCylinderAfter))
            {
                LogInfo("出料【" + posId + "】处理完成!");
                runStatus = LineRunStatus.Runing;
                lineStatus = LineStatus.StoreOnline;
                MoveInfo.EndMove();
            }
        } 
        #endregion

       
    }
}