wanshenmean
15 小时以前 627371d0ffdf50239313f2c86d022a0c5c69550d
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/RobotJob/RobotClientManager.cs
@@ -1,6 +1,6 @@
using Serilog;
using System.Collections.Concurrent;
using System.Net.Sockets;
using Microsoft.Extensions.Logging;
using WIDESEAWCS_Core.LogHelper;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
@@ -101,8 +101,7 @@
                // 清理该客户端的 HandleClientAsync 启动标志
                // 以便下次重连时可以重新启动处理
                _handleClientStarted.TryRemove(ipAddress, out _);
                _logger.LogDebug("客户端未连接,IP: {IpAddress}", ipAddress);
                QuartzLogger.Debug($"客户端未连接,IP: {ipAddress}", robotCrane.DeviceName);
                QuartzLogHelper.LogDebug(_logger, $"客户端未连接,IP: {ipAddress}", robotCrane.DeviceName);
                return false;
            }
@@ -113,8 +112,7 @@
                // 绑定客户端断开连接的事件处理
                _tcpSocket.RobotReceived += OnRobotReceived;
                // 记录日志:事件订阅成功
                _logger.LogInformation("机械手TCP消息事件已订阅,设备: {DeviceName}", robotCrane.DeviceName);
                QuartzLogger.Info($"机械手TCP消息事件已订阅", robotCrane.DeviceName);
                QuartzLogHelper.LogInfo(_logger, $"机械手TCP消息事件已订阅", robotCrane.DeviceName);
            }
            // 从 TCP 服务器的客户端字典中获取 TcpClient 对象
@@ -126,8 +124,7 @@
            {
                // 移除启动标志,返回 false 表示客户端不可用
                _handleClientStarted.TryRemove(ipAddress, out _);
                _logger.LogWarning("获取TcpClient失败,IP: {IpAddress}", ipAddress);
                QuartzLogger.Warn($"获取TcpClient失败,IP: {ipAddress}", robotCrane.DeviceName);
                QuartzLogHelper.LogWarn(_logger, $"获取TcpClient失败,IP: {ipAddress}", robotCrane.DeviceName);
                return false;
            }
@@ -138,8 +135,7 @@
            if (!alreadyStarted)
            {
                // 记录日志:启动消息处理
                _logger.LogInformation("启动客户端消息处理,IP: {IpAddress}", ipAddress);
                QuartzLogger.Info($"启动客户端消息处理", robotCrane.DeviceName);
                QuartzLogHelper.LogInfo(_logger, $"启动客户端消息处理,IP: {ipAddress}", robotCrane.DeviceName);
                // 获取最新的状态对象
                var latestStateForSubscribe = _stateManager.GetState(ipAddress);
@@ -157,8 +153,7 @@
                            if (t.IsFaulted)
                            {
                                // 记录错误日志
                                _logger.LogError(t.Exception, "监听客户端消息事件异常,IP: {IpAddress}", ipAddress);
                                QuartzLogger.Error($"监听客户端消息事件异常", robotCrane.DeviceName, t.Exception);
                                QuartzLogHelper.LogError(_logger, t.Exception, $"监听客户端消息事件异常,IP: {ipAddress}", $"监听客户端消息事件异常,IP: {ipAddress}", robotCrane.DeviceName);
                                // 发生错误时,移除启动标志,允许下次重试
                                _handleClientStarted.TryRemove(ipAddress, out _);
                            }
@@ -195,8 +190,7 @@
            _handleClientStarted.TryRemove(clientId, out _);
            // 记录日志:客户端断开连接
            _logger.LogInformation("客户端断开连接,IP: {ClientId}", clientId);
            QuartzLogger.Info($"客户端断开连接", clientId);
            QuartzLogHelper.LogInfo(_logger, $"客户端断开连接,IP: {clientId}", clientId);
            // 重置该客户端的状态信息
            _stateManager.TryUpdateStateSafely(clientId, state =>