EmptyShelfBackJob.cs 5.7 KB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.ModelBinding;
using System.Windows.Forms;
using Common;
using DeviceLibrary.bean;
using DeviceLibrary.manager;

namespace DeviceLibrary
{
    /// <summary>
    /// 料架回收任务
    /// </summary>
    public class EmptyShelfBackJob : Job
    {
        /// <summary>
        /// 料架回收任务
        /// </summary>
        public EmptyShelfBackJob(JobParam jobParam) : base(jobParam)
        {
            JobName = "料架回收返回任务";
        }

        private int tryTimes = 0;

        /// <summary>
        /// 料架回收任务
        /// </summary>
        /// <param name="agv"></param>
        public override Job Run(Agv_Info agv)
        {
            if (JobRunStep.IsStep(RunStep.NONE))
            {
                if (JobParam.SrcNode.Area.Equals(Area.Air_C))//C车间风淋门
                {
                    JobRunStep.ToNextStep(RunStep.WAIT_OUT_AIR_DOOR);
                    runInfo = string.Format("从{0}去风淋门", JobParam.SrcNode);
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, SettingString.DoorAirOut);
                }
                else if (JobParam.SrcNode.Area.Equals(Area.C))//C车间
                {
                    JobRunStep.ToNextStep(RunStep.WAIT_IN_ROOM_D);
                    runInfo = string.Format("从{0}过门", JobParam.SrcNode);
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, SettingString.DoorCToD);
                }
                else
                {
                    JobRunStep.ToNextStep(RunStep.RECY_BACK_WAIT_REACH_RECY_ST);
                    runInfo = string.Format("从{0}去{1}", JobParam.SrcNode, JobParam.TargetNode);
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, JobParam.TargetNode.Name);
                }
            }
            else if (JobRunStep.IsStep(RunStep.WAIT_OUT_AIR_DOOR))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    JobRunStep.ToNextStep(RunStep.WAIT_IN_ROOM_D);
                    runInfo = string.Format("出风淋门,准备过门");
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, SettingString.DoorCToD);
                }
            }
            else if (JobRunStep.IsStep(RunStep.WAIT_IN_ROOM_D))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    JobRunStep.ToNextStep(RunStep.RECY_BACK_WAIT_REACH_RECY_ST);
                    runInfo = string.Format("进门,送往{0}", JobParam.TargetNode);
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, JobParam.TargetNode.Name);
                }
            }
            else if (JobRunStep.IsStep(RunStep.RECY_BACK_WAIT_REACH_STANDBY))
            {

            }
            else if (JobRunStep.IsStep(RunStep.RECY_BACK_WAIT_REACH_RECY_ST))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    JobRunStep.ToNextStep(RunStep.RECY_BACK_WAIT_RECY_ST_RESPONSE);
                    runInfo = "AGV到达 " + JobParam.TargetNode + ",并发送入料架请求";
                    JobRunStep.Msg = runInfo;
                    OpManager.ServerToClient.ReadyEnter(JobParam.TargetNode.Name, JobParam.Shelf == null ? "" : JobParam.Shelf.RFID);
                }
            }
            else if (JobRunStep.IsStep(RunStep.RECY_BACK_WAIT_RECY_ST_RESPONSE))
            {
                Node node = NodeManager.GetNodeByName(JobParam.TargetNode.Name);
                if (node.StateEquals(NodeStatus.MayEnter))
                {
                    {
                        JobRunStep.ToNextStep(RunStep.RECY_BACK_WAIT_SHELF_IN_RECY_ST);
                        runInfo = "收到入料架请求的响应 " + JobParam.TargetNode + "入料架,小车链条运行";
                        JobRunStep.Msg = runInfo;
                        AllocateTask(agv, SettingString.Leave);
                    }

                }
                else if (JobRunStep.IsTimeOut(15000, out TimeSpan timeOutValue))
                {
                    tryTimes++;
                    if (tryTimes < 3)
                        return this;
                    tryTimes = 0;
                    JobRunStep.ToNextStep(RunStep.RECY_BACK_WAIT_REACH_RECY_ST);
                    runInfo = JobParam.TargetNode + "无响应,再次发送请求";
                    JobRunStep.Msg = runInfo;
                    AllocateTask(agv, SettingString.Standby);
                }
            }
            else if (JobRunStep.IsStep(RunStep.RECY_BACK_WAIT_SHELF_IN_RECY_ST))
            {
                if (agv.TaskRunState.CheckTaskFinished(agv.Name))
                {
                    JobRunStep.ToNextStep(RunStep.END);
                    runInfo = $"料架{(JobParam.Shelf == null ? "" : JobParam.Shelf.RFID)}进入{JobParam.TargetNode}完成";
                    JobRunStep.Msg = runInfo;
                }
                else if (JobRunStep.IsTimeOut(60000, out TimeSpan timeOutValue1))
                {
                    runInfo = "空料架在[" + JobParam.TargetNode + "]离开小车超时";
                    agv.HasError = true;
                    agv.SetErrorMsg("空料架在[" + JobParam.TargetNode + "]进入小车超时", timeOutValue1.TotalMinutes.ToString("f2"));
                }

            }
            else if (JobRunStep.IsStep(RunStep.END))
            {
                JobRunStep.EndJob();
                return null;
            }
            return this;
        }
    }

}