Newer
Older
RbFreqStand / RbFreqStandMeasure / tools / DetectionHelper.cs
yangqianqian on 30 Apr 2021 34 KB 4.30
using Casic.Birmm.RbFreqStandMeasure.info;
using Casic.Birmm.RbFreqStandMeasure.Properties;
using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Model;
using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service;
using Casic.Birmm.RbFreqStandMeasure.R_DataBase.Service.Impl;
using Casic.Birmm.RbFreqStandMeasure.Tools;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO.Ports;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace Casic.Birmm.RbFreqStandMeasure.tools
{
    public class DetectionHelper
    {
        private readonly object obj = new object();
        private bool isUsing = false;
        public static DetectionHelper detectionHelper;
        public List<Detection> detections;
        private bool isUpdate = false;

        public long detectionId = -1;

        private  System.Threading.Timer timerAccuracy;
        delegate void TimerDelegate(string text);
        private  long devIdAccuracy = -1;
        private  SerialPort portAccuracy;

        private System.Threading.Timer timerStability1;
        private System.Threading.Timer timerStability10;
        private System.Threading.Timer timerStability20;
        private System.Threading.Timer timerStability100;
        private  long devIdStability = -1;
        private  SerialPort portStability;
        private  List<string> resultStability1 = new List<string>();
        private List<string> resultStability10 = new List<string>();
        private List<string> resultStability20 = new List<string>();
        private List<string> resultStability100 = new List<string>();

        private  System.Threading.Timer timerBootFeature;
        private  long devIdBootFeature = -1;
        private  SerialPort portBootFeature;
        private  List<string> resultBootFeature = new List<string>();

        private  System.Threading.Timer timerAgeRate;
        private  long devIdAgeRate = -1;
        private  SerialPort portAgeRate;
        private  List<string> resultAgeRate = new List<string>();

        private  DetectionService detectionService = new DetectionServiceImpl();
        private  DetectionItemService detectionItemService = new DetectionItemServiceImpl();
        private  DeviceService deviceService = new DeviceServiceImpl();

        //1-STABILITY,2-ACCURACY,3-BOOT_FEATURE,4-AGE_RATE


        public DetectionHelper()
        {
            detectionHelper = this;
        }


        #region 稳定度
        public void detecStability(long deviceId, string startTime, string interval, SerialPort port, bool isStartNow, bool isUpdates)
        {
            resultStability1 = new List<string>();
            resultStability10 = new List<string>();
            resultStability20 = new List<string>();
            resultStability100 = new List<string>();
            if (isUpdates)
            {
                isUpdate = true;
            }
            portStability = port;
            devIdStability = deviceId;
            int delay = 0;
            if (!isStartNow && Convert.ToDateTime(startTime) > DateTime.Now)
            {
                TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks);
                delay = secondSpan.Milliseconds;
            }
            string[] arr = interval.Split(',');
            LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "interval==========="+ interval);

            foreach (string inter in arr)
            {
                if (inter.Equals("1")) timerStability1 = new System.Threading.Timer(exeStability1, null, delay + 100, 1000);
                if (inter.Equals("10")) timerStability10 = new System.Threading.Timer(exeStability10, null, delay + 100, 10 * 1000);
                if (inter.Equals("20")) timerStability20 = new System.Threading.Timer(exeStability20, null, delay + 100, 20 * 1000);
                if (inter.Equals("100")) timerStability100 = new System.Threading.Timer(exeStability100, null, delay + 100, 100 * 1000);
            }
        }
        private void exeStability1(Object State)
        {
            try
            {
                while (true)
                {
                    lock (obj)
                    {
                        lock(resultStability1)
                        {
                            if (!isUsing)
                            {
                                isUsing = true;
                                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开始检测稳定度1s");

                                string result = "";

                                string fre = getFrequencyData(portStability);
                                if (fre.Equals(""))
                                {
                                    LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "从" + portStability.PortName + "获取稳定度1s数据失败,!");
                                }
                                resultStability1.Add(fre);
                                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "稳定度1s fre=" + fre);
                                if (!isUpdate)
                                {
                                    detectionService.add(devIdStability, fre, "1-1");
                                    if (resultStability1.Count == 101)
                                    {
                                        timerStability1.Dispose();                                    

                                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开始计算稳定度结果");

                                        result = FreMath.Stable(resultStability1) + "";
                                        resultStability1.Clear();


                                        // 更新检测结果
                                        detectionItemService.updateDetecStatus(detectionId, "", "", "", "", "", result, "", "", "");
                                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "detectionId      :" + detectionId);

                                        DetectionItem detectionItem = detectionItemService.searchById(detectionId);
                                        if (detectionItem != null)
                                        {                                           
                                            //更新稳定度检测状态
                                            if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1"))
                                            {
                                                detectionItemService.updateDetecStatus(detectionId, "0", "", "", "", "", "", "", "", "");
                                                
                                            }                                           
                                            detectionItem = detectionItemService.searchById(detectionId);
                                            //更新整个仪器检测状态
                                            if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1"))
                                            {
                                                deviceService.updateStatus(devIdStability, "3", "");
                                                portStability.Close();
                                            }
                                            HomeCtrlForm.homeCtrlForm.LoadChannelStatus();
                                        }
                                        
                                    }
                                }
                                else
                                {
                                    if (resultStability1.Count == 101)
                                    {
                                        timerStability1.Dispose();

                                        string result1 = FreMath.Stable(resultStability1) + "";
                                        detectionItemService.updateDetecStatus(detectionId, "", "", "", "", "", result1, "", "", "");

                                        updateView(resultStability1);

                                        resultStability1.Clear();
                                    }
                                }

                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "稳定度检测错误:" + ex.Message);


            }

        }

        private void exeStability10(Object State)
        {
            while (true)
            {
                lock (obj)
                {
                    if (!isUsing)
                    {
                        isUsing = true;
                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开始检测稳定度10s");

                        string result = "";

                        string fre = getFrequencyData(portStability);
                        if (fre.Equals(""))
                        {
                            //MessageBox.Show("从" + portStability.PortName + "获取数据失败!");                          
                            return;
                        }
                        resultStability10.Add(fre);
                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "稳定度10s  fre=" + fre);
                        if (!isUpdate)
                        {
                            detectionService.add(devIdStability, fre, "1-10");

                            if (resultStability10.Count == 101)
                            {

                                timerStability10.Dispose();
                                result = FreMath.Stable(resultStability10) + "";
                                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "10s稳定度检测结果:" + result);

                                detectionItemService.updateDetecStatus(detectionId, "", "", "", "", "", "", result, "", "");


                                DetectionItem detectionItem = detectionItemService.searchById(detectionId);
                                if (detectionItem != null)
                                {
                                    //更新稳定度检测状态
                                    if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1"))
                                    {
                                        detectionItemService.updateDetecStatus(detectionId, "0", "", "", "", "", "", "", "", "");                                        
                                    }

                                    detectionItem = detectionItemService.searchById(detectionId);
                                    //更新整个仪器检测状态
                                    if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1"))
                                    {
                                        deviceService.updateStatus(devIdStability, "3", "");
                                        portStability.Close();
                                    }

                                    HomeCtrlForm.homeCtrlForm.LoadChannelStatus();
                                }
                            }
                        }
                        else
                        {
                            if (resultStability10.Count == 101)
                            {
                                timerStability10.Dispose();
                                

                                string result1 = FreMath.Stable(resultStability10) + "";
                                detectionItemService.updateDetecStatus(detectionId, "", "", "", "", "", "", result1, "", "");

                                updateView(resultStability10);
                            }
                        }
                        break;
                    }
                }
            }


        }


        private void exeStability20(Object State)
        {
            while (true)
            {
                lock (obj)
                {
                    if (!isUsing)
                    {
                        isUsing = true;
                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开始检测稳定度");

                        string result = "";

                        string fre = getFrequencyData(portStability);
                        if (fre.Equals(""))
                        {
                            return;
                        }
                        resultStability20.Add(fre);

                        if (isUpdate)
                        {
                            detectionService.add(devIdStability, fre, "1-20");

                            if (resultStability20.Count == 101)
                            {
                                timerStability20.Dispose();

                                result = FreMath.Stable(resultStability20) + "";
                                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "20s稳定度检测结果:" + result);

                                detectionItemService.updateDetecStatus(detectionId, "", "", "", "", "", "", "", result, "");


                                DetectionItem detectionItem = detectionItemService.searchById(detectionId);
                                if (detectionItem != null)
                                {
                                    //更新稳定度检测状态
                                    if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1"))
                                    {
                                        detectionItemService.updateDetecStatus(detectionId, "0", "", "", "", "", "", "", "", "");
                                        
                                    }
                                    detectionItem = detectionItemService.searchById(detectionId);
                                    //更新整个仪器检测状态
                                    if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1"))
                                    {
                                        deviceService.updateStatus(detectionId, "3", "");
                                        portStability.Close();
                                    }

                                    HomeCtrlForm.homeCtrlForm.LoadChannelStatus();
                                }
                                
                                resultStability20.Clear();
                            }
                            
                        }
                        else
                        {
                            if (resultStability20.Count == 101)
                            {
                                timerStability20.Dispose();


                                string result1 = FreMath.Stable(resultStability20) + "";
                                detectionItemService.updateDetecStatus(devIdStability, "", "", "", "", "", "", "", result1, "");

                                updateView(resultStability20);

                                resultStability20.Clear();

                            }
                        }
                        isUsing = false;
                        break;
                    }
                }
            }

        }


        private void exeStability100(Object State)
        {
            while (true)
            {
                lock (obj)
                {
                    if (!isUsing)
                    {
                        isUsing = true;
                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开始检测稳定度");

                        string result = "";

                        string fre = getFrequencyData(portStability);
                        if (fre.Equals(""))
                        {
                            return;
                        }
                        resultStability100.Add(fre);

                        if (!isUpdate)
                        {
                            detectionService.add(devIdStability, fre, "1-100");

                            if (resultStability100.Count == 101)
                            {

                                timerStability100.Dispose();

                                result = FreMath.Stable(resultStability100) + "";
                                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "100s稳定度检测结果:" + result);

                                detectionItemService.updateDetecStatus(detectionId, "", "", "", "", "", "", "", "", result);


                                DetectionItem detectionItem = detectionItemService.searchById(detectionId);
                                if (detectionItem != null)
                                {
                                    //更新稳定度检测状态
                                    if (!detectionItem.Stability1.Equals("-1") && !detectionItem.Stability10.Equals("-1") && !detectionItem.Stability20.Equals("-1") && !detectionItem.Stability100.Equals("-1"))
                                    {
                                        detectionItemService.updateDetecStatus(detectionId, "0", "", "", "", "", "", "", "", "");
                                        
                                    }
                                    detectionItem = detectionItemService.searchById(detectionId);
                                    //更新整个仪器检测状态
                                    if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1"))
                                    {
                                        deviceService.updateStatus(devIdStability, "3", "");
                                        portStability.Close();
                                    }
                                    HomeCtrlForm.homeCtrlForm.LoadChannelStatus();
                                }
                                resultStability100.Clear();
                            }
                        }
                        else
                        {
                            if (resultStability100.Count == 101)
                            {
                                timerStability100.Dispose();
                                
                                string result1 = FreMath.Stable(resultStability100) + "";
                                detectionItemService.updateDetecStatus(detectionId, "", "", "", "", "", "", "", "", result1);

                                updateView(resultStability100);

                                resultStability100.Clear();
                            }
                        }
                        isUsing = false;
                        break;
                    }
                }
            }

        }
        #endregion




        #region 准确度
        public void detecAccuracy(long deviceId, SerialPort port, string endTime, bool isStartNow, bool isUpdates)
        {
            portAccuracy = port;
            devIdAccuracy = deviceId;
            if (isUpdates)
            {
                isUpdate = true;
            }
            int delay = 0;
            if (Convert.ToDateTime(endTime)>=DateTime.Now)
            {
                TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(endTime).Ticks - DateTime.Now.Ticks);
                delay = secondSpan.Milliseconds;
            }
            timerAccuracy = new System.Threading.Timer(exeAccuracy, null, delay + 200 ,5*60*1000);            
        }
        private void exeAccuracy(Object State)
        {
            try
            {
                while (true)
                {
                    lock (obj)
                    {
                        if (!isUsing)
                        {
                            isUsing = true;
                            string result = "";
                            double sum = 0.0;
                            List<string> resultList = new List<string>();
                            for (int i = 0; i < 50; i++)
                            {
                                string fre = getFrequencyData(portAccuracy);
                                resultList.Add(fre);

                                if (!isUpdate)
                                {
                                    detectionService.add(devIdAccuracy, fre, "2");
                                }
                                if (resultList.Count == 3)
                                {
                                    sum = sum + Convert.ToDouble(fre);
                                    break;
                                }

                                Thread.Sleep(500);
                            }



                            result = sum / 3 + "";
                            timerAccuracy.Dispose();
                            detectionItemService.updateDetecStatus(detectionId, "", result, "", "", "", "", "", "", "");
                            deviceService.updateStatus(devIdAccuracy, "3", "");
                            HomeCtrlForm.homeCtrlForm.LoadChannelStatus();
                            portAccuracy.Close();

                            if (isUpdate) updateView(resultList);
                            isUsing = false;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "计算准确度出错:"+ ex.Message);

            }
        }
        #endregion




        #region 开机特性
        public void detecBootFeature(long deviceId, string startTime, SerialPort port, bool isStartNow)
        {
            resultBootFeature = new List<string>();
            portBootFeature = port;
            devIdBootFeature = deviceId;
            int delay = 0;
            if (!isStartNow && Convert.ToDateTime(startTime) > DateTime.Now)
            {
                TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks);
                delay = secondSpan.Milliseconds;
            }
            timerBootFeature = new System.Threading.Timer(exeBootFeature, null, delay + 100, 60*60*1000);
        }
        private  void exeBootFeature(Object State)
        {
            while (true)
            {
                lock (obj)
                {
                    if (!isUsing)
                    {
                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开始检测开机特性");

                        isUsing = true;
                        string result = "";
                        double sum = 0.0;
                        for (int i = 0; i < 3; i++)
                        {
                            string fre = getFrequencyData(portBootFeature);
                            if (fre.Equals(""))
                            {
                                //MessageBox.Show("从" + portBootFeature.PortName + "获取数据失败!");
                                isUsing = false;
                                return;
                            }
                            detectionService.add(devIdStability, fre, "3");
                            sum = sum + Convert.ToDouble(fre);
                        }
                        resultBootFeature.Add(sum / 3 + "");

                        if (resultBootFeature.Count == 8)
                        {
                            string max = "0.0";
                            string min = "0.0";
                            foreach (string fre in resultBootFeature)
                            {
                                if (Convert.ToDouble(fre) > Convert.ToDouble(max)) max = fre;
                                if (Convert.ToDouble(fre) < Convert.ToDouble(min) || min.Equals("0.0")) min = fre;
                            }
                            result = (Convert.ToDouble(max) - Convert.ToDouble(min)) + "";

                            detectionItemService.updateDetecStatus(detectionId, "", "", result, "", "", "", "", "", "");                           

                            DetectionItem detectionItem = detectionItemService.searchById(detectionId);
                            if (detectionItem != null)
                            {
                                if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1"))
                                {
                                    deviceService.updateStatus(devIdBootFeature, "3", "");
                                    portBootFeature.Close();
                                }
                            }
                            HomeCtrlForm.homeCtrlForm.LoadChannelStatus();
                            timerBootFeature.Dispose();
                            resultBootFeature.Clear();
                        }

                        isUsing = false;

                        break;
                    }
                }
            }


        }
        #endregion




        #region 日老化率
        public void detecAgeRate(long deviceId, string startTime, SerialPort port, bool isStartNow)
        {
            resultAgeRate = new List<string>();
            portAgeRate = port;
            devIdAgeRate = deviceId;
            int delay = 0;
            if (!isStartNow && Convert.ToDateTime(startTime) > DateTime.Now)
            {
                TimeSpan secondSpan = new TimeSpan(Convert.ToDateTime(startTime).Ticks - DateTime.Now.Ticks);
                delay = secondSpan.Milliseconds;
            }
            timerAgeRate = new System.Threading.Timer(exeAgeRate, null, delay + 100, 12 * 60 * 60 * 1000);
        }
        private void exeAgeRate(Object State)
        {
            while (true)
            {
                lock (obj)
                {
                    if (!isUsing)
                    {
                        isUsing = true;
                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开始检测日老化率");

                        string result = "";
                        double sum = 0.0;
                        for (int i = 0; i < 3; i++)
                        {
                            string fre = getFrequencyData(portAgeRate);
                            if (fre.Equals(""))
                            {
                                //MessageBox.Show("从" + portAgeRate.PortName + "获取数据失败!");
                                isUsing = false;
                                return;
                            }
                            detectionService.add(devIdStability, fre, "4");
                            sum = sum + Convert.ToDouble(fre);
                        }
                        resultAgeRate.Add(sum / 3 + "");

                        if (resultAgeRate.Count == 15)
                        {
                            double r = 0.0;
                            double k = FreMath.DriftRate(resultAgeRate, out r);
                            result = k + "," + r;
                            LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "日老化率检测结果:" + result);

                            detectionItemService.updateDetecStatus(detectionId, "", "", "", result, "", "", "", "", "");                            

                            DetectionItem detectionItem = detectionItemService.searchById(detectionId);
                            if (detectionItem != null)
                            {
                                if (!detectionItem.Stability.Equals("-1") && !detectionItem.Accuracy.Equals("-1") && !detectionItem.AgeRate.Equals("-1") && !detectionItem.BootFeature.Equals("-1"))
                                {
                                    deviceService.updateStatus(devIdAgeRate, "3", "");
                                    portAgeRate.Close();
                                }
                            }
                            HomeCtrlForm.homeCtrlForm.LoadChannelStatus();
                            timerAgeRate.Dispose();
                            resultAgeRate.Clear();
                        }
                        isUsing = false;

                        break;
                    }
                }
            }
        }
        #endregion
       



        // 获取检测数据
        public string getFrequencyData(SerialPort port)
        {
            try
            {
                if (port.IsOpen) LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "portname:" + port.PortName);
                else LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, port.PortName + " port closed");
                string received = "";
                if (ConfigHelper.GetAppConfig("deviceType").ToString().Equals("1"))
                {
                    int count = 0;
                    LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开始获取测量值1");

                    while (count < 5000)
                    {
                        int readLen = port.BytesToRead;
                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "readLen =" + readLen);

                        if (readLen > 0)
                        {
                            byte[] buffer = new byte[readLen];
                            port.Read(buffer, 0, readLen);// 接收数据到buffer里面
                            string data = Encoding.ASCII.GetString(buffer);
                            string[] dataArray = data.Split(' ');
                            if (data.StartsWith("$") && dataArray.Length == 2 && data.LastIndexOf('$') == 0)
                            {
                                if (received.Contains("-"))
                                {
                                    received =( Convert.ToDouble(dataArray[0].Replace("$", "")) - Convert.ToDouble("0."+data.Split(' ')[1].Replace(".", "").Replace("-","").TrimEnd('0')))+ "";
                                }
                                else received = dataArray[0].Replace("$", "") + "." + data.Split(' ')[1].Replace(".", "").TrimEnd('0');

                                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "before received = " + received);

                                received = ((Convert.ToDouble(received) - 10000000) / 10000000) +"";
                                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "received = "+ received);

                                break;
                            }
                        }
                        count++;
                    }
                }
                else
                {
                    LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "开始获取测量值2");

                    int count = 0;

                    while (count < 5000)
                    {
                        int readLen = port.BytesToRead;
                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "readLen=" + readLen);

                        if (readLen > 0)
                        {
                            byte[] buffer = new byte[readLen];
                            port.Read(buffer, 0, readLen);// 接收数据到buffer里面
                            string data = Encoding.ASCII.GetString(buffer);
                            string[] dataArray = data.Split(' ');
                            if (dataArray.Length >= 3)
                            {
                                foreach (string sss in dataArray)
                                {
                                    if (sss.Contains("E"))
                                    {
                                        received = sss;
                                        //received = float.Parse(received)+"";
                                        LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "获取测量值2:" + received + ":" + data);
                                        break;
                                    }
                                }
                                if (!received.Equals("")) break;
                            }
                        }
                        count++;
                    }
                }
                isUsing = false;

                if (received.Equals(""))
                {
                    string name = ConfigHelper.getKeyByValue(port.PortName + " 115200").Replace("channel","通道");
                    LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, name+"获取数据失败!"+ DateTime.Now.ToLongTimeString());
                }
                return received;
            }
            catch (Exception ex)
            {
                LogHelper.WriteErrorLog(MethodBase.GetCurrentMethod().DeclaringType, "错误:" + ex.Message);
                return "";
            }

        }

        private void updateView(List<string> result)
        {
            isUpdate = false;
            new Thread(() =>
            {
                int index = 0;
                foreach (DataGridViewRow row in DetailDlg.dataGridView.Rows)
                {
                    if (index < result.Count)
                    {
                        row.Cells[1].Value = result[index].ToString();
                        detectionService.updateFrequency(Convert.ToInt64(row.Cells[3].Value), result[index].ToString());
                    }
                    index++;
                }
                DetailDlg.label_redetecting.Visible = false;

            }).Start();
           
        }


       
    }
}