From aae674d78fd00f6566cf3babb0edf0b4ec455a75 Mon Sep 17 00:00:00 2001
From: czw <selecti@yeah.net>
Date: 星期四, 03 七月 2025 11:38:10 +0800
Subject: [PATCH] 1

---
 2025年6月12日/AuxAllWCS/Build/Project/代码/VS自定义类/TcpServer.cs |   34 ++++++++++++++++++++++++----------
 1 files changed, 24 insertions(+), 10 deletions(-)

diff --git "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/TcpServer.cs" "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/TcpServer.cs"
index 7bb9c73..af2c750 100644
--- "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/TcpServer.cs"
+++ "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/Build/Project/\344\273\243\347\240\201/VS\350\207\252\345\256\232\344\271\211\347\261\273/TcpServer.cs"
@@ -8,13 +8,14 @@
 using System.Net;
 using System.Text;
 using System.Threading.Tasks;
+using GZ.Modular.Redis;
 
 namespace GZ.Projects.AuxAllWCS
 {
 
     public class TcpServer
     {
-        public static Dictionary<string,string> TrayIps = new Dictionary<string,string>();
+        public static Dictionary<string, string> TrayIps = new Dictionary<string, string>();
         public TcpServer(string ip)
         {
             Init(ip);
@@ -115,18 +116,27 @@
                         //}
                         //else
                         //{
-                        Console.WriteLine($"銆怲CP淇℃伅鍗忚寮傚父 {DateTime.Now.Millisecond}銆戯細IP锛歿remote_ip},MSG锛歿message}");
+                        Console.WriteLine($"銆怲CP淇℃伅鍗忚 {DateTime.Now.Millisecond}銆戯細IP锛歿remote_ip},MSG锛歿message}");
                         var mg = Encoding.ASCII.GetString(PlcHelper.Hex2Bin(message));
-                        Console.WriteLine(mg);
-                        if (mg.StartsWith("DK") && mg.Trim().Length == "DK01000024".Length)
+                        if (mg.Length > 10)
                         {
-                           if(TrayIps.TryGetValue(remote_ip,out string traycode))
+                            mg = mg.Substring(0, 10);
+                        }
+                        Console.WriteLine(mg);
+                        if (mg.StartsWith("DK"))//&& mg.Trim().Length == "DK01000024".Length
+                        {
+                            LogHelper.Info($"鎵爜鍣�>{remote_ip} -{mg}");
+                            if (TrayIps.TryGetValue(remote_ip, out string traycode))
                             {
-                                TrayIps[remote_ip] = traycode;
-                            }else TrayIps.Add(remote_ip, traycode);
-                            Console.WriteLine("TOFF");
-                            var mst = PlcHelper.Hex2Bin("544F4646");
-                            TcpServer.TcpServerSend(remote_ip, mst);
+                                TrayIps[remote_ip] = mg;
+                            }
+                            else TrayIps.Add(remote_ip, mg);
+
+                            RedisHelper.Add("S鎵爜鍣� + (remote_ip.Split('.').LastOrDefault()), mg, out string msg);
+                            RedisHelper.Add("S鎵爜鍣� + (remote_ip.Split('.').LastOrDefault()) + "#time", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), out msg);
+                            //Console.WriteLine("TOFF");
+                            //var mst = PlcHelper.Hex2Bin("544F4646");
+                            //TcpServer.TcpServerSend(remote_ip, mst);
                         }
                         //}
                     }
@@ -159,6 +169,7 @@
 
         public static bool TcpServerSend(string ip, byte[] msg)
         {
+            LogHelper.Info($"TcpServerSend >{ip}:{msg}");
             if (clients.Keys.Contains(ip))
             {
                 var client = clients[ip];
@@ -167,6 +178,7 @@
                     try
                     {
                         client.Send(msg);
+                        LogHelper.Info($"TcpServerSend > 鍙戦�鎴愬姛銆�);
                         return true;
                     }
                     catch (SocketException ex)
@@ -219,6 +231,8 @@
             // 杞崲鍥炲崄杩涘埗
             return Convert.ToInt32(new string(binaryChars), 2);
         }
+        public static List<string> GetStaticClients() => clients.Keys.ToList();
+        public static Dictionary<string, string> GetStaticScan() => TrayIps;
     }
 }
 

--
Gitblit v1.9.1