diff --git a/SlnMesnac.Business/base/BaseAGVBusiness.cs b/SlnMesnac.Business/base/BaseAGVBusiness.cs index 2373ec4..0bcb6b1 100644 --- a/SlnMesnac.Business/base/BaseAGVBusiness.cs +++ b/SlnMesnac.Business/base/BaseAGVBusiness.cs @@ -1,11 +1,16 @@ using Microsoft.Extensions.Logging; +using SlnMesnac.Config; using SlnMesnac.Model.AirportApiEntity; using SlnMesnac.Model.domain; +using SlnMesnac.Repository; using SlnMesnac.Repository.service; using SlnMesnac.TouchSocket; using System; using System.Collections.Generic; +using System.Linq; using System.Text; +using System.Threading; +using System.Threading.Tasks; namespace SlnMesnac.Business.@base { @@ -16,24 +21,34 @@ namespace SlnMesnac.Business.@base { private ILogger _logger; private static BaseAGVBusiness instance; + private AppConfig _appConfig; private AirPorthttpClient _airPorthttpClient; private IAGVStateService _AGVStateService; private IAGVMapPointService _AGVMapPointService; - public BaseAGVBusiness(ILogger logger, AirPorthttpClient airPorthttpClient, IAGVStateService AGVStateService, IAGVMapPointService aGVMapPointService) + public BaseAGVBusiness(ILogger logger, + AirPorthttpClient airPorthttpClient, + IAGVStateService AGVStateService, + IAGVMapPointService aGVMapPointService, + AppConfig appConfig) { _logger = logger; _airPorthttpClient = airPorthttpClient; _AGVStateService = AGVStateService; _AGVMapPointService = aGVMapPointService; + _appConfig = appConfig; } - public static BaseAGVBusiness GetInstance(ILogger logger, AirPorthttpClient airPorthttpClient, IAGVStateService AGVStateService, IAGVMapPointService aGVMapPointService) + public static BaseAGVBusiness GetInstance(ILogger logger, + AirPorthttpClient airPorthttpClient, + IAGVStateService AGVStateService, + IAGVMapPointService aGVMapPointService, + AppConfig appConfig) { if (instance == null) { - instance = new BaseAGVBusiness(logger, airPorthttpClient, AGVStateService, aGVMapPointService); + instance = new BaseAGVBusiness(logger, airPorthttpClient, AGVStateService, aGVMapPointService, appConfig); } return instance; } @@ -85,7 +100,7 @@ namespace SlnMesnac.Business.@base /// /// 发送封装的任务类 /// - /// + /// 任务ID public string DownloadTask(string AGVGUID, string JobGUID, string PointGUID, string ParamName, string TaskName = "AGVCTask", string RobotType = "S800") { try @@ -115,40 +130,48 @@ namespace SlnMesnac.Business.@base /// public bool EndAGVTask(string AGVGUID) { - var agvState = _AGVStateService.GetAGVState(AGVGUID); - if(agvState == null) - { - return false; - } - if(agvState.agvworkstate != "待机") + try { - var response = _airPorthttpClient.AGVOperationalTaskRequest(new AGVRequestOperationalTaskEntity() + AGVState agvState = _AGVStateService.GetAGVState(AGVGUID); + if (agvState == null) { - taskid = agvState.taskno, - state = 0, - operatingSource = "agvc", - operatingUser = "agvc", - remark = "agvcEnd" - }); - if (response.code == 0) + return false; + } + if (agvState.agvworkstate != "待机") + { + var response = _airPorthttpClient.AGVOperationalTaskRequest(new AGVRequestOperationalTaskEntity() + { + taskid = agvState.taskno, + state = 0, + operatingSource = "agvc", + operatingUser = "agvc", + remark = "agvcEnd" + }); + if (response.code == 0) + { + _logger.LogInformation($"AGV {agvState.agvno} 任务 {agvState.taskno} 结束成功"); + return true; + } + else + { + _logger.LogError($"AGV {agvState.agvno} 任务 {agvState.taskno} 结束失败 ERROR:{response.message}"); + return false; + } + } + else if (agvState.agvworkstate == "待机") { - _logger.LogInformation($"AGV {agvState.agvno} 任务 {agvState.taskno} 结束成功"); - return true; + _logger.LogError($"AGV {agvState.agvno} 现在无任务"); + return false; } else { - _logger.LogError($"AGV {agvState.agvno} 任务 {agvState.taskno} 结束失败 ERROR:{response.message}"); + _logger.LogError($"AGV {agvState.agvno} 终止任务失败!"); return false; } } - else if(agvState.agvworkstate == "待机") - { - _logger.LogError($"AGV {agvState.agvno} 现在无任务"); - return false; - } - else + catch (Exception ex) { - _logger.LogError($"AGV {agvState.agvno} 终止任务失败!"); + _logger.LogError($"AGV任务结束失败 ERROR:{ex.Message}"); return false; } } @@ -208,6 +231,92 @@ namespace SlnMesnac.Business.@base return _AGVMapPointService.DeleteAndAddAgvMapPoint(list); } + /// + /// 结束当前任务 清除报警 下发任务 + /// + /// + /// + /// 新任务GUID + public string EndTaskAndClearErrorAndDownloadTask(string agvName, string jobName) + { + bool result = false; + try + { + //终止小车当前任务 + result = EndTaskAndClearError(agvName); + var param = _appConfig.JobConfig.Where(x => x.JobName == jobName).First(); + //调用小车到抓取位置 + return DownloadTask(_appConfig.AGVConfig.Where(x => x.AGVName == agvName).First().AGVGUID, param.JobGUID, param.PointGUID, param.PointParamName); + } + catch (Exception ex) + { + return string.Empty; + } + } + + /// + /// 结束任务并清除报警 延迟1s + /// + public bool EndTaskAndClearError(string agvName) + { + bool result1 = false, result2 = false; + try + { + Task.Run(() => + { + result1 = EndAGVTask(_appConfig.AGVConfig.Where(x => x.AGVName == agvName).First().AGVGUID); + Thread.Sleep(500); + result2 = ClaerError(_appConfig.AGVConfig.Where(x => x.AGVName == agvName).First().AGVIp); + }); + return result1 && result2; + } + catch (Exception ex) + { + _logger.LogError("结束任务并清除报警发生异常 " + ex); + return false; + } + } + + /// + /// 清除报警 延迟500ms + /// + public bool ClaerError(string agvName) + { + bool result = false; + try + { + Task.Run(() => + { + var response = _airPorthttpClient.AGVErrorClear(_appConfig.AGVConfig.Where(x => x.AGVName == agvName).First().AGVIp); + Thread.Sleep(500); + if (response == null) + { + _logger.LogError("清除报警返回空数据"); + result = false; + return false; + } + if(response.code == 0) + { + _logger.LogError("清除报警成功"); + result = true; + return true; + } + else + { + _logger.LogError("清除报警失败 message:" + response.message); + result = false; + return false; + } + }); + return result; + } + catch (Exception ex) + { + _logger.LogError("清除报警发生异常 " + ex); + return false; + } + } + /// /// AGV任务状态代码匹配 /// diff --git a/SlnMesnac.WPF/Page/IndexPage/AddTaskContent.xaml b/SlnMesnac.WPF/Page/IndexPage/AddTaskContent.xaml index 1d481e2..d0e8aee 100644 --- a/SlnMesnac.WPF/Page/IndexPage/AddTaskContent.xaml +++ b/SlnMesnac.WPF/Page/IndexPage/AddTaskContent.xaml @@ -35,6 +35,11 @@ + + +