MainMachine _AutoInOutTest.cs 15.3 KB
using OnlineStore; 
using OnlineStore.LoadCSVLibrary; 
using System.Linq; 

namespace DeviceLibrary
{
    partial class MainMachine
    {
        private bool canStartTest(out string errmsg)
        {
            errmsg = "";
            if (!boxTransport.IgnoreX09 && IOValue(IO_Type.TrayCheck_Fixture).Equals(IO_VALUE.HIGH))
            {
                if (!boxTransport.IgnoreX09 && IOMonitor.IODebound(IO_Type.TrayCheck_Fixture, Config, IO_VALUE.HIGH, 5000))
                {
                    errmsg = crc.GetString("Res0152", "收到任务,但料叉上有料,无法启动,请检查");
                }
                else
                {
                    errmsg = crc.GetString("Res0152", "收到任务,但料叉上有料,无法启动,请检查");
                }
                return false;
            }
            else
            {
                IgnoreGratingSignal = true;
            }
            if (!boxTransport.IsComplateOrFree)
            {
                errmsg = crc.GetString("Res0151", "料仓忙碌中,无法启动");
                return false;
            }
            return true;
        }
        public bool StartAutoTest(string  posName, out string errmsg)
        { 
            if (!canStartTest(out errmsg))
            { 
                return false;
            }
            CurrentPosName = posName;
            CurrStartPos = GetAutoStartPos(1);
            AutoInOutTest = true;
            StopAutoInOut = false;
            CurrentPosIndex = RobotManage.PositionNumList.IndexOf(posName);
            AIOTMoveInfo.NewMove(MoveStep.A01_WaitReel);
            return true;
        }
        public bool ManualTest(string startPos, string posName, out string errmsg)
        { 
            if (!canStartTest(out errmsg))
            {
                return false;
            }
            CurrentPosName = posName;
            CurrentPosIndex = RobotManage.PositionNumList.IndexOf(posName);
            CurrStartPos = startPos;
            AutoInOutTest = false;
            StopAutoInOut = true;
            AIOTMoveInfo.NewMove(MoveStep.A01_Ready);
            AIOTMoveInfo.log($"开始放料任务:" + startPos + "->" + posName);


            return true;
        }
        public void StopAutoInOutTest()
        {
            StopAutoInOut = true;
        }
        private int CurrentPosIndex = 0;
        private string CurrentPosName = "";
        /// <summary>
        /// 自动出入库状态
        /// </summary>
        public bool AutoInOutTest { get; set; } = false;
        bool StopAutoInOut = false;
        string CurrStartPos = "IN_1";

        private string GetAutoStartPos(int count=0)
        {
            if (count == 0)
            {
                if (CurrStartPos.Equals("IN_1"))
                {
                    CurrStartPos = "IN_2";
                }
                else
                {
                    CurrStartPos = "IN_1";
                }
            }
            else
            {
                return CurrStartPos = "IN_" + count;
            }
          
            return CurrStartPos;
        }

        private ACStorePosition getPos(int index)
        {
            if (index <= 0)
            {
                return null;
            }
            CurrentPosName = RobotManage.PositionNumList[index];
            if (!RobotManage.allPositionMap.ContainsKey(CurrentPosName))
            {
                return null;
            }
            ACStorePosition storePosition = RobotManage.allPositionMap[CurrentPosName];
            return storePosition;
        }
        void AutoInOutTestProcess()
        {
            if (CheckWait(AIOTMoveInfo))
                return;
            //常规上料扫码流程
            switch (AIOTMoveInfo.MoveStep)
            {
                case MoveStep.Wait:
                    break;
                case MoveStep.A01_WaitReel:
                    if (IOValue(IO_Type.IN_1_Reel_Check).Equals(IO_VALUE.HIGH))
                    {
                        AIOTMoveInfo.NextMoveStep(MoveStep.A01_Ready);
                        AIOTMoveInfo.log($"料盘1已准备好");
                    }
                    else
                    {
                        Msg.add(crc.GetString("Res0155", "请放入测试料盘1"), MsgLevel.warning);
                    }
                    break;
                case MoveStep.A01_Ready:
                     
                    AIOTMoveInfo.NextMoveStep(MoveStep.A02_StartPutOne);
                    ACStorePosition ac = null;
                    if (string.IsNullOrEmpty(CurrentPosName))
                    {
                        ac = RobotManage.allPositionMap[CurrentPosName];
                    }
                    else
                    {
                        ac = getPos(CurrentPosIndex);
                    }
                    var reel = new ReelParam("auto", ac.BagWidth, ac.BagHigh); 
                    var startPos = RobotManage.allPositionMap[CurrStartPos];
                    if (!boxTransport.Start(new BoxStorePosition(Config, startPos, reel), new BoxStorePosition(Config, ac, reel), StoreMoveType.PutReel))
                    {
                        AIOTMoveInfo.log($"启动运输料盘失败,StopAutoInOut");
                        AutoInOutTest = false;
                        StopAutoInOut = true;
                        return;
                    }
                    AIOTMoveInfo.log($"开始匀速料盘第一盘");
                    break;
                case MoveStep.A02_StartPutOne:
                    if (boxTransport.IsTakedReel)
                    {
                        if (StopAutoInOut)
                        {
                            AIOTMoveInfo.NextMoveStep(MoveStep.A04_WaitOneComplate);
                            AIOTMoveInfo.log($"不在自动测试模式, 直接结束1");
                        }
                        else
                        {
                            AIOTMoveInfo.NextMoveStep(MoveStep.A03_WaitRee2);
                            AIOTMoveInfo.log($"第一盘料盘已取走");
                        }
                    }
                    else
                    {
                        Msg.add(crc.GetString("Res0154", "单料口等待料盘离开."), MsgLevel.info);
                    }
                    break;
                case MoveStep.A03_WaitRee2:
                    if (IOValue(IO_Type.IN_2_Reel_Check).Equals(IO_VALUE.HIGH))
                    {
                        AIOTMoveInfo.NextMoveStep(MoveStep.A04_WaitOneComplate);
                        AIOTMoveInfo.log($"测试料盘2已准备好");
                    }
                    else
                    {
                        Msg.add(crc.GetString("Res0155", "请放入测试料盘2."), MsgLevel.warning);
                    }
                    break;
                case MoveStep.A04_WaitOneComplate:
                    if (boxTransport.IsComplateOrFree)
                    {
                        if (StopAutoInOut)
                        {
                            AIOTMoveInfo.log($"不在自动测试模式, 直接结束2");
                            AIOTMoveInfo.EndMove();
                            return;
                        }
                        AIOTMoveInfo.NextMoveStep(MoveStep.A05_StartPutTwo);
                        AIOTMoveInfo.log($"第一盘料盘已到达目的地");
                        if (CurrentPosIndex - 1 < 0 || StopAutoInOut)
                        {
                            AIOTMoveInfo.log($"已达到最后一个库位:{CurrentPosIndex},或手动停止{StopAutoInOut},自动出入库停止,将料盘送至出口");
                            AIOTMoveInfo.NextMoveStep(MoveStep.A10_LastPos);
                            return;
                        }
                        AIOTMoveInfo.log($"开始匀速料盘第二盘");
                         
                        ac =getPos(CurrentPosIndex-1);
                        reel = new ReelParam("auto", ac.BagWidth, ac.BagHigh);
                        startPos = RobotManage.allPositionMap[GetAutoStartPos()];
                        if (!boxTransport.Start(new BoxStorePosition(Config, startPos, reel), new BoxStorePosition(Config, ac, reel), StoreMoveType.PutReel))
                        {
                            AIOTMoveInfo.log($"启动运输料盘失败,StopAutoInOut");
                            AutoInOutTest = false;
                            StopAutoInOut = true;
                            return;
                        }
                    }
                    break;
                case MoveStep.A05_StartPutTwo:
                    if (boxTransport.IsTakedReel)
                    {
                        AIOTMoveInfo.NextMoveStep(MoveStep.A06_WaitTwoEnd);
                        AIOTMoveInfo.log($"第二盘料盘已取走");
                    }
                    else
                    {
                        Msg.add(crc.GetString("Res0154", "单料口等待料盘离开."), MsgLevel.info);
                    }
                    break;
                case MoveStep.A06_WaitTwoEnd:
                    if (boxTransport.IsComplateOrFree)
                    {
                        AIOTMoveInfo.log($"第二盘料盘已到达目的地");
                        if (CurrentPosIndex - 1 < 0 || StopAutoInOut)
                        {
                            AIOTMoveInfo.log($"已达到最后一个库位:{CurrentPosIndex},或手动停止{StopAutoInOut},自动出入库停止,将料盘送至出口");
                            AIOTMoveInfo.NextMoveStep(MoveStep.A10_LastPos);
                            return;
                        }
                        AIOTMoveInfo.NextMoveStep(MoveStep.A07_NextPos);
                    }
                    break;
                case MoveStep.A07_NextPos:
                    if (boxTransport.IsComplateOrFree)
                    {
                        AIOTMoveInfo.NextMoveStep(MoveStep.A8_WaitPosEnd); 
                        if (CurrentPosIndex - 2 < 0 || StopAutoInOut)
                        {
                            AIOTMoveInfo.log($"A已达到最后一个库位:{CurrentPosIndex},或手动停止{StopAutoInOut},自动出入库停止,将料盘送至出口");
                            AIOTMoveInfo.NextMoveStep(MoveStep.A10_LastPos);
                            CurrentPosIndex++;
                            return;
                        }
                        var ac1 = getPos(CurrentPosIndex);
                        var ac2 =getPos(CurrentPosIndex - 2);
                        reel = new ReelParam("auto", ac2.BagWidth, ac2.BagHigh);
                        if (!boxTransport.Start(new BoxStorePosition(Config, ac1, reel), new BoxStorePosition(Config, ac2, reel), StoreMoveType.PutReel))
                        {
                            AIOTMoveInfo.log($"启动运输料盘失败,StopAutoInOut");
                            AutoInOutTest = false;
                            StopAutoInOut = true;
                            return;
                        }
                        AIOTMoveInfo.log($"开始交替:【{ac1.PositionNum}】->【{ac2.PositionNum}】");
                    }
                    break;
                case MoveStep.A8_WaitPosEnd:
                    if (boxTransport.IsComplateOrFree)
                    {
                        AIOTMoveInfo.log($"料盘已到达目的地");
                        if (CurrentPosIndex - 1 < 0 || StopAutoInOut)
                        {
                            AIOTMoveInfo.log($"已达到最后一个库位:{CurrentPosIndex},或手动停止{StopAutoInOut},自动出入库停止,将料盘送至出口");
                            AIOTMoveInfo.NextMoveStep(MoveStep.A10_LastPos);
                            return;
                        }
                        CurrentPosIndex--;
                        AIOTMoveInfo.NextMoveStep(MoveStep.A07_NextPos);
                        AIOTMoveInfo.log($"CurrentPosIndex={CurrentPosIndex}");
                    }
                    break;
                case MoveStep.A10_LastPos:
                    AIOTMoveInfo.NextMoveStep(MoveStep.A11_R1StartBack);
                    CurrentPosIndex--;
                    CurrStartPos = GetAutoStartPos(1);
                    ACStorePosition start1 = RobotManage.allPositionMap[CurrStartPos];
                    ac = getPos(CurrentPosIndex );
                    reel = new ReelParam("auto", ac.BagWidth, ac.BagHigh);
                    if (!boxTransport.Start(new BoxStorePosition(Config, ac, reel), new BoxStorePosition(Config, start1, reel), StoreMoveType.OutStore))
                    {
                        AIOTMoveInfo.log($"启动运输料盘失败,StopAutoInOut");
                        AutoInOutTest = false;
                        StopAutoInOut = true;
                        return;
                    }
                    AIOTMoveInfo.log($"开始运送料盘【{ac.PositionNum}】->【{start1.PositionNum}】");
                    break;
                case MoveStep.A11_R1StartBack:
                    if (boxTransport.IsPutOnOut)
                    {
                        AIOTMoveInfo.NextMoveStep(MoveStep.A12_WR1End);
                        AIOTMoveInfo.log($"料盘已到达目的地");
                        //AutoInOutTest = false;
                    }
                    break;
                case MoveStep.A12_WR1End:
                    if (boxTransport.IsComplateOrFree)
                    {
                        AIOTMoveInfo.NextMoveStep(MoveStep.A13_R1End);
                        AIOTMoveInfo.log($"料盘已到取走");
                        //AutoInOutTest = false;
                    }
                    break; 
                case MoveStep.A13_R1End:
                    AIOTMoveInfo.NextMoveStep(MoveStep.A15_StartR2Back);
                    CurrStartPos = GetAutoStartPos(2);
                    ACStorePosition start2 = RobotManage.allPositionMap[CurrStartPos];
                    ac = RobotManage.allPositionMap.Values.ToArray()[CurrentPosIndex - 1];
                    reel = new ReelParam("auto", ac.BagWidth, ac.BagHigh);
                    if (!boxTransport.Start(new BoxStorePosition(Config, ac, reel), new BoxStorePosition(Config, start2, reel), StoreMoveType.OutStore))
                    {
                        AIOTMoveInfo.log($"启动运输料盘失败,StopAutoInOut");
                        AutoInOutTest = false;
                        StopAutoInOut = true;
                        return;
                    }
                    AIOTMoveInfo.log($"开始运送料盘【{ac.PositionNum}】->【{start2.PositionNum}】");
                    break;
                case MoveStep.A15_StartR2Back:
                    if (boxTransport.IsPutOnOut)
                    {
                        AIOTMoveInfo.log($"料盘已到达目的地");
                        AIOTMoveInfo.NextMoveStep(MoveStep.A15_R2End);
                    }
                    break;
                case MoveStep.A15_R2End:
                    if (boxTransport.IsComplateOrFree)
                    {
                        AIOTMoveInfo.log($"料盘已取走");
                        AIOTMoveInfo.EndMove();
                        AutoInOutTest = false;
                    }
                    break;
                default:
                    AIOTMoveInfo.log($"未找到对应步骤:{AIOTMoveInfo.MoveStep}");
                    break;
            }
        }
    }
}