MainMachine _AutoInOutTest.cs 16.2 KB
using CodeLibrary;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DeviceLibrary
{
    partial class MainMachine
    {
        public bool StartAutoInOutTest(string posname, out string errmsg)
        {
            errmsg = "";
            if (!boxTransport.IsComplateOrFree)
            {
                errmsg = crc.GetString("Res0002", "料仓忙碌中,无法启动");
                return false;
            }
            //if (!IsAIOTestReelIsReady)
            //{
            //    errmsg = crc.GetString("Res0003", "入库料盘没有准备好,无法启动");
            //    return false;
            //}


            poslist = RobotManage.PositionNumList.Select(a => { return CSVPositionReader<ACStorePosition>.allPositionMap[a]; }).ToList();//CSVPositionReader<ACStorePosition>.getPositionList();
            poslist.RemoveAll(x => { return x.PositionNum.StartsWith("fix#"); });
            CurrentPosIndex = poslist.FindIndex(x => x.PositionNum == posname);
            AutoInOutTest = true;
            StopAutoInOut = false;
            AIOTMoveInfo.NextMoveStep(MoveStep.AIOTest_Start);
            return true;
        }
        public void StopAutoInOutTest()
        {
            StopAutoInOut = true;
        }
        List<ACStorePosition> poslist;
        int CurrentPosIndex = 0;
        /// <summary>
        /// 自动出入库状态
        /// </summary>
        public bool AutoInOutTest { get; set; } = false;
        bool StopAutoInOut = false;
        void AutoInOutTestProcess()
        {
            if (CheckWait(AIOTMoveInfo))
                return;
            //常规上料扫码流程
            switch (AIOTMoveInfo.MoveStep)
            {
                case MoveStep.Wait:

                    break;
                case MoveStep.AIOTest_Start:
                    AIOTMoveInfo.NextMoveStep(MoveStep.AIOTest_01_CloseFlip);
                    OpenSingleDoor(AIOTMoveInfo);
                    CloseFlipDoor(AIOTMoveInfo);
                    AIOTMoveInfo.log($"打开单料门、关闭翻板门");
                    break;
                case MoveStep.AIOTest_01_CloseFlip:
                    AIOTMoveInfo.NextMoveStep(MoveStep.AIOTest_02_Pause1);
                    AIOTMoveInfo.log($"库位测试,放第一盘料");
                    RobotManage.UserPause();
                    break;
                case MoveStep.AIOTest_02_Pause1:
                    AIOTMoveInfo.NextMoveStep(MoveStep.AIOTest_03_FirstReady);
                    var ac = poslist[CurrentPosIndex];
                    var reel = new ReelParam("auto", ac.BagWidth, ac.BagHigh);
                    if (!boxTransport.Start(new BoxStorePosition(Config, StoreSide.NGDoor, reel), new BoxStorePosition(Config, ac, reel), StoreMoveType.InStore))
                    {
                        AIOTMoveInfo.log($"料仓周转启动失败");
                        AutoInOutTest = false;
                        StopAutoInOut = true;
                        return;
                    }
                    AIOTMoveInfo.log($"开始转运料盘第一盘");
                    break;

                case MoveStep.AIOTest_03_FirstReady:
                    if (boxTransport.IsTakedReel)
                    {
                        AIOTMoveInfo.NextMoveStep(MoveStep.AIOTest_04_FirstPuted);
                        ReelTaked();
                        AIOTMoveInfo.log($"第一盘料盘已取走");
                    }
                    else
                    {
                        Msg.add(crc.GetString(L.wait_reel_transfer, "单料口等待料盘离开."), MsgLevel.info);
                    }
                    break;
                case MoveStep.AIOTest_04_FirstPuted:
                    if (boxTransport.IsComplateOrFree)
                    {
                        AIOTMoveInfo.NextMoveStep(MoveStep.AIOTest_05_Pause2);
                        AIOTMoveInfo.log($"第一盘料盘已到达目的地");
                        if (CurrentPosIndex - 1 < 0 || StopAutoInOut)
                        {
                            AIOTMoveInfo.log($"已达到最后一个库位:{CurrentPosIndex},或手动停止{StopAutoInOut},自动出入库停止,将料盘送至出口");
                            AIOTMoveInfo.NextMoveStep(MoveStep.StoreOut10);
                            CloseFlipDoor(AIOTMoveInfo);
                            return;
                        }
                        CloseFlipDoor(AIOTMoveInfo);
                    }
                    break;
                case MoveStep.AIOTest_05_Pause2:
                    AIOTMoveInfo.NextMoveStep(MoveStep.AIOTest_06_SecondReady);
                    RobotManage.UserPause();
                    AIOTMoveInfo.log($"库位测试,放第二盘料");
                    break;
                case MoveStep.AIOTest_06_SecondReady:
                    AIOTMoveInfo.NextMoveStep(MoveStep.StoreIn05);
                    AIOTMoveInfo.log($"开始转运料盘第二盘");
                    ac = poslist[CurrentPosIndex - 1];
                    reel = new ReelParam("auto", ac.BagWidth, ac.BagHigh);
                    if (!boxTransport.Start(new BoxStorePosition(Config, StoreSide.NGDoor, reel), new BoxStorePosition(Config, ac, reel), StoreMoveType.InStore))
                    {
                        AIOTMoveInfo.log($"料仓周转启动失败");
                        AutoInOutTest = false;
                        StopAutoInOut = true;
                        return;
                    }
                    break;
                //case MoveStep.StoreIn01:
                //    //AIOTMoveInfo.NextMoveStep(MoveStep.StoreIn02);
                //    //var ac = poslist[CurrentPosIndex];
                //    //var reel = new ReelParam("auto", ac.BagWidth, ac.BagHigh);
                //    //if (!boxTransport.Start(new BoxStorePosition(Config, StoreSide.NGDoor, reel), new BoxStorePosition(Config, ac, reel), StoreMoveType.InStore))
                //    //{
                //    //    AIOTMoveInfo.log($"料仓周转启动失败");
                //    //    AutoInOutTest = false;
                //    //    StopAutoInOut = true;
                //    //    return;
                //    //}
                //    //AIOTMoveInfo.log($"开始转运料盘第一盘");
                //    break;
                //case MoveStep.StoreIn02:
                //    //if (boxTransport.IsTakedReel)
                //    //{
                //    //    AIOTMoveInfo.NextMoveStep(MoveStep.StoreIn03);
                //    //    ReelTaked();
                //    //    AIOTMoveInfo.log($"第一盘料盘已取走");
                //    //}
                //    //else
                //    //{
                //    //    Msg.add(crc.GetString(L.wait_reel_transfer, "单料口等待料盘离开."), MsgLevel.info);
                //    //}
                //    break;
                //case MoveStep.StoreIn03:
                //    //if (Setting_Init.Device_AIOTest_DirectGetReel)
                //    //{
                //    //    AIOTMoveInfo.NextMoveStep(MoveStep.StoreIn04);
                //    //    CloseFlipDoor(AIOTMoveInfo);
                //    //    AIOTMoveInfo.log($"合拢翻转板,准备料盘");
                //    //}
                //    //else if (IsAIOTestReelIsReady)
                //    //{
                //    //    AIOTMoveInfo.NextMoveStep(MoveStep.StoreIn04);
                //    //    AIOTMoveInfo.log($"入库料盘已准备好");
                //    //}
                //    break;
                //case MoveStep.StoreIn04:
                //    //if (boxTransport.IsComplateOrFree)
                //    //{
                //    //    AIOTMoveInfo.NextMoveStep(MoveStep.StoreIn05);
                //    //    AIOTMoveInfo.log($"第一盘料盘已到达目的地");
                //    //    if (CurrentPosIndex - 1 < 0 || StopAutoInOut)
                //    //    {
                //    //        AIOTMoveInfo.log($"已达到最后一个库位:{CurrentPosIndex},或手动停止{StopAutoInOut},自动出入库停止,将料盘送至出口");
                //    //        AIOTMoveInfo.NextMoveStep(MoveStep.StoreOut10);
                //    //        CloseFlipDoor(AIOTMoveInfo);
                //    //        return;
                //    //    }
                //    //    if (Setting_Init.Device_AIOTest_DirectGetReel)
                //    //    {
                //    //        RobotManage.UserPause("暂停放入第二盘", true);
                //    //    }
                //    //    AIOTMoveInfo.log($"开始转运料盘第二盘");
                //    //    ac = poslist[CurrentPosIndex - 1];
                //    //    reel = new ReelParam("auto", ac.BagWidth, ac.BagHigh);
                //    //    if (!boxTransport.Start(new BoxStorePosition(Config, StoreSide.NGDoor, reel), new BoxStorePosition(Config, ac, reel), StoreMoveType.InStore))
                //    //    {
                //    //        AIOTMoveInfo.log($"料仓周转启动失败");
                //    //        AutoInOutTest = false;
                //    //        StopAutoInOut = true;
                //    //        return;
                //    //    }
                //    //}
                //    break;
                case MoveStep.StoreIn05:
                    if (boxTransport.IsTakedReel)
                    {
                        AIOTMoveInfo.NextMoveStep(MoveStep.StoreIn06);
                        ReelTaked();
                        AIOTMoveInfo.log($"第二盘料盘已取走");
                    }
                    else
                    {
                        Msg.add(crc.GetString(L.wait_reel_transfer, "单料口等待料盘离开."), MsgLevel.info);
                    }
                    break;
                case MoveStep.StoreIn06:
                    if (boxTransport.IsComplateOrFree)
                    {
                        AIOTMoveInfo.log($"第二盘料盘已到达目的地");
                        if (CurrentPosIndex - 1 < 0 || StopAutoInOut)
                        {
                            AIOTMoveInfo.log($"已达到最后一个库位:{CurrentPosIndex},或手动停止{StopAutoInOut},自动出入库停止,将料盘送至出口");
                            AIOTMoveInfo.NextMoveStep(MoveStep.StoreOut10);
                            CloseFlipDoor(AIOTMoveInfo);
                            return;
                        }

                        //ac = poslist[CurrentPosIndex - 1];
                        //reel = new ReelParam("auto", ac.BagWidth, ac.BagHigh);
                        //if (!boxTransport.Start(new BoxStorePosition(Config, StoreSide.String, reel), new BoxStorePosition(Config, ac, reel), StoreMoveType.InStore))
                        //{
                        //    AIOTMoveInfo.log($"料仓周转启动失败");
                        //    AutoInOutTest = false;
                        //    StopAutoInOut = true;
                        //    return;
                        //}
                        AIOTMoveInfo.NextMoveStep(MoveStep.StoreIn07);
                    }
                    break;
                case MoveStep.StoreIn07:
                    if (boxTransport.IsComplateOrFree)
                    {
                        AIOTMoveInfo.NextMoveStep(MoveStep.StoreIn08);
                        var ac1 = poslist[CurrentPosIndex];
                        if (CurrentPosIndex - 2 < 0 || StopAutoInOut)
                        {
                            AIOTMoveInfo.log($"A已达到最后一个库位:{CurrentPosIndex},或手动停止{StopAutoInOut},自动出入库停止,将料盘送至出口");
                            AIOTMoveInfo.NextMoveStep(MoveStep.StoreOut10);
                            CurrentPosIndex++;
                            CloseFlipDoor(AIOTMoveInfo);
                            return;
                        }
                        var ac2 = poslist[CurrentPosIndex - 2];
                        reel = new ReelParam("auto", ac2.BagWidth, ac2.BagHigh);
                        if (!boxTransport.Start(new BoxStorePosition(Config, ac1, reel), new BoxStorePosition(Config, ac2, reel), StoreMoveType.InStore))
                        {
                            AIOTMoveInfo.log($"料仓周转启动失败");
                            AutoInOutTest = false;
                            StopAutoInOut = true;
                            return;
                        }
                        AIOTMoveInfo.log($"开始交替");
                    }
                    break;
                case MoveStep.StoreIn08:
                    if (boxTransport.IsComplateOrFree)
                    {
                        AIOTMoveInfo.log($"料盘已到达目的地");
                        if (CurrentPosIndex - 1 < 0 || StopAutoInOut)
                        {
                            AIOTMoveInfo.log($"B已达到最后一个库位:{CurrentPosIndex},或手动停止{StopAutoInOut},自动出入库停止,将料盘送至出口");
                            AIOTMoveInfo.NextMoveStep(MoveStep.StoreOut10);
                            CloseFlipDoor(AIOTMoveInfo);
                            return;
                        }
                        CurrentPosIndex--;
                        AIOTMoveInfo.NextMoveStep(MoveStep.StoreIn07);
                    }
                    break;
                case MoveStep.StoreOut10:
                    AIOTMoveInfo.NextMoveStep(MoveStep.StoreOut11);
                    CurrentPosIndex--;
                    ac = poslist[CurrentPosIndex];
                    reel = new ReelParam("auto", ac.BagWidth, ac.BagHigh);
                    if (!boxTransport.Start(new BoxStorePosition(Config, ac, reel), new BoxStorePosition(Config, StoreSide.NGDoor, reel), StoreMoveType.OutStore))
                    {
                        AIOTMoveInfo.log($"料仓周转启动失败");
                        AutoInOutTest = false;
                        StopAutoInOut = true;
                        return;
                    }
                    AIOTMoveInfo.log($"开始转运料盘");

                    break;
                case MoveStep.StoreOut11:
                    if (boxTransport.IsComplateOrFree)
                    {
                        NGPuted("");
                        AIOTMoveInfo.NextMoveStep(MoveStep.StoreOut12);
                        AIOTMoveInfo.log($"料盘已到达目的地");
                        //AutoInOutTest = false;
                    }
                    break;
                case MoveStep.StoreOut12:
                    if (ClampMoveInfo.MoveStep == MoveStep.Wait)
                    {
                        AIOTMoveInfo.NextMoveStep(MoveStep.StoreOut13);
                        AIOTMoveInfo.log($"NG口已空闲");
                        CloseFlipDoor(AIOTMoveInfo);
                    }
                    else
                    {
                        AIOTMoveInfo.log($"等待NG口空闲");
                    }
                    break;
                case MoveStep.StoreOut13:
                    AIOTMoveInfo.NextMoveStep(MoveStep.StoreOut14);
                    ac = poslist[CurrentPosIndex - 1];
                    reel = new ReelParam("auto", ac.BagWidth, ac.BagHigh);
                    if (!boxTransport.Start(new BoxStorePosition(Config, ac, reel), new BoxStorePosition(Config, StoreSide.NGDoor, reel), StoreMoveType.OutStore))
                    {
                        AIOTMoveInfo.log($"料仓周转启动失败");
                        AutoInOutTest = false;
                        StopAutoInOut = true;
                        return;
                    }
                    AIOTMoveInfo.log($"开始转运料盘");
                    break;
                case MoveStep.StoreOut14:
                    if (boxTransport.IsComplateOrFree)
                    {
                        NGPuted("");
                        AIOTMoveInfo.log($"料盘已到达目的地");
                        AIOTMoveInfo.EndMove();
                        AutoInOutTest = false;
                    }
                    break;
                default:
                    AIOTMoveInfo.log($"未找到对应步骤:{AIOTMoveInfo.MoveStep}");
                    break;
            }
        }
    }
}