wangxinhui
6 天以前 5368df4e3ab0f1ca849b550a9fcbd0338e7f859d
ÏîÄ¿´úÂë/WCSServices/WIDESEAWCS_Server/Controllers/AGV/AGVController.cs
@@ -15,6 +15,7 @@
using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_DTO;
using WIDESEAWCS_DTO.Agv;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_IBasicInfoRepository;
using WIDESEAWCS_ITaskInfoRepository;
using WIDESEAWCS_ITaskInfoService;
@@ -86,6 +87,80 @@
            }
            return content;
        }
        /// <summary>
        /// AGV任务请求
        /// </summary>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("WorkRequest"), AllowAnonymous]
        public AgvTaskReqContent WorkRequest([FromBody] AgvTaskRequestDTO agvTaskRequestDTO)
        {
            AgvTaskReqContent content = new AgvTaskReqContent();
            try
            {
                //获取任务
                Dt_Task? taskExist = _taskRepository.QueryFirst(x=>x.PalletCode==agvTaskRequestDTO.ContainerCode) ?? throw new Exception($"未找到料箱{agvTaskRequestDTO.ContainerCode}任务");
                //获取站台
                Dt_StationManger? stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == agvTaskRequestDTO.PositionId) ?? throw new Exception($"未找到{agvTaskRequestDTO.PositionId}站台位置");
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode) ?? throw new Exception($"未找到对应设备{stationManger.StationDeviceCode}");
                OtherDevice commonConveyorLine = (OtherDevice)device;
                if (stationManger.StationType==StationTypeEnum.StationType_OnlyOutbound.ObjToInt())
                {
                    short IsPut = commonConveyorLine.Communicator.Read<short>("0");
                    if (IsPut != 256) throw new Exception($"{agvTaskRequestDTO.PositionId}禁止放箱");
                }
                else
                {
                    short IsTake = commonConveyorLine.Communicator.Read<short>("11");
                    if (IsTake != 256) throw new Exception($"{agvTaskRequestDTO.PositionId}禁止取箱");
                }
                content.OK();
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
        /// <summary>
        /// AGV作业完成
        /// </summary>
        /// <returns></returns>
        [HttpPost, HttpGet, Route("WorkFinish"), AllowAnonymous]
        public AgvTaskReqContent WorkFinish([FromBody] AgvTaskRequestDTO agvTaskRequestDTO)
        {
            AgvTaskReqContent content = new AgvTaskReqContent();
            try
            {
                //获取站台
                Dt_StationManger? stationManger = _stationMangerRepository.QueryFirst(x => x.StationCode == agvTaskRequestDTO.PositionId) ?? throw new Exception($"未找到{agvTaskRequestDTO.PositionId}站台位置");
                IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode) ?? throw new Exception($"未找到对应设备{stationManger.StationDeviceCode}");
                OtherDevice commonConveyorLine = (OtherDevice)device;
                if (stationManger.StationType == StationTypeEnum.StationType_OnlyOutbound.ObjToInt())
                {
                    commonConveyorLine.Communicator.Write("21", (short)256);
                }
                else
                {
                    commonConveyorLine.Communicator.Write("23", (short)256);
                }
                content.OK();
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("数据写入,地址:【23】,写入的数据:【256】") || ex.Message.Contains("数据写入,地址:【21】,写入的数据:【256】"))
                {
                    content.OK();
                }
                else
                {
                    content.Error(ex.Message);
                }
            }
            return content;
        }
    }
}