1
czw
2025-07-03 99da99b13c68c5f2b82da2764d54b92b1b598657
2025Äê6ÔÂ12ÈÕ/AuxAllWCS/Build/Project/´úÂë/VS×Ô¶¨ÒåÀà/TcpServer.cs
@@ -14,7 +14,7 @@
    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 +115,25 @@
                        //}
                        //else
                        //{
                        Console.WriteLine($"【TCP信息协议异常 {DateTime.Now.Millisecond}】:IP:{remote_ip},MSG:{message}");
                        Console.WriteLine($"【TCP信息协议 {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);
                            //Console.WriteLine("TOFF");
                            //var mst = PlcHelper.Hex2Bin("544F4646");
                            //TcpServer.TcpServerSend(remote_ip, mst);
                        }
                        //}
                    }
@@ -159,6 +166,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 +175,7 @@
                    try
                    {
                        client.Send(msg);
                        LogHelper.Info($"TcpServerSend > å‘送成功。");
                        return true;
                    }
                    catch (SocketException ex)
@@ -219,6 +228,8 @@
            // è½¬æ¢å›žåè¿›åˆ¶
            return Convert.ToInt32(new string(binaryChars), 2);
        }
        public static List<string> GetStaticClients() => clients.Keys.ToList();
        public static Dictionary<string, string> GetStaticScan() => TrayIps;
    }
}