/// <summary>
        /// 设置设备配置参数
        /// </summary>
        /// <param name="strMAC">mac地址</param>
        /// <param name="pConvSetting">配置参数结构体</param>
        /// <param name="timeout">等待超时时间,单位毫秒。</param>
        /// <param name="bindIp">指定固定的绑定IP发送数据</param>
        /// <returns>true:成功;false:失败。备注:如果在超时时间内收到设备回复,则会立即返回结果</returns>
        public static bool SetConvCommSetting(string strMAC, NetDeviceSetting pConvSetting, int timeout, string bindIp = "", int CommPort = 1)
        {
            Console.WriteLine("MAC:" + strMAC + " 开始设置串口配置参数【" + CommPort + "】 " + pConvSetting.SockSetting[CommPort - 1].srcPacket.Length);

            byte[] data = null;

            _currentMac = strMAC;

            _setConvCommSettingResult = false;

            data = GetCommConvData(strMAC, pConvSetting, CommPort);

            if (data != null)
            {
                //data为数据体,现在要加22个字节的包头和检验
                byte[] sendbuff = new byte[data.Length + 22];

                sendbuff[0] = 0xFF;

                sendbuff[1] = (byte)(sendbuff.Length - 3);

                sendbuff[2] = (byte)(0x05 + CommPort);
                if (CommPort == 4)
                {
                    sendbuff[2] = 0x0F;
                }

                Util.ConvertMacToByte(strMAC, sendbuff, 3);                         //3,4,5,6,7,8---MAC---

                Buffer.BlockCopy(Util.User, 0, sendbuff, 9, Util.User.Length);      //9,10,11,12,13,14---用户名---

                Buffer.BlockCopy(Util.PassWord, 0, sendbuff, 15, Util.User.Length); //15,16,17,18,19,20---密码---

                Buffer.BlockCopy(data, 0, sendbuff, 21, data.Length);

                sendbuff[sendbuff.Length - 1] = Util.NetNetModelLjl(sendbuff);

                _udpHandler.Send(sendbuff, 1);

                _resetEvent.WaitOne(timeout);//信号量等待

                _resetEvent.Reset();
            }

            if (_setConvCommSettingResult)
            {//设置成功后,再保存一下串口的参数
                _udpHandler.Send(Util.GetDataByType("04", strMAC), 1);

                _resetEvent.WaitOne(300);//信号量等待

                _resetEvent.Reset();
            }
            _currentMac = "";

            return(_setConvCommSettingResult);
        }
        /// <summary>
        /// 串口参数下发生成
        /// </summary>
        /// <param name="strMAC"></param>
        /// <param name="pConvSetting"></param>
        /// <param name="PortComm"></param>
        /// <returns></returns>
        private static byte[] GetCommConvData(string strMAC, NetDeviceSetting pConvSetting, int PortComm)
        {
            if (pConvSetting.SockSetting == null || PortComm > pConvSetting.SockSetting.Length || pConvSetting.ComSetting == null || PortComm > pConvSetting.ComSetting.Length)
            {
                return(null);
            }

            PortComm -= 1;

            byte[] data = new byte[pConvSetting.SockSetting[PortComm].srcPacket.Length];

            int i;

            Buffer.BlockCopy(pConvSetting.SockSetting[PortComm].srcPacket, 0, data, 0, data.Length);//先把存储的设置信息读出来

            if (data.Length == 63)
            {
                SocketSetting socketSet = pConvSetting.SockSetting[PortComm];
                ComSetting    comSet    = pConvSetting.ComSetting[PortComm];
                //需要修改的内容有:串口波特率,停止位,校验位,起如位,串口流控制
                Util.ConvertIntToByte(comSet.Baudrate, data, 0);                 //0,1,2,3,串口波特率
                data[4] = (byte)comSet.Databit;                                  //数据位
                data[5] = (byte)comSet.CheckMode;                                //校验位
                data[6] = (byte)comSet.StopBit;                                  //停止位
                data[7] = (byte)comSet.FlowMode;                                 //串口控制流
                Util.ConvertInt16ToByte((ushort)socketSet.Port, data, 12);       //本地端口
                Util.ConvertInt16ToByte((ushort)socketSet.ServerPort, data, 14); //服务器端口
                for (i = 16; i < 46; i++)
                {
                    data[i] = 0;
                }
                Util.ConvertIpToAscllByte(socketSet.IpServer, data, 16); //ip地址
                data[51] = (byte)socketSet.Mode;                         //通讯模式
                Util.ConvertIntToByte(comSet.MinSendByte, data, 52);     //串口打包长度
                data[56] = (byte)comSet.MinSendTime;                     //串口打包时间
            }
            else
            {
                data = null;
            }

            return(data);
        }
        /// <summary>
        /// 获取设备配置参数
        /// </summary>
        /// <param name="strMAC">mac地址</param>
        /// <param name="pConvSetting">配置参数结构体</param>
        /// <param name="timeout">等待超时时间,单位毫秒。</param>
        /// <param name="bindIp">指定固定的绑定IP发送数据</param>
        /// <param name="stationfind">搜索分站为1,搜索交换机为0</param>
        /// <returns>true:成功;false:失败。备注:如果在超时时间内收到设备回复,则会立即返回结果 </returns>
        public static bool GetConvSetting(string strMAC, out NetDeviceSetting pConvSetting, int timeout, string bindIp = "", string stationfind = "0")
        {
            Console.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss ffff") + "  MAC:" + strMAC + " 获取交换机的基础信息 03");

            _getConvSettingResult = false;

            _setting = new NetDeviceSetting();

            if (stationfind == "0")
            {
                _udpHandler.Send(Util.GetDataByType("11", strMAC), 1);
            }

            _resetEvent.WaitOne(timeout);//信号量等待

            pConvSetting = _setting;

            _resetEvent.Reset();

            return(_getConvSettingResult);
        }
        /// <summary>
        /// 设置设备配置参数
        /// </summary>
        /// <param name="strMAC">mac地址</param>
        /// <param name="pConvSetting">配置参数结构体</param>
        /// <param name="timeout">等待超时时间,单位毫秒。</param>
        /// <param name="bindIp">指定固定的绑定IP发送数据</param>
        /// <param name="stationfind">搜索分站为1,搜索交换机为0</param>
        /// <returns>true:成功;false:失败。备注:如果在超时时间内收到设备回复,则会立即返回结果</returns>
        public static bool SetConvSetting(string strMAC, NetDeviceSetting pConvSetting, int timeout, string bindIp = "", string stationfind = "0")
        {
            Console.WriteLine("MAC:" + strMAC + " 开始设置网络设备基础配置参数 05");
            byte[] data = null;
            ushort ljl  = 0;

            _resetEvent = new ManualResetEvent(false);

            _currentMac = strMAC;

            _setConvSettingResult = false;

            if (stationfind == "1")//表示设置的是分站的IP信息
            {
                data    = new byte[37];
                data[0] = 0x3E;
                data[1] = 0xE3;
                data[2] = 0x80;
                data[3] = 0x08;
                data[4] = 0;
                data[5] = 0x4D;
                data[6] = 27;
                data[7] = 0x00;
                Util.ConvertMacToByte(strMAC, data, 8);                            //8,9,10,11,12,13
                Util.ConvertIPToByte(pConvSetting.NetSetting.IpAddr, data, 14);    //IP ---77m78 79 80
                Util.ConvertIPToByte(pConvSetting.NetSetting.SubMask, data, 22);   //子网掩码 ---81 82 83 84
                Util.ConvertIPToByte(pConvSetting.NetSetting.GatewayIp, data, 18); //网关 ---85 86 87 88
                data[26] = pConvSetting.NetSetting.SetFzh;

                for (int i = 4; i <= 26; i++)
                {
                    ljl += data[i];
                }
                data[35] = Convert.ToByte(ljl & 0xFF);
                data[36] = Convert.ToByte((ljl >> 8) & 0xFF);
            }
            else if (stationfind == "0")//表示设置的是交换机的IP信息
            {
                data    = new byte[208];
                data[0] = 0x7F;
                data[1] = 0x10;
                data[2] = 0x05;
                data[3] = 0x00;
                data[4] = 0xD0;
                data[5] = 0x11;
                data[6] = 0x06;
                Util.ConvertMacToByte(strMAC, data, 71);                           //3,4,5,6,7,8---MAC---71 72 73 74 75 76
                Util.ConvertIPToByte(pConvSetting.NetSetting.IpAddr, data, 77);    //IP ---77m78 79 80
                Util.ConvertIPToByte(pConvSetting.NetSetting.SubMask, data, 81);   //子网掩码 ---81 82 83 84
                Util.ConvertIPToByte(pConvSetting.NetSetting.GatewayIp, data, 85); //网关 ---85 86 87 88
                data[207] = 0x0D;
                ljl       = CRC_16(data, data.Length);
                data[205] = Convert.ToByte(ljl >> 8);
                data[206] = Convert.ToByte(ljl & 0xFF);
            }

            if (data != null)
            {
                _udpHandler.Send(data, 1);

                _resetEvent.WaitOne(timeout);//信号量等待

                _resetEvent.Reset();
            }

            return(_setConvSettingResult);
        }