StationEquip_InStore.cs 12.4 KB
using Asa;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace OnlineStore.DeviceLibrary
{
    partial class StationEquip
    {

        #region 箱子检测 
        protected override void BoxProcess()
        {
        }

        #endregion

        #region 入料流程
        public override bool StartInStoreMove(InOutParam param)
        {
            runStatus = LineRunStatus.Busy;
            MoveInfo.NewMove(LineMoveType.InStore);
            MoveInfo.MoveParam = param;
            MoveInfo.NextMoveStep(LineMoveStep.SI_01_StopUp);
            StopUp(MoveInfo);
            LogInfo($"开始入库,阻挡上升");
            return true;
        }
        ContainerInfo curboxInfo;
        /// <summary>
        /// 检查当前容器是否是该工位的出库料箱
        /// </summary>
        /// <param name="trayInfo"></param>
        /// <returns></returns>
        private bool IsCurStationBox(ContainerInfo trayInfo)
        {
            return (trayInfo?.InOrOutStore.Equals(ContainerType.OutStore) ??false)&& (trayInfo?.InoutParam?.DeviceId.Equals(DeviceID)??false);
        }
        private void AddWaitBoxCheck(bool high)
        {
            if (high)
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Stop_BoxCheck, IO_VALUE.HIGH));
            else
                MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Stop_BoxCheck, IO_VALUE.LOW));
        }
        private void WaitTime(int ms)
        {
            MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(ms));
        }
        protected override void InStoreProcess()
        {
            if (MoveInfo.IsInWait)
            {
                CheckWait(MoveInfo);
            }
            if (MoveInfo.IsInWait)
            {
                return;
            }
            if (MoveInfo.IsStep(LineMoveStep.SI_01_StopUp))
            {
                MoveInfo.NextMoveStep(LineMoveStep.SI_01_WaitBoxCheck);
                LogInfo($" 前阻挡下降");
                FrontStopDown(MoveInfo);
                AddWaitBoxCheck(true);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
            }
            else if (MoveInfo.IsStep(LineMoveStep.SI_01_WaitBoxCheck))
            {
                MoveInfo.NextMoveStep(LineMoveStep.SI_02_FrontStopUp);
                LogInfo($" 前阻挡上升");
                FrontStopUp(MoveInfo);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
            }
            else if (MoveInfo.IsStep(LineMoveStep.SI_02_FrontStopUp))
            {
                MoveInfo.NextMoveStep(LineMoveStep.SI_03_ReadAndCheckBox);
                UpdateContainerCode();
                curboxInfo = ContainerManager.GetTrayInfo(CurContainerId);
                LogInfo($" 读取容器信息:{JsonHelper.SerializeObject(curboxInfo)}");
            }
            else if (MoveInfo.IsStep(LineMoveStep.SI_03_ReadAndCheckBox))
            {
                if(GetStationCode(out string rfid))
                {
                    EquipBase equipBase = GetOutEquip();
                    if (equipBase != null)
                    {
                        if (equipBase.IsIdle())
                        {
                            MoveInfo.NextMoveStep(LineMoveStep.SI_08_StopDown);
                            LogInfo($"分拣台有箱子{rfid},放行");
                            StopDown(MoveInfo);
                        }
                        else
                        {
                            MoveInfo.NextMoveStep(LineMoveStep.SI_09_WaitDownriverIdle);
                            LogInfo($"分拣台有箱子{rfid},等待下游{equipBase.Name}空闲再放行容器");
                        }
                    }
                    else
                    {
                        SetWarnMsg($"无下游信息,结束处理");
                        MoveEndS();
                    }
                }
                else if (IsCurStationBox(curboxInfo))
                {
                    MoveInfo.NextMoveStep(LineMoveStep.SI_04_BoxArrive);
                    LogInfo($" 该箱子是该工位出库容器,上报到达状态");
                    ContainerManager.UpdateTaskStatus(CurContainerId, TaskStatus.NEED_AWAY,$"s{DeviceID}");
                }
                else
                {
                    EquipBase equipBase = GetOutEquip();
                    if (equipBase != null)
                    {
                        if (equipBase.IsIdle())
                        {
                            MoveInfo.NextMoveStep(LineMoveStep.SI_08_StopDown);
                            LogInfo($"该箱子不是该工位出库容器,放行");
                            StopDown(MoveInfo);
                        }
                        else
                        {
                            MoveInfo.NextMoveStep(LineMoveStep.SI_09_WaitDownriverIdle);
                            LogInfo($" 等待下游{equipBase.Name}空闲再放行容器");
                        }
                    }
                    else
                    {
                        SetWarnMsg($"无下游信息,结束处理");
                        MoveEndS();
                    }
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.SI_09_WaitDownriverIdle))
            {
                EquipBase equipBase = GetOutEquip();
                //if (DeviceID == 5)
                //{
                //    if (MoveInfo.IsTimeOut())
                //    {
                //        SetWarnMsg($"等待容器到达下游{equipBase.Name}超时");
                //    }
                //    else if (!equipBase.IsContainerArrived())
                //    {
                //        return;
                //    }
                //}
                if (equipBase != null && equipBase.IsIdle())
                {
                    MoveInfo.NextMoveStep(LineMoveStep.SI_08_StopDown);
                    LogInfo($" 下游{equipBase.Name}空闲,不是该工位出库容器,放行");
                    StopDown(MoveInfo);
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.SI_04_BoxArrive))
            {
                MoveInfo.NextMoveStep(LineMoveStep.SI_05_WaitBoxLeave);
                LogInfo($"等待出库容器被拿走");
                AddWaitBoxCheck(false);
            }
            else if (MoveInfo.IsStep(LineMoveStep.SI_05_WaitBoxLeave))
            {
                MoveInfo.NextMoveStep(LineMoveStep.SI_06_WaitBoxAtStation);
                LogInfo($"出库容器被拿走,等待容器到达工作台");
            }
            else if (MoveInfo.IsStep(LineMoveStep.SI_06_WaitBoxAtStation))
            {
                EquipBase equipBase = GetOutEquip();
                if (DeviceID == 5)
                {
                    if (MoveInfo.IsTimeOut())
                    {
                        SetWarnMsg($"等待容器到达下游{equipBase.Name}超时");
                    }
                    else if (!equipBase.IsContainerArrived())
                    {
                        return;
                    }
                }
                ClearSpecifiedWarnMsg($"等待容器到达下游");
                if (MoveInfo.IsTimeOut(30))
                {
                    MoveInfo.NextMoveStep(LineMoveStep.SI_07_AllStopDown);
                    if (ContainerManager.GetInTaskCnt(DeviceID) > 0)
                    {
                        LogInfo($"容器到达工作台30秒超时,该工位将有出库容器到达,前阻挡下降");
                        FrontStopDown(MoveInfo);

                    }
                    else if (ContainerManager.GetOutTaskCnt(DeviceID) > 0)
                    {
                        LogInfo($"容器到达工作台30秒超时,该工位将有入库容器离开,阻挡下降");
                        StopDown(MoveInfo);
                    }
                    else if(DeviceID==5)
                    {
                        LogInfo($"容器到达工作台30秒超时,前阻挡下降");
                        FrontStopDown(MoveInfo);
                    }
                    else
                    {
                        LogInfo($"容器到达工作台30秒超时,所有阻挡下降");
                        StopDown(MoveInfo);
                        FrontStopDown(MoveInfo);
                    }
                    ContainerManager.UpdateTaskStatus(CurContainerId, TaskStatus.FINISHED);
                }
                else
                {
                    ReadStationShelfId();
                    if (CurShelfId_Station.Equals(CurContainerId))
                    {
                        MoveInfo.NextMoveStep(LineMoveStep.SI_07_AllStopDown);
                        if (ContainerManager.GetInTaskCnt(DeviceID) > 0)
                        {
                            LogInfo($" 容器到达工作台,该工位将有出库容器到达,前阻挡下降");
                            FrontStopDown(MoveInfo);
                        }
                        else if (ContainerManager.GetOutTaskCnt(DeviceID) > 0)
                        {
                            LogInfo($"容器到达工作台,该工位将有入库容器离开,阻挡下降");
                            StopDown(MoveInfo);
                        }
                        else if (DeviceID == 5)
                        {
                            LogInfo($"箱子到达工作台,前阻挡下降");
                            FrontStopDown(MoveInfo);
                        }
                        else
                        {
                            LogInfo($"箱子到达工作台,所有阻挡下降");
                            StopDown(MoveInfo);
                            FrontStopDown(MoveInfo);
                        }
                        ContainerManager.UpdateTaskStatus(CurShelfId_Station, TaskStatus.FINISHED);
                    }
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.SI_07_AllStopDown))
            {
                MoveEndS();
            }
            else if (MoveInfo.IsStep(LineMoveStep.SI_08_StopDown))
            {
                MoveInfo.NextMoveStep(LineMoveStep.SI_09_WaitBoxLeave);
                LogInfo($"等待容器放行完成");
                AddWaitBoxCheck(false);
                MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
            }
            else if (MoveInfo.IsStep(LineMoveStep.SI_09_WaitBoxLeave))
            {
                EquipBase equipBase = GetOutEquip();
                if (DeviceID==5)
                {
                    if(MoveInfo.IsTimeOut())
                    {
                        SetWarnMsg($"等待容器到达下游{equipBase.Name}超时");
                    }
                    else if(!equipBase.IsContainerArrived())
                    {
                        return;
                    }
                }
                ClearSpecifiedWarnMsg($"等待容器到达下游");
                MoveInfo.NextMoveStep(LineMoveStep.SI_10_FrontStopDown);
                if (ContainerManager.GetInTaskCnt(DeviceID) > 1)
                {
                    LogInfo($"该工位将有出库容器到达,阻挡上升,前阻挡下降");
                    StopUp(MoveInfo);
                    FrontStopDown(MoveInfo);
                }
                else if (ContainerManager.GetOutTaskCnt(DeviceID) > 0)
                {
                    LogInfo($"该工位将有入库容器离开,前阻挡保持上升");
                }
                else if (DeviceID == 5)//工位5放行一个容器后前阻挡上升
                {
                    LogInfo($"阻挡上升");
                    StopUp(MoveInfo);
                }
                else
                {
                    FrontStopDown(MoveInfo);
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.SI_10_FrontStopDown))
            {
                MoveInfo.NextMoveStep(LineMoveStep.SI_11_End);
                if (DeviceID == 5)
                {
                    LogInfo($"前阻挡下降");
                    FrontStopDown(MoveInfo);
                }
            }
            else if (MoveInfo.IsStep(LineMoveStep.SI_11_End))
            {
                MoveEndS();
            }
            #region 
            #endregion
        }
        #endregion

    }
}