queryStatusController.cs 6.2 KB
using DeviceLib.WebApi.Schemas;
using DeviceLibrary;
using DeviceLibrary.AGVService.Schemas;
using log4net.Util;
using OnlineStore;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Web.Http;
using WebApi.Schemas;

namespace WebApi.Controllers
{
    [RoutePrefix("api")]
    public class queryStatusController : ApiController
    {
        [HttpGet]
        public Result_20861 Get([FromBody] InParam_20861 body)
        {
            Result_20861 result = new Result_20861();
            try
            {
                var cid = body.cid;
                {
                    if (string.IsNullOrEmpty(cid))
                    {
                        result.code = 202;
                        result.status = "cid is empty";
                    }
                    else
                    {
                        if (body.cid.Equals("B1") || body.cid.Equals("B2"))
                        {
                            if (!RobotManage.isRunning)
                            {
                                result.code = 201;
                                result.status = crc.GetString("Res0079", "机器尚未启动不能呼叫Agv");
                                return result;
                            }
                        }
                        else
                        {
                            result.code = -1;
                            result.status = $" cid {body.cid} not exist";
                        }
                        //IS_RECEIVING 正在接收料串
                        //HAS_STACKER 有料串
                        //IS_DELIVERING 正在出料串
                        //EMPTY 无料串
                        //Error 错误
                        switch (body.cid)
                        {
                            case "B1"://NS200入料口上料任务

                                if (RobotManage.mainMachine.RightMoveInfo.IsStep(MoveStep.Wait))
                                {
                                    if (RobotManage.mainMachine.IOValue(IO_Type.RightFornt_Check).Equals(IO_VALUE.HIGH)
                                          || RobotManage.mainMachine.IOValue(IO_Type.RightEnd_Check).Equals(IO_VALUE.HIGH))
                                    {
                                        result.status = "HAS_STACKER";
                                    }
                                    else
                                    {
                                        result.status = "EMPTY";
                                    }
                                }
                                else
                                {
                                    if (RobotManage.mainMachine.RightMoveInfo.MoveStep >= MoveStep.R40_InShelf)
                                    {
                                        result.code = 0;
                                        result.status = "IS_RECEIVING";
                                    }
                                    else if (RobotManage.mainMachine.RightMoveInfo.MoveStep >= MoveStep.R30_OutShelf)
                                    {
                                        result.code = 0;
                                        result.status = "IS_DELIVERING";
                                    }
                                    else if (RobotManage.mainMachine.IOValue(IO_Type.RightFornt_Check).Equals(IO_VALUE.HIGH)
                                          || RobotManage.mainMachine.IOValue(IO_Type.RightEnd_Check).Equals(IO_VALUE.HIGH))
                                    {
                                        result.status = "HAS_STACKER";
                                    }
                                    else
                                    {
                                        result.status = "EMPTY";
                                    }
                                    //{
                                    //    result.code = 203;
                                    //    result.status = "Error";
                                    //}
                                }
                                break;
                            case "B2"://NS200出料口上料任务
                                if (RobotManage.mainMachine.LeftMoveInfo.IsStep(MoveStep.Wait))
                                {
                                    if (RobotManage.mainMachine.IOValue(IO_Type.LeftFornt_Check).Equals(IO_VALUE.HIGH)
                                          || RobotManage.mainMachine.IOValue(IO_Type.LeftEnd_Check).Equals(IO_VALUE.HIGH))
                                    {
                                        result.status = "HAS_STACKER";
                                    }
                                    else
                                    {
                                        result.status = "EMPTY";
                                    }
                                }
                                else
                                {
                                    if (RobotManage.mainMachine.LeftMoveInfo.MoveStep >= MoveStep.L60_InShelf)
                                    {
                                        result.code = 0;
                                        result.status = "IS_RECEIVING";
                                    }
                                    else if (RobotManage.mainMachine.LeftMoveInfo.MoveStep >= MoveStep.L50_OutShelf)
                                    {
                                        result.code = 0;
                                        result.status = "IS_DELIVERING";
                                    }
                                    else
                                    {
                                        result.code = 203;
                                        result.status = "Error";
                                    }
                                }
                                break;
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                result.code = 204;
                result.status = $"parse error:{ex.Message}";
                LogUtil.error("QueryStatus", ex);
            }

            return result;
        }
    }
}