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)