diff --git a/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs b/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs index 38b8b20..83bb45a 100644 --- a/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs +++ b/SlnMesnac.Business/base/BaseTaskInfoBusiness.cs @@ -55,14 +55,13 @@ namespace SlnMesnac.Business.@base _Taskservice = Taskservice; _AGVStateService = agvService; _airpttpClient = airPorthttpClient; - InitClearTimer(); //doWhileGetAGVTaskInfo(); _baseAGVBusiness = baseAGVBusiness; _AGVMapPointService = aGVMapPointService; _AGVJobService = agvJobService; - + //新建Timer RefreshTimer = new System.Timers.Timer(1000); RefreshTimer.Elapsed += (sender, e) => { @@ -346,6 +345,7 @@ namespace SlnMesnac.Business.@base //入库代码 _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(record.agvno, _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入库", "0").JobName); + _AGVStateService.ResetAGVStackCount(record.agvno); _logger.LogInformation($"Deliver [{record.agvno}] 入库"); } } @@ -357,6 +357,7 @@ namespace SlnMesnac.Business.@base //入库代码 _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(record.agvno, _AGVJobService.GetAGVJobListByTypeAndConveyorNo("1000入库", "0").JobName); + _AGVStateService.ResetAGVStackCount(record.agvno); _logger.LogInformation($"AMR [{record.agvno}] 入库"); } } @@ -366,310 +367,5 @@ namespace SlnMesnac.Business.@base _logger.LogError($"清理满载AGV时发生错误!Error: [{ex.Message}]"); } } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /// - /// 获取任务列表,向待执行任务派发AGV (定期执行) - /// - private void GetAGVTaskInfo(object source, ElapsedEventArgs e) - { - try - { - //获取任务列表 - List Task = _Taskservice.GetAGVTaskInfos(); - if (Task != null && Task.Count > 0) - { - //更新前端 - _RefreshLogMessageAction?.Invoke("任务数量:" + Task.Count); - foreach (AirportTask taskItem in Task) - { - //判断任务是否未完成 - if (taskItem.totalcount < taskItem.loadcount && taskItem.finishtime == null && taskItem.taskstate != "已完成") - { - //判断任务是否有小车正在执行 - if (!string.IsNullOrEmpty(taskItem.deliveragvno) && !string.IsNullOrEmpty(taskItem.amragvno)) - { - continue; - } - else - { - //Deliver未派发,AMR未派发 - if (string.IsNullOrEmpty(taskItem.deliveragvno) && string.IsNullOrEmpty(taskItem.amragvno)) - { - _RefreshLogMessageAction?.Invoke($"正在为AGV,AMR分配任务..."); - _logger.LogInformation($"正在为AGV,AMR分配任务"); - - //查询AGV设备状态及AMR设备状态 - - //这里要看AGV是否会立刻更新状态 - CreateAGVTask(taskItem); - //查询机械臂状态 - } - //Deliver已派发,AMR未派发 - if (!string.IsNullOrEmpty(taskItem.deliveragvno) && string.IsNullOrEmpty(taskItem.amragvno)) - { - _RefreshLogMessageAction?.Invoke($"正在为AMR分配任务..."); - _logger.LogInformation($"正在为AMR分配任务"); - //查询AMR状态 - CreateAMRTask(taskItem); - } - //Deliver未派发,AMR已派发 - if (string.IsNullOrEmpty(taskItem.deliveragvno) && !string.IsNullOrEmpty(taskItem.amragvno)) - { - _RefreshLogMessageAction?.Invoke($"正在为AGV分配任务..."); - _logger.LogInformation($"正在为AGV分配任务"); - } - } - - _Taskaction?.Invoke(taskItem); - } - } - } - } - catch (Exception ex) - { - - } - } - - - - - - - - - - - - /// - /// 调用接口更新指定的任务状态 - /// - /// - public void RefreshTaskStateForResopnse(AGVRequestTaskStateDetailEntity request) - { - AGVResponseEntity response = _airpttpClient.AGVGetTaskStateDetailRequest(request); - if (response.code == 1) - { - _logger.LogError("返回错误:" + response.message); - return; - } - if (response.code == 0) - { - AirportTask record = new AirportTask(); - List list = _Taskservice.GetTaskInfos(); - //list.Where(x => x.taskno == response.Data - } - } - - /// - /// 持续读取AGV状态信息 - /// - private void doWhileGetAGVTaskInfo() - { - try - { - Task.Run(() => - { - while (true) - { - GetAGVTaskInfo(null, null); - Task.Delay(1000); - } - - }); - - } - catch (Exception ex) - { - - } - } - - /// - /// 清理Timer - /// - private void InitClearTimer() - { - System.Timers.Timer timer = new System.Timers.Timer - { - Interval = 1000, // 每天执行一次 - AutoReset = true, - - }; - timer.Elapsed += GetAGVTaskInfo; - timer.Start(); - - } - - - /// - /// 向AMR派发任务 - /// - /// - /// - private bool CreateAMRTask(AirportTask AirportTask) - { - bool iflag = false; - try - { - iflag = true; - //获取AMR设备状态 - List State = _AGVStateService.GetAgvState(AgvType.AMR); - foreach (var AgvItem in State) - { - //根据规则筛选最优AGV - if (AgvItem.agvworkstate == "任务空闲") - { - _logger.LogInformation($"获取空闲AMR列表"); - _RefreshLogMessageAction?.Invoke("执行站台[" + AirportTask.conveyorno + "],下发" + "[" + AirportTask.taskno + "]任务"); - //调用派发任务接口,向任务状态为任务空闲的AGV派发任务 - bool iTaskflag = true; - if (iTaskflag) - { - _RefreshLogMessageAction?.Invoke("[" + AgvItem.agvno + "]AMR,执行任务[" + AirportTask.taskno + "]"); - AgvItem.taskno = AirportTask.taskno; - AgvItem.agvworkstate = "任务执行中"; - AgvItem.refreshtime = DateTime.Now; - _AGVStateService.UpdateAsync(AgvItem); - - //更新任务信息表状态为执行中 - AirportTask.amragvno = AgvItem.agvno; - AirportTask.taskstate = "执行中"; - _Taskservice.UpdateTaskAsync(AirportTask); - break; - } - } - } - return iflag; - } - catch (Exception ex) - { - return iflag; - } - } - - /// - /// 向DeliverAGV派发任务 - /// - /// - private bool CreateAGVTask(AirportTask AirportTask) - { - bool iflag = false; - try - { - iflag = true; - //获取DeliverAGV设备状态 - List State = _AGVStateService.GetAgvState(AgvType.Deliver); - foreach (var AgvItem in State) - { - //根据规则筛选最优AGV - if (AgvItem.agvworkstate == "任务空闲") - { - _logger.LogInformation($"获取空闲AGV列表"); - _RefreshLogMessageAction?.Invoke("执行站台[" + AirportTask.conveyorno + "],下发" + "[" + AirportTask.taskno + "]任务"); - //调用派发任务接口,向任务状态为任务空闲的AGV派发任务 - bool iTaskflag = true; - if (iTaskflag) - { - _RefreshLogMessageAction?.Invoke("[" + AgvItem.agvno + "]AGV,执行任务[" + AirportTask.taskno + "]"); - AgvItem.taskno = AirportTask.taskno; - AgvItem.agvworkstate = "任务执行中"; - AgvItem.refreshtime = DateTime.Now; - _AGVStateService.UpdateAsync(AgvItem); - - //更新任务信息表状态为执行中 - AirportTask.deliveragvno = AgvItem.agvno; - AirportTask.taskstate = "执行中"; - _Taskservice.UpdateTaskAsync(AirportTask); - break; - } - } - } - return iflag; - } - catch (Exception ex) - { - return iflag; - } - } - - /// - /// 获取任务状态详情 - /// - private void GetTaskStateDetail() - { - try - { - Task.Run(() => - { - List Task = _Taskservice.GetAGVTaskInfos(); - if (Task.Count > 0) - { - // 设置计时器 - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - //通过任务编号查询agv任务 - - - - // 检查是否超过两秒 - if (stopwatch.ElapsedMilliseconds > 2000) - { - _logger.LogError("超时"); - } - Thread.Sleep(100); - } - - }); - } - catch (Exception ex) - { - - } - } - } } \ No newline at end of file diff --git a/SlnMesnac.Business/base/VisionBusiness.cs b/SlnMesnac.Business/base/VisionBusiness.cs index 5711bec..132854f 100644 --- a/SlnMesnac.Business/base/VisionBusiness.cs +++ b/SlnMesnac.Business/base/VisionBusiness.cs @@ -280,6 +280,7 @@ namespace SlnMesnac.Business.@base _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask(airportTask.deliveragvno, _AGVJobService.GetAGVJobListByTypeAndConveyorNo("800入库", airportTask.conveyorno).JobName); _logger.LogInformation($"任务 [{airportTask.taskno}] Deliver [{airportTask.deliveragvno}] 入库"); + _aGVStateService.ResetAGVStackCount(airportTask.deliveragvno); airportTask.deliveragvno = null; airportTask.deliveragvisarrive = null; _airportTaskService.UpdateTaskAsync(airportTask); @@ -429,6 +430,12 @@ namespace SlnMesnac.Business.@base } } + /// + /// 码垛计数 + /// + /// + /// + /// public void StackCount(AirportTask airportTask, byte lastCount) { //AMR码垛计数 diff --git a/SlnMesnac.Repository/service/IAGVStateService.cs b/SlnMesnac.Repository/service/IAGVStateService.cs index 1821791..6d477b6 100644 --- a/SlnMesnac.Repository/service/IAGVStateService.cs +++ b/SlnMesnac.Repository/service/IAGVStateService.cs @@ -51,5 +51,12 @@ namespace SlnMesnac.Repository.service /// AGVState GetSingleAGVState(string AGVguid); + /// + /// AGV + /// + /// + /// + bool ResetAGVStackCount(string AGVguid); + } } \ No newline at end of file diff --git a/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs b/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs index 89de1d5..7a5b55e 100644 --- a/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs +++ b/SlnMesnac.Repository/service/Impl/AGVStateServiceImpl.cs @@ -31,14 +31,8 @@ namespace SlnMesnac.Repository.service.Impl List agvStateInfoList = null; try { - Expression> exp = x => true; - exp = exp.And(x => - (x.agvno != null || x.agvno != "") - && (x.taskno == null || x.taskno == "") - && x.agvworkstate == "空闲" - && x.agvalarmstate == "正常" - && x.agvtype == _AgvType); - agvStateInfoList = base._rep.GetList(exp); + var a = ((int)AgvType).ToString(); + agvStateInfoList = base._rep.GetList(x => x.agvtype == a); } catch (Exception ex) { @@ -146,5 +140,23 @@ namespace SlnMesnac.Repository.service.Impl return null; } } + + /// + /// 重置AGV计数 + /// + /// + /// + public bool ResetAGVStackCount(string AGVguid) + { + try + { + return _rep.Update(x => new AGVState() { stackcount = 0 }, x => x.agvno == AGVguid); + } + catch (Exception ex) + { + _logger.LogError($"重置计数更新发生错误{ex.Message}"); + return false; + } + } } } \ No newline at end of file diff --git a/SlnMesnac.WPF/Page/ControlPage/UserTaskControl.xaml b/SlnMesnac.WPF/Page/ControlPage/UserTaskControl.xaml index ccc1789..ce031d7 100644 --- a/SlnMesnac.WPF/Page/ControlPage/UserTaskControl.xaml +++ b/SlnMesnac.WPF/Page/ControlPage/UserTaskControl.xaml @@ -5,24 +5,25 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:SlnMesnac.WPF.Page.ControlPage" mc:Ignorable="d" d:DesignWidth="800" Background="Transparent" Height="590"> - - - +