From 5108f663523ad79c165a6ba3f10be098dc07e67b Mon Sep 17 00:00:00 2001 From: anerx <512464164@qq.com> Date: Sun, 23 Mar 2025 13:55:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0AGV=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Seyounth.Hyosung.Core/Agv/HikAgv.cs | 44 ++++++++++++++++--- .../Agv/HikModels/TaskStatusModel.cs | 8 ++++ .../Agv/HyosungAgvService.cs | 13 +++--- 3 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 Seyounth.Hyosung.Core/Agv/HikModels/TaskStatusModel.cs diff --git a/Seyounth.Hyosung.Core/Agv/HikAgv.cs b/Seyounth.Hyosung.Core/Agv/HikAgv.cs index 294be19..a622275 100644 --- a/Seyounth.Hyosung.Core/Agv/HikAgv.cs +++ b/Seyounth.Hyosung.Core/Agv/HikAgv.cs @@ -46,7 +46,8 @@ public class HikAgv(ILogger logger) logger.LogInformation($"task {taskCode} cancel succeed."); } - public async Task CarryToAsync(AgvPosition start, AgvPosition end, string ctnrType, int priority, string taskType) + public async Task CarryToAsync(AgvPosition start, AgvPosition end, string ctnrType, int priority, + string taskType) { var url = Url + SchedulingTaskUri; var input = new @@ -65,19 +66,50 @@ public class HikAgv(ILogger logger) var rs = await PostAsync(url, input); if (rs is null) { - logger.LogWarning($"{start.PositionCode} carry to {end.PositionCode} error: result is null"); - return; + throw new NullReferenceException($"{start.PositionCode} carry to {end.PositionCode} error: result is null"); } if (rs.Code != "0") { - logger.LogWarning($"{start.PositionCode} carry to {end.PositionCode} error: code is {rs.Code} message is {rs.Message}"); - return; + throw new Exception( + $"{start.PositionCode} carry to {end.PositionCode} error: code is {rs.Code} message is {rs.Message}"); } - logger.LogInformation($"{start.PositionCode} carry to {end.PositionCode} succeed"); + return rs.Data; } + public async Task WaitingForTaskCompletedAsync(string taskCode) + { + while (true) + { + var input = new + { + reqCode = GetRequestCode(), + taskCodes = new List { taskCode } + }; + var rs = await PostAsync>(Url + "queryTaskStatus", input); + if (rs is null) + { + throw new NullReferenceException($"task {taskCode} wait completed error: result is null"); + } + + if (rs.Code != "0") + { + throw new Exception($"task {taskCode} wait completed error: code is {rs.Code} message is {rs.Message}"); + } + + // 检查是否有符合条件的任务状态为 9 + var task = rs.Data.FirstOrDefault(t => t.taskCode == taskCode); + if (task is { taskStatus: "9" }) + { + logger.LogInformation($"task {taskCode} wait completed succeed"); + break; // 退出循环 + } + + // 可以添加适当的延迟,避免频繁请求 + await Task.Delay(1000); + } + } public async Task UnBin(AgvBinEntity bin) { diff --git a/Seyounth.Hyosung.Core/Agv/HikModels/TaskStatusModel.cs b/Seyounth.Hyosung.Core/Agv/HikModels/TaskStatusModel.cs new file mode 100644 index 0000000..60eeb59 --- /dev/null +++ b/Seyounth.Hyosung.Core/Agv/HikModels/TaskStatusModel.cs @@ -0,0 +1,8 @@ +namespace Seyounth.Hyosung.Core.Agv.HikModels; + +public class TaskStatusModel +{ + public string taskCode { get; set; } + + public string taskStatus { get; set; } +} \ No newline at end of file diff --git a/Seyounth.Hyosung.Core/Agv/HyosungAgvService.cs b/Seyounth.Hyosung.Core/Agv/HyosungAgvService.cs index 9c6c30b..1ec3295 100644 --- a/Seyounth.Hyosung.Core/Agv/HyosungAgvService.cs +++ b/Seyounth.Hyosung.Core/Agv/HyosungAgvService.cs @@ -24,7 +24,7 @@ public class HyosungAgvService( } while (status is null); var tray = await trayService.GetByCode(trayCode); - var height = (int)Math.Ceiling((double)((tray.StackHeight??0) / 10.0)!); + var height = (int)Math.Ceiling((double)((tray.StackHeight ?? 0) / 10.0)!); var bin = await agvBinService.GetAvailableBin(height); AgvPosition start = new AgvPosition() { @@ -36,17 +36,16 @@ public class HyosungAgvService( PositionCode = bin.CtnrCode, Type = "05" }; - if(!string.IsNullOrEmpty(bin.HeightCode)) - await UnBin(bin); + if (!string.IsNullOrEmpty(bin.HeightCode)) + await UnBin(bin); var ctnrType = await dictService.GetKeyAsync("AgvRackType", bin.Height.ToString()); if (string.IsNullOrEmpty(ctnrType)) ctnrType = "14"; bin.HeightCode = ctnrType; - - await _agv.CarryToAsync(start, stop, ctnrType, 120, "1"); + + var taskCode = await _agv.CarryToAsync(start, stop, ctnrType, 120, "1"); + await _agv.WaitingForTaskCompletedAsync(taskCode); await agvBinService.BindAsync(bin); - //ȴ30 ȷAGVѾѲƷ - await Task.Delay(30 * 1000); } public async Task UnBin(AgvBinEntity bin)