wankeda
2026-01-13 ce3b28cdcdb2b6a912413cd9e744d0ecadcb78a0
WCS/WIDESEAWCS_Server/WIDESEAWCS_TaskInfoService/TaskService.cs
@@ -26,6 +26,7 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Net.Sockets;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@@ -495,6 +496,56 @@
            return content;
        }
        public WebResponseContent LedShowTask(string stationCode, string palletCode, int taskType)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                // 获取LED服务地址配置
                string ledApiAddress = AppSettings.Get("LEDApiAddress");
                if (string.IsNullOrEmpty(ledApiAddress))
                {
                    return WebResponseContent.Instance.Error("未找到LED服务地址");
                }
                // 解析IP地址(处理可能包含的http://前缀)
                string ipAddress = ledApiAddress;
                int port = 8888; // 默认端口
                // 拼接推送格式
                string sendData = $"{stationCode}|{palletCode}|{taskType}";
                // TCP连接WinForm
                using (TcpClient tcpClient = new TcpClient())
                {
                    // 设置连接超时
                    tcpClient.ReceiveTimeout = 5000;
                    tcpClient.SendTimeout = 5000;
                    // 连接TCP服务
                    tcpClient.Connect(ipAddress, port);
                    NetworkStream stream = tcpClient.GetStream();
                    byte[] data = Encoding.UTF8.GetBytes(sendData);
                    stream.Write(data, 0, data.Length);
                    stream.Flush();
                    Console.WriteLine($"✅ TCP数据发送成功:{sendData}");
                }
            }
            catch (SocketException socketEx)
            {
            }
            catch (Exception ex)
            {
                content = WebResponseContent.Instance.Error($"LED推送失败:{ex.Message}");
            }
            return content;
        }
        /// <summary>
        /// 
        /// </summary>