wxr
2021-07-01 43b0d5870d528f23ecd6aeceb6cfd4325188b46f
HDL_ON/DAL/DriverLayer/UdpSocket.cs
@@ -1,9 +1,8 @@
using System;
using System.Net.Sockets;
using System.Net;
using Newtonsoft.Json.Linq;
namespace HDL_ON
namespace HDL_ON.DriverLayer
{
   public class UdpSocket
   {
@@ -22,20 +21,32 @@
      //本地Socket
      private Socket busSocket;
      public int Port = 0;
      /// <summary>
      /// 启动Socket接收和发送功能
      /// </summary>
      public void Start ()
      public void Start (int port = 0)
        {
            if (IsRunning ) {
                return;
         if (IsRunning)
         {
                if (port == Port)
                {
                    return;
                }
                else
                {
                    busSocket.Close();
                }
            }
         if (port != 0)
            Port = port;
         if (Port == 0)
            return;
            busSocket = new Socket (AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            busSocket.EnableBroadcast = true;
            try {
                busSocket.Bind (new IPEndPoint (IPAddress.Any, 6000));
            busSocket.Bind(new IPEndPoint(IPAddress.Any, Port));
            busSocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(IPAddress.Parse("239.0.168.188")));
         }
@@ -46,7 +57,7 @@
            asyncBeginReceive();
            MainPage.Log ($"udp port : 6000");
            MainPage.Log ($"udp port : {port}");
        }
      /// <summary>
@@ -120,10 +131,11 @@
            packet.Bytes = new byte[len];
            Array.Copy(bytes, 0, packet.Bytes, 0, packet.Bytes.Length);
            //MainPage.Log($"接收{packet.RemoteEndPoint}数据");
            //mqtt连接数据读取  A协议网络设备信息读取回复 处理
            if (((IPEndPoint)packet.RemoteEndPoint).Port == 8585)
            {
               Common.A_Protocal_Common.apc.ConvertReceiveData(bytes);
               Control.Ins.ConvertReceiveData(bytes);
            }
            else if(((IPEndPoint)packet.RemoteEndPoint).Port == 6000)//处理bus 6000端口的数据
            {