Exemple #1
0
        private void chart1_Click(object sender, EventArgs e)
        {
            chart1.Series.Clear();
            List <List <float> > dataList;
            string fileName = textBox1.Text;

            string[] tag = File.ReadAllLines(@".\SearchString.txt");
            dataList = CSVHelper.OpenCSV(@fileName, tag);
            //start
            int iStart = Convert.ToInt32(textBox2.Text) * 4;

            for (int i = 0; i < 2; i++)
            {
                Series s1 = new Series("s" + i);
                s1.ChartType           = SeriesChartType.Spline;
                s1.IsValueShownAsLabel = true;

                float[] x = dataList[iStart + i * 2].ToArray();
                float[] y = dataList[iStart + i * 2 + 1].ToArray();
                for (int j = 0; j < x.Length; j++)
                {
                    s1.Points.AddXY(x[j], y[j]);
                }
                chart1.Series.Add(s1);
            }
        }
        public List <List <float> > readCSVgetCurrent(List <List <string> > pressure, string fileName, List <List <string> > currStandardData, List <List <string> > currStandardDataSearch)
        {
            List <List <float> > dataList;
            int lineCount = pressure.Count;
            List <List <float> > current = new List <List <float> >();

            for (int i = 0; i < lineCount; i++)
            {
                List <float> l = new List <float>();
                current.Add(l);
            }
            string[] tag = File.ReadAllLines(@".\SearchString.txt");
            if (tag.Length != 24)
            {
                string errormsg = "SearchString.txt文件中数据应为24行!";
                throw new Exception(errormsg);
            }
            //MessageBox.Show("pre open", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            dataList = CSVHelper.OpenCSV(fileName, tag);
            for (int i = 0; i < dataList.Count; i++)
            {
                if (dataList[i].Count <= 0)
                {
                    string errormsg = "SearchString.txt中" + (i + 1) + "行(" + tag[i] + ")在原始数据里没有找到";
                    throw new Exception(errormsg);
                }
            }
            //MessageBox.Show("tail open", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //start
            INIHelper ini = new INIHelper(@"./CurrStandard.ini", "Demo");

            string[] iniKey     = { "PinkValue" };
            string[] iniSetting = new string[1];
            ini.read(iniKey, out iniSetting);
            for (int i = 0; i < dataList.Count / 4; i++)
            {
                float[] x  = dataList[i * 4].ToArray();
                float[] y  = dataList[i * 4 + 1].ToArray();
                float[] xx = dataList[i * 4 + 2].ToArray();
                float[] yy = dataList[i * 4 + 3].ToArray();
                for (int k = 0; k < x.Length; k++)
                {
                    x[k] = x[k] / 1000;
                }
                for (int k = 0; k < xx.Length; k++)
                {
                    xx[k] = xx[k] / 1000;
                }
                for (int j = 0; j < pressure[i].Count; j++)
                {
                    //MessageBox.Show("average pre", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    AverageXAverageY a      = new BXHSerialPort.AverageXAverageY();
                    float            v1     = 0;
                    float            v2     = 0;
                    bool             v1Find = a.ifFind(x, y, pressure[i][j], currStandardDataSearch[i][j]);
                    bool             v2Find = a.ifFind(xx, yy, pressure[i][j], currStandardDataSearch[i][j]);
                    if (v1Find || v2Find)
                    {
                        v2 = a.getAverageX(xx, yy, pressure[i][j], currStandardData[i][j], currStandardDataSearch[i][j]);
                        v1 = a.getAverageX(x, y, pressure[i][j], currStandardData[i][j], currStandardDataSearch[i][j]);
                    }
                    //else if (v1Find&&(!v2Find))
                    //{
                    //    v1 = a.getAverageX(x, y, pressure[i][j], currStandardData[i][j], currStandardDataSearch[i][j]);
                    //    v2 = v1;
                    //    v2 = a.getAverageX(xx, yy, pressure[i][j], currStandardData[i][j], currStandardDataSearch[i][j]);
                    //}
                    //else if ((!v1Find) && v2Find)
                    //{
                    //    v2 = a.getAverageX(xx, yy, pressure[i][j], currStandardData[i][j], currStandardDataSearch[i][j]);
                    //    v1 = v2;
                    //    v1 = a.getAverageX(x, y, pressure[i][j], currStandardData[i][j], currStandardDataSearch[i][j]);
                    //}
                    else
                    {
                        string errormsg = "没有搜索到这个压力数据:" + pressure[i][j] + "";
                        throw new Exception(errormsg);
                    }
                    //MessageBox.Show("shuju", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    float resultValue = (v1 + v2) / 2;
                    if ((currStandardDataSearch[i][j] != "55") && (currStandardDataSearch[i][j] != "66") && (pressure[i][j] != "NA"))
                    {
                        float currStand;
                        float pinkValue;
                        try
                        {
                            currStand = Convert.ToSingle(currStandardData[i][j]);
                            pinkValue = Convert.ToSingle(iniSetting[0]);
                        }
                        catch (Exception)
                        {
                            string errormsg = "判断粉色部分的数据值,标准电流:" + currStandardData[i][j] + ",行:" + (i + 1) + "第" + (j + 1) + "个数据" + ",差值基准:" + iniSetting[0];
                            throw new Exception(errormsg);
                        }
                        float abs = Math.Abs(resultValue - currStand);
                        if (abs > pinkValue)
                        {
                            string errormsg = "(粉色部分的数据值 - TCU内部标准值) =差值的绝对值 > " + pinkValue + ",\n行:" + (i + 1) + "第" + (j + 1) + "个数据,压力值:" + pressure[i][j] + ",计算值:" + resultValue + ",标准值:" + currStandardData[i][j];
                            throw new Exception(errormsg);
                        }
                    }
                    current[i].Add(resultValue);
                }
            }
            //end

            return(current);
        }