mac
2023-11-06 54c202bd4867092fca2bc6f96bec0cfd1056a46a
HDL_ON/DAL/DriverLayer/UdpSocket.cs
@@ -29,14 +29,14 @@
        {
         if (IsRunning)
         {
                if (port == Port)
            if (port == Port)
                {
                    return;
                }
            }
                else
                {
                    busSocket.Close();
                }
            }
            }
         if (port != 0)
            Port = port;
@@ -49,9 +49,12 @@
            busSocket.Bind(new IPEndPoint(IPAddress.Any, Port));
            busSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("239.0.168.188")));
            relinkCount = 0;
         }
         catch{
                busSocket = null;
         catch (Exception ex){
            MainPage.Log ($"udp port bind error : {ex.Message}");
            busSocket = null;
                return;
            }
@@ -65,6 +68,10 @@
      /// </summary>
      public void Stop()
      {
         if(busSocket == null)
            {
            return;
            }
         if (!IsRunning)
         {
            return;
@@ -72,10 +79,11 @@
         try
         {
            busSocket.Close();
            relinkCount = 0;
         }
         catch { }
         busSocket = null;
            MainPage.Log("Socket关闭");
         MainPage.Log("Socket关闭");
      }
      /// <summary>
@@ -98,6 +106,10 @@
         {
            return;
         }
         if(busSocket == null)
            {
            return;
            }
            try {
                Packet packet = new Packet ();
@@ -105,10 +117,21 @@
            } 
            catch (Exception e) {
                System.Threading.Thread.Sleep (1);
                asyncBeginReceive ();
                Console.WriteLine("asyncBeginReceive " + relinkCount   );
            if (relinkCount == 0)
            {
               relinkCount = 1;
               asyncBeginReceive();
            }
                Console.WriteLine($"asyncBeginReceive {e.Message}");
            } 
      }
      /// <summary>
        /// 重连次数
        /// </summary>
      private int relinkCount = 0;
      /// <summary>
      /// 异步接收数据结束
@@ -120,9 +143,12 @@
         {
            return;
         }
         try
         {
            if (busSocket == null)
            {
               return;
            }
            asyncBeginReceive();
            Packet packet = (Packet)iar.AsyncState;
            int len = busSocket.EndReceiveFrom(iar, ref packet.RemoteEndPoint);
@@ -137,10 +163,11 @@
            {
               Control.Ins.ConvertReceiveData(bytes, ((IPEndPoint)packet.RemoteEndPoint).Address.ToString());
            }
            else if(((IPEndPoint)packet.RemoteEndPoint).Port == 6000)//处理bus 6000端口的数据
            else if (((IPEndPoint)packet.RemoteEndPoint).Port == 6000)//处理bus 6000端口的数据
            {
               packet.Manager();
            }
         }
         catch (Exception ex)
         {