| | |
| | | |
| | | namespace HDL_ON.DriverLayer |
| | | { |
| | | |
| | | /// <summary> |
| | | /// 通讯方式 |
| | | /// </summary> |
| | | public enum CommunicationMode |
| | | { |
| | | none, |
| | | /// <summary> |
| | | /// 本地udp |
| | | /// </summary> |
| | |
| | | tcp_local_client, |
| | | } |
| | | |
| | | |
| | | |
| | | public class Control |
| | | { |
| | | static Control _control; |
| | | public static Control ins |
| | | public static Control Ins |
| | | { |
| | | get |
| | | { |
| | |
| | | return _control; |
| | | } |
| | | } |
| | | bool _gatewayOnline = false; |
| | | /// <summary> |
| | | /// 网关是否在线 |
| | | /// </summary> |
| | | public bool gatewayOnline = false; |
| | | public bool GatewayOnline { |
| | | get |
| | | { |
| | | return _gatewayOnline; |
| | | } |
| | | set |
| | | { |
| | | _gatewayOnline = value; |
| | | //修改主页连接状态 |
| | | UI.HomePage.LoadEvent_CheckLinkStatus(); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 是否为远程连接 |
| | | /// </summary> |
| | | public bool IsRemote = false; |
| | | /// <summary> |
| | | /// 通讯地址IP |
| | | /// </summary> |
| | |
| | | /// <summary> |
| | | /// 本地udp |
| | | /// </summary> |
| | | public Control_Udp_Bus myUdp = null; |
| | | public Control_Udp myUdp = null; |
| | | |
| | | /// <summary> |
| | | /// 通讯方式 |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 改变通讯方式 |
| | | /// 打开Udp |
| | | /// </summary> |
| | | public void ChangeCommunicationMode(CommunicationMode communicationMode) |
| | | public void OpenUdp() |
| | | { |
| | | if (this.communicationMode == communicationMode) |
| | | if (myUdp == null) |
| | | { |
| | | return; |
| | | myUdp = new Control_Udp(); |
| | | } |
| | | |
| | | this.communicationMode = communicationMode; |
| | | |
| | | |
| | | switch (this.communicationMode) |
| | | UdpSocket._BusSocket.Start(); |
| | | } |
| | | /// <summary> |
| | | /// 打开tcp客服端 |
| | | /// </summary> |
| | | public void OpenTcpClent() |
| | | { |
| | | if (myTcpClient == null) |
| | | { |
| | | case CommunicationMode.local_BusUdp: |
| | | if (myUdp == null) |
| | | { |
| | | myUdp = new Control_Udp_Bus(); |
| | | } |
| | | UdpSocket._BusSocket.Start(); |
| | | if (myTcpClient != null) |
| | | { |
| | | myTcpClient.Close(); |
| | | myTcpClient = null; |
| | | } |
| | | break; |
| | | case CommunicationMode.tcp_local_client: |
| | | if (myTcpClient == null) |
| | | { |
| | | myTcpClient = new Control_TcpClient(reportIp); |
| | | myTcpClient.Connect(); |
| | | } |
| | | if (myUdp != null) |
| | | { |
| | | UdpSocket._BusSocket.Stop(); |
| | | myUdp = null; |
| | | } |
| | | break; |
| | | myTcpClient = new Control_TcpClient(reportIp); |
| | | myTcpClient.Connect(); |
| | | } |
| | | } |
| | | |
| | | ///// <summary> |
| | | ///// 改变通讯方式 |
| | | ///// </summary> |
| | | //public void ChangeCommunicationMode(CommunicationMode communicationMode) |
| | | //{ |
| | | // this.communicationMode = communicationMode; |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// 搜索本地网关列表 |
| | | /// </summary> |
| | | public void SearchLoaclGateway() |
| | | { |
| | | ChangeCommunicationMode(CommunicationMode.local_BusUdp); |
| | | OpenUdp(); |
| | | 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(); |
| | | } |
| | | } |