//private IPEndPoint localIpep = new IPEndPoint(IPAddress.Parse(localIpAddress), 10101);


        //public SensorChannelConfigForm(SerialPort paramPortDev)
        public SensorChannelConfigForm(DevExpress.XtraBars.Ribbon.RibbonForm form)
        {
            InitializeComponent();
            //mSerialPort = paramPortDev;
            //mSerialPort.ReceivedBytesThreshold = 1;
            this._form = form;

            //初始化配置值
            //获取静态配置类中的配置值
            List <string> configList = SensorChannelConfigValue.getSensorChannelConfigList();

            if (null == configList || configList.Count != 30)
            {
            }
            else
            {
                //1-30循环显示在相应输入框
                for (int i = 1; i <= 30; i++)
                {
                    string  configVal = configList[i - 1];
                    Control control   = Controls.Find("numericUpDown" + Convert.ToString(i), true)[0];
                    control.GetType().GetProperty("Text").SetValue(control, configVal, null);
                    //String value = control.GetType().GetProperty("Text").GetValue(control, null).ToString();
                }
            }
        }
        /// <summary>
        /// 监听传感器通道配置值变化
        /// </summary>
        /// <param name="lastUpdateTime"></param>
        public void listenSensorChannelConfigValue(Object lastUpdateTime)
        {
            int index = 0;

            while (true)
            {
                //超时
                if (index >= 10)
                {
                    XtraMessageBox.Show("读取超时,请稍后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                }
                //未配置
                if (SensorChannelConfigValue.updateTime < Convert.ToInt64(lastUpdateTime))
                {
                    XtraMessageBox.Show("传感器通道未配置!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                }
                //读取配置成功
                if (SensorChannelConfigValue.updateTime > Convert.ToInt64(lastUpdateTime))
                {
                    Action action = () =>
                    {
                        //获取静态配置类中的配置值
                        List <string> configList = SensorChannelConfigValue.getSensorChannelConfigList();
                        if (null == configList || configList.Count != 30)
                        {
                            XtraMessageBox.Show("读取失败,请完成配置再读取哦!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        //1-30循环显示在相应输入框
                        for (int i = 1; i <= 30; i++)
                        {
                            string  configVal = configList[i - 1];
                            Control control   = Controls.Find("numericUpDown" + Convert.ToString(i), true)[0];
                            control.GetType().GetProperty("Text").SetValue(control, configVal, null);
                            //String value = control.GetType().GetProperty("Text").GetValue(control, null).ToString();
                        }
                    };
                    Invoke(action);

                    XtraMessageBox.Show("读取成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                }
                index++;
                Thread.Sleep(1000);
            }
        }
        /// <summary>
        /// 读取传感器通道配置值,并显示在相应输入框中【已废弃】
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click_used(object sender, EventArgs e)
        {
            //获取静态配置类中的配置值
            List <string> configList = SensorChannelConfigValue.getSensorChannelConfigList();

            if (null == configList || configList.Count != 30)
            {
                XtraMessageBox.Show("读取失败,请完成配置再读取哦!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //1-30循环显示在相应输入框
            for (int i = 1; i <= 30; i++)
            {
                string  configVal = configList[i - 1];
                Control control   = Controls.Find("numericUpDown" + Convert.ToString(i), true)[0];
                control.GetType().GetProperty("Text").SetValue(control, configVal, null);
                //String value = control.GetType().GetProperty("Text").GetValue(control, null).ToString();
            }
            XtraMessageBox.Show("读取成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        /// <summary>
        /// 保存配置,并发送
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            List <string> channelConfigValues = new List <string>();  //存放通道配置值

            int isVerified = 0;

            try
            {
                //检查通道配置合理性
                for (int i = 1; i <= 30; i++)
                {
                    Control control = Controls.Find("numericUpDown" + Convert.ToString(i), true)[0];
                    String  value   = control.GetType().GetProperty("Text").GetValue(control, null).ToString();
                    if (!string.IsNullOrWhiteSpace(value) && value != "0")  //&& value != "0"
                    {
                        channelConfigValues.Add(value);
                    }
                    else
                    {
                        break;
                    }
                    isVerified = i;
                }

                //判断是否完成所有传感器通道的配置合理性检查
                if (isVerified == 30)
                {
                    //判断是否有更改,是:弹框提示;否:继续执行
                    if (!Enumerable.SequenceEqual(channelConfigValues, SensorChannelConfigValue.configList))
                    {
                        //if (channelConfigValues.Equals(SensorChannelConfigValue.configList)) {
                        if (XtraMessageBox.Show("该配置表已更改,是否重新下发配置信息?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == System.Windows.Forms.DialogResult.Cancel)
                        {
                            this.Close();
                            return;
                        }
                        else
                        {
                        }
                    }
                    //else {
                    //初始化传感器通道配置信息类
                    SensorChannelConfigValue.setChannelConfigValue(channelConfigValues);

                    //生成配置信息 byte数组 对应的 16进制字符串数组
                    string sendCmdStr = SensorChannelConfigValue.getSendCmd();

                    //将上述16进制字符串数组 拼接为 0x_ _ 格式 的字符串

                    /*string sendCmdStr = "";
                     * for (int i = 0; i < sendCmd.Length; i++) {
                     *  sendCmdStr+="0x"+sendCmd[i]+" ";
                     * }
                     * */

                    //下发通道配置信息
                    //1、关闭线程
                    //MainForm.thrRecv.Abort();    //所谓的关闭线程
                    //MainForm.thrRecv.Join();    //挂起
                    //2、关闭udpcRecv
                    //MainForm.udpcRecv.Close();
                    //MainForm.udpcRecv = null;
                    //3、创建udpcSend

                    //4、创建thrSend
                    MainForm.thrSend = new Thread(MainForm.SendMessage);

                    //5、开启thrSend(thrSend执行结束后自动关闭udpcSend,销毁thrSend)
                    MainForm.thrSend.Start(sendCmdStr);

                    //6、在主界面显示发送内容
                    Action action = () =>
                    {
                        MainForm.showMessage(MainForm.richTextBox1, string.Format("{0}{1}", "上位机(" + MainForm.localIpep + ")[传感器通道配置信息下发]_" + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", System.Globalization.DateTimeFormatInfo.InvariantInfo) + ":", sendCmdStr));
                    };
                    action.Invoke();



                    XtraMessageBox.Show("指令已下发!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    MainForm.isCollecting = true;
                    //this.Close();
                    // }
                }
                else
                {
                    XtraMessageBox.Show("存在未配置通道,请检查更改!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception exception) {
                XtraMessageBox.Show(exception.Message, "配置异常", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }