ProvidingEquip_Partial.cs 19.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 托盘检测
        private void StartCheckFixture()
        {
            int num = TrayManager.GetNum(DeviceID);
            if (IOValue(IO_Type.StopCylinder_Check2).Equals(IO_VALUE.HIGH))
            {
                //托盘在两个阻挡内
                if (num > 0)
                {
                    SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
                    CheckLog("托盘检测(流水线阻挡)SecondStoreMove:(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
                {
                    LogUtil.error(Name + "检测到check4亮,但是为获取到托盘号,StartCheckFixture失败~");
                }
            }
            else if (IOValue(IO_Type.StopCylinder_Check1).Equals(IO_VALUE.HIGH))
            {
                //托盘在第一个阻挡处
                SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_01_StopCylinder1Down);
                CheckLog(" 托盘检测:料盘检测 SecondStoreMove(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.isCanProcessLine())
            {
                return;
            }
            if (SecondMoveInfo.IsInWait)
            {
                CheckWait(SecondMoveInfo);
            }
            if (SecondMoveInfo.IsInWait)
            {
                return;
            }

            #region 托盘检测
            if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_01_StopCylinder1Down))
            {
                CheckLog("托盘检测(流水线阻挡)SecondStoreMove:(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("托盘检测(流水线阻挡)SecondStoreMove:(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("托盘检测(流水线阻挡)SecondStoreMove:(MIO_04_Wait ,等待编码信号稳定)");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_04_Wait);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(500));
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_04_Wait))
            {
                try
                {
                    
                    //判断是否需要顶升
                    bool isNeed = false;
                    //此处先对托盘号进行验证
                    currMoveTrayNum = TrayManager.GetNum(DeviceID);
                    bool isFull = TrayManager.IsFixTureFull(currMoveTrayNum);
                    if (TrayManager.RightTrayCode(currMoveTrayNum, preTrayNum, false))
                    {
                        //出料中,需要拦盘
                        if (CheckIsNeedOutStore())
                        {
                            //preTrayNum = currMoveTrayNum;
                            SecondMoveInfo.MoveParam = new InOutParam(currMoveTrayNum);
                            SecondMoveInfo.NextMoveStep(LineMoveStep.MO_05_CodeRember);
                            SecondMoveInfo.EndStepWait();
                            return;
                        } 
                    }
                    else
                    {
                        string msg = Name + " 托盘顺序错乱,上个托盘号【" + preTrayNum + "】当前托盘号 【" + currMoveTrayNum + "】最大盘号【" + TrayManager.MaxTrayNum + "】";
                        TrayManager.UpdateTrayNumError(DeviceID, msg);
                        LogUtil.error(msg);
                        return;
                    }
                    if (isNeed)
                    {
                        CheckLog("托盘检测(流水线阻挡)SecondStoreMove:(MIO_05_WaitTime 等待一秒钟)");
                        SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_05_WaitTime);
                        SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(200));
                    }
                    else
                    {
                        LogInfo(SecondMoveInfo.MoveNum + "***************上个托盘号【" + preTrayNum + "】,当前" + (isFull ? "有料托盘" : "空托盘") + "【" + currMoveTrayNum + "】没有出出料任务,放盘通过~");
                        //  preTrayNum = currMoveTrayNum;
                        if (TrayManager.ErrorStoreId.Equals(DeviceID))
                        {
                            TrayManager.UpdateTrayNumError(-1, "");
                        }
                        CheckLog("托盘放行  SecondStoreMove:(MO_07_WaitCanGo ,移栽2,需要判断是否可以放盘通过,最多等待10000)");
                        SecondMoveInfo.NextMoveStep(LineMoveStep.MO_07_WaitCanGo);
                        //if (DeviceID.Equals(2))
                        //{
                        //    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(10000));
                        //    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitSideWay());
                        //    SecondMoveInfo.OneWaitCanEndStep = true;
                        //}
                    }
                }
                catch (Exception ex)
                {
                    LogUtil.error("判断托盘是否需要顶升出错:" + ex.ToString());
                }
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_05_WaitTime))
            {
                CheckLog("托盘检测(流水线阻挡)SecondStoreMove:(MIO_06_TopCylinderUp 顶升气缸上 升 )");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_06_TopCylinderUp);
                CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_Down, IO_Type.TopCylinder_UP);
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_06_TopCylinderUp))
            {
                CheckLog("托盘检测(流水线阻挡)SecondStoreMove:(MIO_07_TopCylinderUpWait ,顶升气缸上升时等待1秒钟,再下降)");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_07_TopCylinderUpWait);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_07_TopCylinderUpWait))
            {
                CheckLog("托盘检测(流水线阻挡)*************** 托盘号【" + currMoveTrayNum + "】");

                //托盘号正确
                //preTrayNum = num; 
                //判断盘是空盘,空盘并且编号正确才需要放料盘过去
                if (CheckIsNeedOutStore())
                {
                    SecondMoveInfo.MoveParam = new InOutParam(currMoveTrayNum); 
                    LogInfo(SecondMoveInfo.MoveNum + "*************** 托盘号【" + currMoveTrayNum + "】可以放出料托盘,正在出料中,移栽料盘");
                    SecondMoveInfo.NextMoveStep(LineMoveStep.MO_05_CodeRember);
                    SecondMoveInfo.EndStepWait();
                }
               else 
                {
                    //preTrayNum = num;
                    if (TrayManager.ErrorStoreId.Equals(DeviceID))
                    {
                        TrayManager.UpdateTrayNumError(-1, "");
                    }
                    CheckLog("托盘检测 SecondStoreMove:(MO_09_TopCylinder_Down ,托盘号【" + currMoveTrayNum + "】,直接放盘通过,顶升气缸下降)");
                    SecondMoveInfo.NextMoveStep(LineMoveStep.MO_06_TopCylinder_Down);
                    CylinderMove(SecondMoveInfo, IO_Type.TopCylinder_UP, IO_Type.TopCylinder_Down);
                }

            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MIO_08_WaitInStore) && MoveInfo.MoveType.Equals(LineMoveType.None))
            {
                CheckLog("托盘放行 SecondStoreMove:(MIO_09_WaitLetFixtureGo ,等待移栽完成后放开阻挡)");
                StartOutStoreMove(SecondMoveInfo.MoveParam);
                SecondMoveInfo.NextMoveStep(LineMoveStep.MIO_09_WaitLetFixtureGo);
            }
            #endregion

            #region 不需要出出料,直接放行
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MO_06_TopCylinder_Down))
            {
                CheckLog("托盘放行  SecondStoreMove:(MO_07_WaitCanGo ,移栽2,需要判断是否可以放盘通过,最多等待10000)");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_07_WaitCanGo);
                if (DeviceID.Equals(2))
                {
                    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(10000));
                    SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitSideWay());
                    SecondMoveInfo.OneWaitCanEndStep = true;
                }

            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MO_07_WaitCanGo))
            {
                CheckLog("托盘放行  SecondStoreMove:(MO_10_StopCylinder2_Down ,阻挡气缸1-2下降)");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_10_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_10_StopCylinder2_Down))
            {
                CheckLog("托盘放行  SecondStoreMove:(MO_11_Tray_Check , 阻挡2托盘检测=0), 延时2秒)");
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_11_Tray_Check);
                SecondMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.StopCylinder_Check2, IO_VALUE.LOW));
            }
            else if (SecondMoveInfo.MoveStep.Equals(LineMoveStep.MO_11_Tray_Check))
            {
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_12_StopCylinder_Back);
                CheckLog("托盘放行  SecondStoreMove:(MO_12_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_12_StopCylinder_Back))
            {
                preTrayNum = currMoveTrayNum;
                CheckLog("托盘放行  SecondStoreMove:(托盘放行结束) ");
                // 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.UpdateFixtureValue(num, false, 0);

                //阻挡气缸移动
                InStoreLog("放托盘(放开阻挡):SecondStoreMove=MO_09_TopCylinder_Down   物品已移走,顶升气缸1下降)");
                SecondMoveInfo.NewMove(LineMoveType.CheckFixture);
                SecondMoveInfo.NextMoveStep(LineMoveStep.MO_06_TopCylinder_Down);
                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));
            }
         else  if( MoveInfo.MoveStep.Equals(LineMoveStep.PO_10_BeforeAfterCylinderAfter))
            {
                LogInfo("出料【" + posId + "】处理完成!");
                runStatus = LineRunStatus.Runing;
                lineStatus = LineStatus.StoreOnline;
                MoveInfo.EndMove();
            }
        } 
        #endregion

        private void CheckLog(string msg)
        {
            LogUtil.debug(Name + msg);
        }
        private void InStoreLog(string msg)
        {
            string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosId : "";
            LogUtil.info(Name + "【" + posId + "】" + msg);
        }
        private void OutStoreLog(string msg)
        {
            string posId = MoveInfo.MoveParam != null ? MoveInfo.MoveParam.PosId : "";
            LogUtil.info(Name + "【" + posId + "】" + msg);
        }
         
    }
}