MainMachine _AutoInOutTest.cs 11.8 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(int posindex, out string errmsg)
        {
            errmsg = "";
            if (!boxTransport.IsComplateOrFree)
            {
                errmsg = crc.GetString("Res0002","料仓忙碌中,无法启动");
                return false;
            }
            if(!IsInStoreReady)
            {
                errmsg = crc.GetString("Res0003","入库料盘没有准备好,无法启动");
                return false;
            }
            poslist = RobotManage.PositionNumList.Select(a => { return CSVPositionReader<ACStorePosition>.allPositionMap[a]; }).ToList();//CSVPositionReader<ACStorePosition>.getPositionList();
            AutoInOutTest = true;
            StopAutoInOut = false;
            CurrentPosIndex = posindex;
            //AIOTMoveInfo.NewMove(MoveStep.Wait);
            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:
                    if (IsInStoreReady)
                    {
                        AIOTMoveInfo.NextMoveStep(MoveStep.StoreIn01);
                        AIOTMoveInfo.log($"入库料盘已准备好");
                    }
                    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 (IsInStoreReady)
                    {
                        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;
                        }
                        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;
            }
        }
    }
}