1
czw
2025-07-03 c066f9be49a723b39104e4a199b35604aa772b7f
2025Äê6ÔÂ12ÈÕ/AuxAllWCS/Build/Project/´úÂë/VS×Ô¶¨ÒåÀà/TcpServer.cs
@@ -8,6 +8,7 @@
using System.Net;
using System.Text;
using System.Threading.Tasks;
using GZ.Modular.Redis;
namespace GZ.Projects.AuxAllWCS
{
@@ -117,19 +118,25 @@
                        //{
                        Console.WriteLine($"【TCP信息协议 {DateTime.Now.Millisecond}】:IP:{remote_ip},MSG:{message}");
                        var mg = Encoding.ASCII.GetString(PlcHelper.Hex2Bin(message));
                        if (mg.Length > 10)
                        {
                            mg = mg.Substring(0, 10);
                        }
                        Console.WriteLine(mg);
                        if (mg.StartsWith("DK") && mg.Trim().Length == "DK01000024".Length)
                        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;
                                TrayIps[remote_ip] = mg;
                            }
                            else TrayIps.Add(remote_ip, traycode);
                            else TrayIps.Add(remote_ip, mg);
                            Console.WriteLine("TOFF");
                            var mst = PlcHelper.Hex2Bin("544F4646");
                            TcpServer.TcpServerSend(remote_ip, mst);
                            RedisHelper.Add("Scan" + (remote_ip.Split('.').LastOrDefault()), mg, out string msg);
                            RedisHelper.Add("Scan" + (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);
                        }
                        //}
                    }
@@ -162,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];
@@ -170,6 +178,7 @@
                    try
                    {
                        client.Send(msg);
                        LogHelper.Info($"TcpServerSend > å‘送成功。");
                        return true;
                    }
                    catch (SocketException ex)
@@ -222,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;
    }
}