From 17e5dbd7bd0364e27a33f1a7dab91cf33d5dcabc Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期三, 04 三月 2026 11:52:12 +0800
Subject: [PATCH] 增强Redis缓存服务与设备通信优化
---
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs | 443 +++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 315 insertions(+), 128 deletions(-)
diff --git a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
index e338e6f..bd3d436 100644
--- a/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
+++ b/Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotJob.cs
@@ -1,19 +1,22 @@
锘縰sing HslCommunication;
using Newtonsoft.Json;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup;
using Quartz;
-using System.Collections.Concurrent;
+using System.Net;
using System.Net.Sockets;
-using System.Text.Json;
+using System.Threading.Tasks;
+using WIDESEA_Core;
+using WIDESEAWCS_Common;
using WIDESEAWCS_Common.HttpEnum;
+using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
+using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_Core.Helper;
-using WIDESEAWCS_Core.Http;
using WIDESEAWCS_DTO.Stock;
-using WIDESEAWCS_ITaskInfoRepository;
+using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_ITaskInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
-using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.SocketServer;
namespace WIDESEAWCS_Tasks
@@ -21,18 +24,31 @@
[DisallowConcurrentExecution]
public class RobotJob : IJob
{
- private readonly TcpSocketServer _TcpSocket;
- private static readonly ConcurrentDictionary<string, RobotSocketState> _socketStates = new();
- private static int _eventSubscribedFlag;
- private readonly IRobotTaskService _taskService;
- private readonly ITaskExecuteDetailService _taskExecuteDetailService;
- private readonly ITaskRepository _taskRepository;
- private readonly IRouterService _routerService;
+ private const int MaxTaskTotalNum = 48;
- public RobotJob(TcpSocketServer TcpSocket, IRobotTaskService taskService)
+ private readonly TcpSocketServer _TcpSocket;
+
+ //private static readonly ConcurrentDictionary<string, RobotSocketState> _socketStates = new();
+ private static int _eventSubscribedFlag;
+
+ private readonly ITaskService _taskService;
+ private readonly IRobotTaskService _robotTaskService;
+ private readonly ICacheService _cache;
+ private readonly HttpClientHelper _httpClientHelper;
+
+ private static IRobotTaskService _latestRobotTaskService = null!;
+ private static ITaskService _latestTaskService = null!;
+
+ public RobotJob(TcpSocketServer TcpSocket, IRobotTaskService RobottaskService, ITaskService TaskService, ICacheService cache, HttpClientHelper httpClientHelper)
{
_TcpSocket = TcpSocket;
- _taskService = taskService;
+ _robotTaskService = RobottaskService;
+ _taskService = TaskService;
+ _cache = cache;
+ _httpClientHelper = httpClientHelper;
+
+ _latestRobotTaskService = RobottaskService;
+ _latestTaskService = TaskService;
}
public async Task Execute(IJobExecutionContext context)
@@ -47,7 +63,7 @@
string ipAddress = robotCrane.IPAddress;
// 鑾峰彇鎴栧垱寤虹姸鎬�
- RobotSocketState state = _socketStates.GetOrAdd(ipAddress, _ => new RobotSocketState
+ RobotSocketState state = _cache.GetOrAdd($"{RedisPrefix.Code}:{RedisName.SocketDevices}:{ipAddress}", _ => new RobotSocketState
{
IPAddress = ipAddress,
RobotCrane = robotCrane
@@ -56,56 +72,125 @@
// 鏇存柊璁惧淇℃伅
state.RobotCrane = robotCrane;
- // 妫�鏌ユ槸鍚︽湁璇ュ鎴风杩炴帴
- var clientIds = _TcpSocket.GetClientIds();
- if (!clientIds.Contains(ipAddress))
+ try
{
- return;
- }
-
- // 璁㈤槄涓�娆� message 浜嬩欢锛堝叏灞�涓�娆★級
- if (Interlocked.CompareExchange(ref _eventSubscribedFlag, 1, 0) == 0)
- {
- _TcpSocket.MessageReceived += _TcpSocket_MessageReceived;
- _TcpSocket.RobotReceived += _TcpSocket_RobotReceived;
- }
-
- if (!state.IsEventSubscribed)
- {
- _TcpSocket._clients.TryGetValue(ipAddress, out TcpClient client);
- Task clientTask = _TcpSocket.HandleClientAsync(client, robotCrane.IPAddress, _TcpSocket._cts.Token, state);
- state.IsEventSubscribed = true;
- }
-
- // 鑾峰彇浠诲姟骞剁紦瀛樺埌鐘舵�佷腑
- Dt_RobotTask? task = GetTask(robotCrane);
- if (task != null)
- {
- state.CurrentTask = task;
- if (task.RobotTaskTotalNum != 48)
+ // 妫�鏌ユ槸鍚︽湁璇ュ鎴风杩炴帴
+ var clientIds = _TcpSocket.GetClientIds();
+ if (!clientIds.Contains(ipAddress))
{
- // 澶勭悊姝e湪鎵ц鐨勪换鍔�
- if (state.RobotRunMode == 1 && state.RobotControlMode == 1)
- {
- await Task.Delay(1000);
- if ((state.CurrentAction == "Homed" || state.CurrentAction == "PickFinished" || state.CurrentAction == "PutFinished") && state.OperStatus == "Running")
- {
- // TODO 璇诲彇绾夸綋鐢垫睜鏉$爜锛屽彂閫佸彇鐢垫睜鎸囦护
- if (true)
- {
- // 妯℃嫙璇诲彇鏉$爜
- state.CellBarcode = new string[] { "CellBarcode1", "CellBarcode2", "CellBarcode3", "CellBarcode4" };
+ return;
+ }
- string taskString = $"Pickbattery,{task.RobotSourceAddress}";
- // 鍙戦�佷换鍔℃寚浠�
+ // 璁㈤槄涓�娆� message 浜嬩欢锛堝叏灞�涓�娆★級
+ if (Interlocked.CompareExchange(ref _eventSubscribedFlag, 1, 0) == 0)
+ {
+ _TcpSocket.MessageReceived += _TcpSocket_MessageReceived;
+ _TcpSocket.RobotReceived += _TcpSocket_RobotReceived;
+ }
+
+ if (!state.IsEventSubscribed)
+ {
+ if (_TcpSocket._clients.TryGetValue(ipAddress, out TcpClient client))
+ {
+ _ = _TcpSocket.HandleClientAsync(client, robotCrane.IPAddress, _TcpSocket._cts.Token, state)
+ .ContinueWith(t =>
+ {
+ if (t.IsFaulted)
+ Console.WriteLine($"HandleClientAsync error: {t.Exception?.GetBaseException().Message}");
+ }, TaskContinuationOptions.OnlyOnFaulted);
+ state.IsEventSubscribed = true;
+
+ // 鏇存柊缂撳瓨涓殑鐘舵��
+ _cache.TryUpdateIfChanged($"{RedisPrefix.Code}:{RedisName.SocketDevices}:{ipAddress}", state);
+ }
+ }
+
+ // 鑾峰彇浠诲姟骞剁紦瀛樺埌鐘舵�佷腑
+ Dt_RobotTask? task = GetTask(robotCrane);
+ if (task != null)
+ {
+ if (task.RobotTaskTotalNum <= MaxTaskTotalNum)
+ {
+ // 澶勭悊姝e湪鎵ц鐨勪换鍔�
+ if (state.RobotRunMode == 2 && state.RobotControlMode == 1 && state.OperStatus != "Running")
+ {
+ if (state.CurrentAction == "PickFinished" && state.RobotArmObject == 1 && task.RobotTaskState == TaskRobotStatusEnum.RobotPickFinish.GetHashCode())
+ {
+ string taskString = $"Putbattery,{task.RobotTargetAddress}";
bool result = await _TcpSocket.SendToClientAsync(ipAddress, taskString);
+ if (result)
+ {
+ task.RobotTaskState = TaskRobotStatusEnum.RobotExecuting.GetHashCode();
+ await _robotTaskService.UpdateRobotTaskAsync(task);
+ }
+ }
+ else if (state.CurrentAction == "PutFinished" && state.RobotArmObject == 0 && task.RobotTaskState == TaskRobotStatusEnum.RobotPutFinish.GetHashCode())
+ {
+ task.RobotTaskState = TaskRobotStatusEnum.RobotExecuting.GetHashCode();
+ await _robotTaskService.UpdateRobotTaskAsync(task);
+ }
+ else if (state.OperStatus == "Homed" && state.RobotArmObject == 0 && task.RobotTaskState != TaskRobotStatusEnum.RobotExecuting.GetHashCode())
+ {
+ // 闅忔満鐢熸垚涓ゅぉ鎵樼洏鏉$爜瀛樻斁鍒颁袱涓彉閲忛噷闈�
+ // 瀹氫箟鍓嶇紑锛堜緥濡傦細TRAY浠h〃鎵樼洏锛�
+ // 缁勭洏璇诲彇绾夸綋鏉$爜
+ if (task.RobotTaskType == RobotTaskTypeEnum.GroupPallet.GetHashCode())
+ {
+ string prefix = "TRAY";
+
+ // 鐢熸垚涓や釜鎵樼洏鏉$爜
+ string trayBarcode1 = GenerateTrayBarcode(state, prefix);
+ string trayBarcode2 = GenerateTrayBarcode(state, prefix);
+ if (!trayBarcode1.IsNullOrEmpty() && !trayBarcode2.IsNullOrEmpty())
+ {
+
+ await SendSocketRobotPickAsync(task, state);
+ }
+ }
+ else // 鎹㈢洏鐩存帴鍙戦�佸彇璐у湴鍧�
+ {
+ await SendSocketRobotPickAsync(task, state);
+ }
+ }
+
+ if (state.CurrentTask.IsNullOrEmpty() && state.ToJson() != task.ToJson())
+ {
+ state.IsSplitPallet = task.RobotTaskType == RobotTaskTypeEnum.SplitPallet.GetHashCode();
+ state.IsGroupPallet = task.RobotTaskType == RobotTaskTypeEnum.GroupPallet.GetHashCode() || task.RobotTaskType == RobotTaskTypeEnum.ChangePallet.GetHashCode();
+ state.CurrentTask = task;
+ // 鏇存柊缂撳瓨涓殑鐘舵��
+ _cache.TryUpdateIfChanged($"{RedisPrefix.Code}:{RedisName.SocketDevices}:{ipAddress}", state);
}
}
}
}
}
+ catch (Exception)
+ {
+ }
+ finally
+ {
+ // 鍙�夛細鍦ㄨ繖閲屽鐞嗕换浣曢渶瑕佸湪浠诲姟瀹屾垚鍚庢墽琛岀殑娓呯悊宸ヤ綔
+ }
+ }
- return;
+ //涓存椂娴嬭瘯鐢�
+ private static string GenerateTrayBarcode(RobotSocketState state, string prefix = "")
+ {
+ // 褰撳墠鏃ユ湡
+ string datePart = DateTime.Now.ToString("yyyyMMdd");
+
+ // 鏃堕棿鎴筹紙鏃跺垎绉掞級
+ string timePart = DateTime.Now.ToString("HHmmss");
+
+ // 闅忔満鏁�
+ string randomPart = Random.Shared.Next(100, 1000).ToString();
+
+ // 缁勫悎锛氬墠缂� + 鏃ユ湡 + 鏃堕棿 + 闅忔満鏁�
+ var barCode = prefix + datePart + timePart + randomPart;
+ state.CellBarcode.Add(barCode);
+
+ return barCode;
}
/// <summary>
@@ -115,7 +200,14 @@
/// <returns></returns>
private Task<string?> _TcpSocket_RobotReceived(string clientId)
{
- _socketStates.TryRemove(clientId, out _);
+ var robotSocketState = _cache.Get<RobotSocketState>($"{RedisPrefix.Code}:{RedisName.SocketDevices}:{clientId}");
+ robotSocketState.IsEventSubscribed = false;
+ robotSocketState.CurrentAction = "";
+ robotSocketState.OperStatus = "";
+ robotSocketState.RobotArmObject = 0;
+ robotSocketState.RobotControlMode = 0;
+ robotSocketState.RobotRunMode = 0;
+ _cache.TryUpdateIfChanged($"{RedisPrefix.Code}:{RedisName.SocketDevices}:{clientId}", robotSocketState);
return Task.FromResult<string?>(null);
}
@@ -129,95 +221,90 @@
/// <returns></returns>
private async Task<string?> _TcpSocket_MessageReceived(string message, bool isJson, TcpClient client, RobotSocketState state)
{
- WebResponseContent content = new WebResponseContent();
+ if (!(bool)(_cache?.TryGetValue($"{RedisPrefix.Code}:{RedisName.SocketDevices}:{client.Client.RemoteEndPoint}", out state)))
+ return null;
+
string messageLower = message.ToLowerInvariant();
- if (IsSimpleCommand(messageLower, state))
+ if (await IsSimpleCommandAsync(messageLower, state))
{
- return null;
+ await _TcpSocket.SendMessageAsync(client, message);
}
-
- if (IsPrefixCommand(messageLower))
+ else if (IsPrefixCommand(messageLower))
{
try
{
var parts = message.Split(',');
- if (parts.Length >= 1)
+ if (parts.Length >= 1 && state.CurrentTask != null)
{
var cmd = parts[0].ToLowerInvariant();
- int[] positions = new int[4];
- for (int i = 1; i <= 4 && i < parts.Length; i++)
- {
- int.TryParse(parts[i], out positions[i - 1]);
- }
+ int[] positions = parts.Skip(1)
+ .Select(p => int.TryParse(p, out int value) ? value : (int?)null)
+ .Where(v => v.HasValue && v.Value != 0)
+ .Select(v => v!.Value)
+ .ToArray();
+
+ var task = await _latestRobotTaskService.Repository.QueryFirstAsync(x => x.RobotTaskId == state.CurrentTask.RobotTaskId);
if (cmd.StartsWith("pickfinished"))
{
- StockDTO stockDTO = new StockDTO
+ if (state.IsSplitPallet)
{
- SourceLineNo = state.CurrentTask?.RobotSourceAddressLineCode,
- SourcePalletNo = state.CurrentTask?.RobotSourceAddressPalletCode,
- TargetPalletNo = state.CurrentTask?.RobotTargetAddressPalletCode,
- TargetLineNo = state.CurrentTask?.RobotTargetAddressLineCode,
- Details = positions
- .Where(x => x > 0)
- .OrderBy(x => x)
- .Select((x, idx) => new StockDetailDTO
- {
- Quantity = state.CurrentTask?.RobotTaskTotalNum ?? 1,
- Channel = x > 0 ? x : throw new ArgumentOutOfRangeException(nameof(x), "Channel must be positive"),
- CellBarcode = state.CellBarcode[idx]
- })
- .ToList()
- };
- state.LastPickPositions = positions;
+ var stockDTO = BuildStockDTO(state, positions);
+ state.LastPickPositions = positions;
- var result = await HttpRequestHelper.HTTPPostAsync(nameof(Category.WMS), stockDTO.ToJsonString(), state.CurrentTask?.RobotTaskType == 2 ? nameof(ConfigKey.ChangePalletAsync) : nameof(ConfigKey.SplitPalletAsync));
- content = JsonConvert.DeserializeObject<WebResponseContent>(result);
+ var result = _httpClientHelper.Post<WebResponseContent>(nameof(ConfigKey.SplitPalletAsync), stockDTO.ToJson());
- if (content.Status)
+ if (result.Data.Status && result.IsSuccess)
+ {
+ state.CurrentAction = "PickFinished";
+ }
+ }
+ else
{
state.CurrentAction = "PickFinished";
}
+
+ state.LastPickPositions = positions;
+ task.RobotTaskState = TaskRobotStatusEnum.RobotPickFinish.GetHashCode();
+ await _latestRobotTaskService.Repository.UpdateDataAsync(task);
}
else if (cmd.StartsWith("putfinished"))
{
- state.LastPutPositions = positions;
- if (state.CurrentTask?.RobotTaskType == 1)
+ bool putSuccess = true;
+ if (state.IsGroupPallet)
{
- // 鍙戦�佹暟鎹粰WMS缁勭洏/鎹㈢洏
- StockDTO stockDTO = new StockDTO
- {
- SourceLineNo = state.CurrentTask?.RobotSourceAddressLineCode,
- SourcePalletNo = state.CurrentTask?.RobotSourceAddressPalletCode,
- TargetPalletNo = state.CurrentTask?.RobotTargetAddressPalletCode,
- TargetLineNo = state.CurrentTask?.RobotTargetAddressLineCode,
- Details = positions
- .Where(x => x > 0)
- .OrderBy(x => x)
- .Select((x, idx) => new StockDetailDTO
- {
- Quantity = state.CurrentTask?.RobotTaskTotalNum ?? 1,
- Channel = x > 0 ? x : throw new ArgumentOutOfRangeException(nameof(x), "Channel must be positive"),
- CellBarcode = state.CellBarcode[idx]
- })
- .ToList()
- };
- var result = await HttpRequestHelper.HTTPPostAsync(nameof(Category.WMS), stockDTO.ToJsonString(), nameof(ConfigKey.GroupPalletAsync));
- content = JsonConvert.DeserializeObject<WebResponseContent>(result);
+ state.LastPutPositions = positions;
+ var stockDTO = BuildStockDTO(state, positions);
+ var configKey = state.CurrentTask?.RobotTaskType == RobotTaskTypeEnum.ChangePallet.GetHashCode()
+ ? nameof(ConfigKey.ChangePalletAsync) : nameof(ConfigKey.GroupPalletAsync);
- if (content.Status)
- {
- state.CurrentAction = "PutFinished";
- }
+ var result = _httpClientHelper.Post<WebResponseContent>(configKey, stockDTO.ToJson());
+ putSuccess = result.Data.Status && result.IsSuccess;
}
+
+ if (putSuccess)
+ {
+ state.CurrentAction = "PutFinished";
+ state.RobotTaskTotalNum += positions.Length;
+ task.RobotTaskTotalNum += positions.Length;
+ }
+
+ task.RobotTaskState = TaskRobotStatusEnum.RobotPutFinish.GetHashCode();
+ await _latestRobotTaskService.Repository.UpdateDataAsync(task);
}
+
+ await _TcpSocket.SendMessageAsync(client, message);
}
}
- catch { }
-
- return null;
+ catch (Exception ex)
+ {
+ Console.WriteLine($"RobotJob MessageReceived Error: {ex.Message}");
+ }
}
+
+ // 鏇存柊缂撳瓨涓殑鐘舵��
+ _cache.TryUpdateIfChanged($"{RedisPrefix.Code}:{RedisName.SocketDevices}:{state.IPAddress}", state);
return null;
}
@@ -228,16 +315,16 @@
/// <param name="message"></param>
/// <param name="state"></param>
/// <returns></returns>
- private bool IsSimpleCommand(string message, RobotSocketState state)
+ private async Task<bool> IsSimpleCommandAsync(string message, RobotSocketState state)
{
switch (message)
{
case "homing":
- state.CurrentAction = "Homing";
+ state.OperStatus = "Homing";
return true;
case "homed":
- state.CurrentAction = "Homed";
+ state.OperStatus = "Homed";
return true;
case "picking":
@@ -248,19 +335,19 @@
state.CurrentAction = "Putting";
return true;
- case "allpickfinished":
+ case "allpickfinished": // 鍙栬揣瀹屾垚
state.CurrentAction = "AllPickFinished";
- if(state.CurrentTask?.RobotTaskType == 2|| state.CurrentTask?.RobotTaskType == 3)
+ if (state.CurrentTask?.RobotTaskType == RobotTaskTypeEnum.SplitPallet.GetHashCode() || state.CurrentTask?.RobotTaskType == RobotTaskTypeEnum.ChangePallet.GetHashCode())
{
- // TODO 鏈烘鎵嬪彇璐у畬鎴愶紝鍒ゆ柇鏄惁鎹㈢洏銆佹媶鐩樹换鍔★紝鍒涘缓绌烘墭鐩樺洖搴撲换鍔�
+ await HandleInboundTaskAsync(state, useSourceAddress: true);
}
return true;
- case "allputfinished":
+ case "allputfinished": // 鏀捐揣瀹屾垚
state.CurrentAction = "AllPutFinished";
- if (state.CurrentTask?.RobotTaskType == 1 )
+ if (state.CurrentTask?.RobotTaskType == RobotTaskTypeEnum.GroupPallet.GetHashCode() || state.CurrentTask?.RobotTaskType == RobotTaskTypeEnum.ChangePallet.GetHashCode())
{
- // TODO 鏈烘鎵嬪彇璐у畬鎴愶紝鍒ゆ柇鏄惁缁勭洏浠诲姟锛屽垱寤虹粍鐩樺叆搴撲换鍔�
+ await HandleInboundTaskAsync(state, useSourceAddress: false);
}
return true;
@@ -309,6 +396,48 @@
}
}
+ private async Task HandleInboundTaskAsync(RobotSocketState state, bool useSourceAddress)
+ {
+ var currentTask = state.CurrentTask;
+ if (currentTask == null)
+ {
+ return;
+ }
+
+ string roadway = currentTask.RobotRoadway == "1" ? "GWSC001" : currentTask.RobotRoadway == "2" ? "HCSC001" : "SC001";
+ int warehouseId = currentTask.RobotRoadway == "1" ? 1 : currentTask.RobotRoadway == "2" ? 2 : 3;
+
+ CreateTaskDto taskDto = new CreateTaskDto
+ {
+ PalletCode = currentTask.RobotTargetAddressPalletCode ?? string.Empty,
+ SourceAddress = currentTask.RobotSourceAddress ?? string.Empty,
+ TargetAddress = currentTask.RobotTargetAddress ?? string.Empty,
+ Roadway = roadway,
+ WarehouseId = warehouseId,
+ PalletType = 1,
+ TaskType = 4
+ };
+ var result = _httpClientHelper.Post<WebResponseContent>(nameof(ConfigKey.CreateTaskInboundAsync), taskDto.ToJson());
+ if (!result.Data.Status && result.IsSuccess)
+ {
+ return;
+ }
+
+ WMSTaskDTO taskDTO = JsonConvert.DeserializeObject<WMSTaskDTO>(result.Data.ToString() ?? string.Empty) ?? new WMSTaskDTO();
+ var content = _latestTaskService.ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
+ if (!content.Status) return;
+
+ var taskInfo = _latestTaskService.QueryByTaskNum(taskDTO.TaskNum);
+ if (taskInfo == null) return;
+
+ string targetAddress = useSourceAddress ? taskDTO.SourceAddress : taskDTO.TargetAddress;
+
+ IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceProDTOs.Any(d => d.DeviceChildCode == targetAddress));
+ device?.Communicator.Write(nameof(ConveyorLineDBNameNew.Target), taskInfo.NextAddress);
+ device?.Communicator.Write(nameof(ConveyorLineDBNameNew.TaskNo), taskDTO.TaskNum);
+ device?.Communicator.Write(nameof(ConveyorLineDBNameNew.WCS_STB), 1);
+ }
+
/// <summary>
/// 鏈烘鎵嬪墠缂�鍛戒护澶勭悊
/// </summary>
@@ -319,9 +448,52 @@
return message.StartsWith("pickfinished") || message.StartsWith("putfinished");
}
+ private static StockDTO BuildStockDTO(RobotSocketState state, int[] positions)
+ {
+ string sss = state.ToJson();
+ return new StockDTO
+ {
+ SourceLineNo = state.CurrentTask.RobotSourceAddressLineCode,
+ SourcePalletNo = state.CurrentTask.RobotSourceAddressPalletCode,
+ TargetPalletNo = state.CurrentTask.RobotTargetAddressPalletCode,
+ TargetLineNo = state.CurrentTask.RobotTargetAddressLineCode,
+ Details = positions
+ .Where(x => x > 0)
+ .OrderBy(x => x)
+ .Select((x, idx) => new StockDetailDTO
+ {
+ Quantity = state.RobotTaskTotalNum > 0 ? state.RobotTaskTotalNum + positions.Length : positions.Length,
+ Channel = x,
+ CellBarcode = state.CellBarcode?.Count > 0 ? state.CellBarcode[x - 1] : ""
+ })
+ .ToList()
+ };
+ }
+
private Dt_RobotTask? GetTask(RobotCraneDevice robotCrane)
{
- return _taskService.QueryRobotCraneTask(robotCrane.DeviceCode);
+ return _robotTaskService.QueryRobotCraneTask(robotCrane.DeviceCode);
+ }
+
+ /// <summary>
+ /// 鍙戦�佹満姊版墜鍙栬揣鍛戒护
+ /// </summary>
+ /// <param name="task"></param>
+ /// <param name="state"></param>
+ /// <returns></returns>
+ private async Task SendSocketRobotPickAsync(Dt_RobotTask task, RobotSocketState state)
+ {
+ string taskString = $"Pickbattery,{task.RobotSourceAddress}";
+ // 鍙戦�佷换鍔℃寚浠�
+ bool result = await _TcpSocket.SendToClientAsync(state.IPAddress, taskString);
+ if (result)
+ {
+ // TODO 澶勭悊鎴愬姛鍙戦�佷换鍔℃寚浠ゅ悗鐨勯�昏緫
+ task.RobotTaskState = TaskRobotStatusEnum.RobotExecuting.GetHashCode();
+ result = await _robotTaskService.UpdateRobotTaskAsync(task);
+ // 鏇存柊缂撳瓨涓殑鐘舵��
+ _cache.TryUpdateIfChanged($"{RedisPrefix.Code}:{RedisName.SocketDevices}:{state.IPAddress}", state);
+ }
}
}
@@ -345,7 +517,7 @@
public int? RobotControlMode { get; set; }
/// <summary>
- /// 鏈烘鎵嬫姄鍙栧璞�
+ /// 鏈烘鎵嬫槸鍚︽姄鍙栫墿鏂欙紝0-鏃犵墿鏂欙紝1-鏈夌墿鏂�
/// </summary>
public int? RobotArmObject { get; set; }
@@ -377,11 +549,26 @@
/// <summary>
/// 鎶撳彇浣嶇疆鏉$爜
/// </summary>
- public string[] CellBarcode { get; set; }
+ public List<string> CellBarcode { get; set; }
/// <summary>
/// 褰撳墠鎶撳彇浠诲姟
/// </summary>
public Dt_RobotTask? CurrentTask { get; set; }
+
+ /// <summary>
+ /// 鏄惁闇�瑕佹媶鐩�
+ /// </summary>
+ public bool IsSplitPallet { get; set; }
+
+ /// <summary>
+ /// 鏄惁闇�瑕佺粍鐩�
+ /// </summary>
+ public bool IsGroupPallet { get; set; }
+
+ /// <summary>
+ /// 浠诲姟鎬绘暟
+ /// </summary>
+ public int RobotTaskTotalNum { get; set; }
}
}
\ No newline at end of file
--
Gitblit v1.9.3