wei
2021-10-28 270b3d8539f6b4a991a9ebf3b3a9eceb436d61d5
HDL_ON/DAL/DriverLayer/Control_Udp.cs
@@ -978,7 +978,7 @@
                        UdpSocket._BusSocket.AsyncBeginSend(packet);
                        controlLostCount++;
                    }
                    System.Threading.Thread.Sleep(300);
                    System.Threading.Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
@@ -1078,7 +1078,7 @@
        /// <summary>
        /// 读取网关IP
        /// </summary>
        public void SearchLocalGateway()
        public void SearchLocalGateway(bool broadcast = false)
        {
            try
            {
@@ -1086,23 +1086,21 @@
                var bodyString = JsonConvert.SerializeObject(sendJob);
                
                var sendBytes = Control.Ins.ConvertSendBodyData(CommunicationTopic.SearchLoaclGateway, bodyString, false);
                //组播发送
                packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("239.0.168.188"), 8585));
                if (broadcast)
                {
                    //广播
                    packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("255.255.255.255"), 8585));
                }
                else
                {
                    //组播发送
                    packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("239.0.168.188"), 8585));
                }
                packet.HaveSendCount = 4;
                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount));
                thread.IsBackground = true;
                thread.Start(packet);
                //wait();不需要等待
                //hjSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                //hjSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
                //EndPoint ipep = new IPEndPoint(IPAddress.Parse(CsConst.myLocalIP), HDLUDP.UDPPort);
                //hjSocket.Bind(ipep);
            }
            catch (Exception ex)
@@ -1111,6 +1109,26 @@
            }
        }
        /// <summary>
        /// 读取网关IP
        /// </summary>
        public void SendLinkCommand(string topic,string bodyString)
        {
            try
            {
                var sendBytes = Control.Ins.ConvertSendBodyData(topic, bodyString, false);
                //组播发送
                packet = new Packet(sendBytes, new System.Net.IPEndPoint(System.Net.IPAddress.Parse("239.0.168.188"), 8585));
                packet.HaveSendCount = 4;
                System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(managerSendCount));
                thread.IsBackground = true;
                thread.Start(packet);
            }
            catch (Exception ex)
            {
                MainPage.Log($"Send bus data error {ex.Message}");
            }
        }
        /// <summary>
        /// 发送udp A协议数据