wxr
2020-01-10 1a4b95a7ebef71838bd3eda2c22056bbf0db65ec
HDL_ON/DriverLayer/Control_Bus.cs
File was renamed from HDL_ON/HDL/Operation/Control.cs
@@ -1,39 +1,28 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HDL_ON.DAL;
using HDL_ON.DAL.Net;
using HDL_ON.UI;
using HDL_ON.Entity.Enumerative;
namespace HDL_ON
{
    public class Control
    public partial class Control
    {
        public bool IsCanShowTip;
        public System.DateTime LatestDateTime = System.DateTime.Now;
        /// <summary>
        /// 所有微信对一端口的控制都会放到这个集合里
        /// </summary>
        private static System.Collections.Generic.List<Control> controlList = new List<Control>(50);
        private static List<Control> controlList = new List<Control>(50);
        /// <summary>
        /// 发送数据,等待有反馈
        /// </summary>
        /// <returns>The bytes send has return.</returns>
        public static byte[] ControlBytesSendHasReturn(Command command, byte subnetID, byte deviceID, byte[] gatewayBytes, bool isShow = true)
        static byte[] ControlBytesSendHasReturn(Command command, byte subnetID, byte deviceID, byte[] gatewayBytes, int sendCount = 3)
        {
            if (command == Command.ReadDeviceLoopInfo || command == Command.ReadDeviceModul)
                CommonPage.LocalPhoneFindDevice = true;
            if (command == Command.ReadGateway || command == Command.ReadGatewayProgrammingMode || command == Command.SetGateway)
            {
                CommonPage.FindGateway = true;
                CommonPage.LocalPhoneFindDevice = true;
            }
            Control control = new Control() { IsCanShowTip = isShow };
            Control control = new Control();
            control.Send(new Target()
            {
                IPEndPoint = CommonPage.EndPoint,
@@ -41,31 +30,21 @@
                SubnetID = subnetID,
                DeviceID = deviceID,
                AddData = gatewayBytes,
            }, SendCount.Three, true);
            }, sendCount, true);
            CommonPage.FindGateway = false;
            return control.UsefulBytes;
        }
        /// <summary>
        /// 发送数据,不需要等待回复
        /// </summary>
        public static void ControlBytesSend(Command command, byte subnetID, byte deviceID, byte[] gatewayBytes, SendCount sendCount = SendCount.Three, System.Net.IPEndPoint ipEndpoint = null, bool isShowTip = true)
        static void ControlBytesSend(Command command, byte subnetID, byte deviceID, byte[] gatewayBytes, int sendCount = 3, System.Net.IPEndPoint ipEndpoint = null)
        {
            if (command == Command.ReadDeviceLoopInfo || command == Command.ReadDeviceModul)
                CommonPage.LocalPhoneFindDevice = true;
            if (command == Command.ReadGateway || command == Command.ReadGatewayProgrammingMode
                || command == Command.SetGateway)
            {
                CommonPage.FindGateway = true;
                CommonPage.LocalPhoneFindDevice = true;
            }
            Control control = new Control() { IsCanShowTip = isShowTip };
            Control control = new Control();
            control.Send(new Target()
            {
                IPEndPoint = ipEndpoint == null ? CommonPage.EndPoint : ipEndpoint,//new System.Net.IPEndPoint (System.Net.IPAddress.Parse (new Net.NetWiFi ().BroadcastIpAddress.ToString ()), 6000),
                IPEndPoint = ipEndpoint == null ? CommonPage.EndPoint : ipEndpoint,
                Command = command,
                SubnetID = subnetID,
                DeviceID = deviceID,
@@ -457,7 +436,6 @@
                        }
                        System.Threading.Thread.Sleep(100);
                    }
                }
                catch (Exception ex)
                {
@@ -466,10 +444,6 @@
                finally
                {
                    allDone.Set();
                    if (Packet.HaveSendCount == 3 && IsCanShowTip)
                    {
                        //MainPage.AddTip (Language.StringByID (SimpleControl.R.MyInternationalizationString.OperationFailed));
                    }
                }
            }
        }
@@ -685,10 +659,10 @@
        /// </summary>
        /// <param name="target">发送对象</param>
        /// <param name="sendCount">重发次数</param>
        public void Send(Target target, SendCount sendCount, bool isWait)
        public void Send(Target target, int sendCount, bool isWait)
        {
            Packet = new Packet(target.SendBytes, target.IPEndPoint);
            Packet.HaveSendCount = 3 - (int)sendCount;
            Packet.HaveSendCount = 3 - sendCount;
            ini(target);
@@ -697,5 +671,6 @@
                this.wait();
            }
        }
    }
}
}