MainMachine _AutoInOutTest.cs 6.1 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("Res0072","料仓忙碌中,无法启动");
                return false;
            }
            if(!IsInStoreReady)
            {
                errmsg = crc.GetString("Res0073","入库料盘没有准备好,无法启动");
                return false;
            }
            AutoInOutTest = true;
            StopAutoInOut = false;
            CurrentPosIndex = posindex;
            //AIOTMoveInfo.NewMove(MoveStep.Wait);
            return true;
        }
        public void StopAutoInOutTest()
        {
            StopAutoInOut = true;
        }
        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 = RobotManage.allPositionMap[RobotManage.StorePositionNumList[CurrentPosIndex]];
                    var from = RobotManage.allPositionMap["EP_1_1"];
                    var reel = new ReelParam("auto");
                    if (!boxTransport.Start(new BoxStorePosition(Config, from, reel), new BoxStorePosition(Config, ac, reel), StoreMoveType.InStore)) {
                        AIOTMoveInfo.log($"料仓周转启动失败");
                        AutoInOutTest = false;
                        StopAutoInOut = true;
                        return;
                    }
                    AIOTMoveInfo.log($"开始转运料盘第一盘");                    
                    break;
                case MoveStep.StoreIn02:
                case MoveStep.StoreIn03:
                    if (boxTransport.IsComplateOrFree)
                    {
                        AIOTMoveInfo.NextMoveStep(MoveStep.StoreIn04);
                        var ac1 = RobotManage.allPositionMap[RobotManage.StorePositionNumList[CurrentPosIndex]];
                        if (CurrentPosIndex - 1 < 0 || StopAutoInOut)
                        {
                            AIOTMoveInfo.log($"A已达到最后一个库位:{CurrentPosIndex},或手动停止{StopAutoInOut},自动出入库停止,将料盘送至出口");
                            AIOTMoveInfo.NextMoveStep(MoveStep.StoreOut10);
                            CurrentPosIndex++;
                            return;
                        }
                        var ac2 = RobotManage.allPositionMap[RobotManage.StorePositionNumList[CurrentPosIndex-1]];
                        reel = new ReelParam("auto");
                        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.StoreIn04:
                    if (boxTransport.IsComplateOrFree)
                    {
                        AIOTMoveInfo.log($"料盘已到达目的地");                        
                        if (CurrentPosIndex-1 < 0 || StopAutoInOut)
                        {
                            AIOTMoveInfo.log($"B已达到最后一个库位:{CurrentPosIndex},或手动停止{StopAutoInOut},自动出入库停止,将料盘送至出口");
                            AIOTMoveInfo.NextMoveStep(MoveStep.StoreOut10);
                            return;
                        }
                        CurrentPosIndex--;
                        AIOTMoveInfo.NextMoveStep(MoveStep.StoreIn03);
                    }
                    break;
                case MoveStep.StoreOut10:
                    AIOTMoveInfo.NextMoveStep(MoveStep.StoreOut11);
                    ac = RobotManage.allPositionMap[RobotManage.PositionNumList[CurrentPosIndex]];
                    var to = RobotManage.allPositionMap["OP_1"];
                    reel = new ReelParam("auto");
                    if (!boxTransport.Start(new BoxStorePosition(Config, ac, reel), new BoxStorePosition(Config, to, reel), StoreMoveType.OutStore))
                    {
                        AIOTMoveInfo.log($"料仓周转启动失败");
                        AutoInOutTest = false;
                        StopAutoInOut = true;
                        return;
                    }
                    AIOTMoveInfo.log($"开始转运料盘");
                    
                    break;
                case MoveStep.StoreOut11:
                    if (boxTransport.IsComplateOrFree)
                    {
                        AIOTMoveInfo.log($"库位测试结束");
                        AIOTMoveInfo.EndMove();
                        AutoInOutTest = false;
                    }
                    break;
                default:
                    AIOTMoveInfo.log($"未找到对应步骤:{AIOTMoveInfo.MoveStep}");
                    break;
            }
        }
    }
}