wxr
2020-11-23 d4160d80c79245c1d7d0cd450ba48cb7850e411d
HDL_ON/DAL/DriverLayer/Control.cs
File was renamed from HDL_ON/DriverLayer/Control.cs
@@ -15,10 +15,6 @@
        /// </summary>
        local_BusUdp,
        /// <summary>
        /// 本地tcp服务端
        /// </summary>
        tcp_local_server,
        /// <summary>
        /// 本地tcp客户端
        /// </summary>
        tcp_local_client,
@@ -40,6 +36,10 @@
                return _control;
            }
        }
        /// <summary>
        /// 网关是否在线
        /// </summary>
        public bool gatewayOnline = false;
        /// <summary>
        /// 通讯地址IP
        /// </summary>
@@ -63,10 +63,24 @@
        public CommunicationMode communicationMode;
        /// <summary>
        /// 打开tcp服务端
        /// </summary>
        public void OpenTcpServer()
        {
            myTcpServer = new Control_TcpServer();
            myTcpServer.OpenServer();
        }
        /// <summary>
        /// 改变通讯方式
        /// </summary>
        public void ChangeCommunicationMode(CommunicationMode communicationMode)
        {
            if (this.communicationMode == communicationMode)
            {
                return;
            }
            this.communicationMode = communicationMode;
@@ -78,32 +92,10 @@
                        myUdp = new Control_Udp_Bus();
                    }
                    UdpSocket._BusSocket.Start();
                    if (myTcpServer != null)
                    {
                        myTcpClient.Close();
                        myTcpClient = null;
                    }
                    if (myTcpClient != null)
                    {
                        myTcpClient.Close();
                        myTcpClient = null;
                    }
                    break;
                case CommunicationMode.tcp_local_server:
                    if (myTcpServer == null)
                    {
                        myTcpServer = new Control_TcpServer();
                        myTcpServer.OpenServer();
                    }
                    if (myTcpClient != null)
                    {
                        myTcpClient.Close();
                        myTcpClient = null;
                    }
                    if(myUdp != null)
                    {
                        UdpSocket._BusSocket.Stop();
                        myUdp = null;
                    }
                    break;
                case CommunicationMode.tcp_local_client:
@@ -112,11 +104,6 @@
                        myTcpClient = new Control_TcpClient(reportIp);
                        myTcpClient.Connect();
                    }
                    if (myTcpServer != null)
                    {
                        myTcpClient.Close();
                        myTcpClient = null;
                    }
                    if (myUdp != null)
                    {
                        UdpSocket._BusSocket.Stop();
@@ -127,6 +114,26 @@
        }
        /// <summary>
        /// 搜索本地网关列表
        /// </summary>
        public void SearchLoaclGateway()
        {
            ChangeCommunicationMode(CommunicationMode.local_BusUdp);
            if (DB_ResidenceData.residenceData.GatewayType == 0)
            {
                myUdp.ControlBytesSend(Command.ReadGateway, 255, 255, new byte[] { (byte)new Random().Next(255), (byte)new Random().Next(255) });
            }
            else if (DB_ResidenceData.residenceData.GatewayType == 1)
            {
                UdpSocket._BusSocket.SearchNetDeviceAction = (revIp) =>
                {
                    MainPage.Log($"搜索到网络设备:{revIp}");
                };
                myUdp.SearchLocalGateway();
            }
        }
        /// <summary>
        /// 场景控制入口
        /// </summary>
        public void ControlScene(Scene scene)