Beispiel #1
0
 private static bool edgeTestPoint(double x, double y, plotData spec, bool isUpper)
 {
     for (int i = 0; i < spec.xData.Length; i++)
     {
         if (x == spec.xData[i])
         {
             if (float.IsNaN(spec.yData[i]))
             {
                 return(true);
             }
             if (isUpper)
             {
                 if (y >= spec.yData[i])
                 {
                     return(false);
                 }
             }
             else
             {
                 if (y <= spec.yData[i])
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Beispiel #2
0
        private static string[] getTDDString(plotData TDD, TDD tddParams, string itemName)
        {
            int lengthCount = tddParams.points - 1;

            double step       = (double.Parse(tddParams.stopTime) - double.Parse(tddParams.startTime)) / lengthCount;
            double temp       = 0;
            double startValue = double.Parse(TDD.xData[0].ToString());
            double endValue   = double.Parse(TDD.xData.Max().ToString());

            string[] retValue = new string[lengthCount + 2];

            int startPoint = (int)(startValue / step);
            int endPoint   = (int)(endValue / step);

            retValue[0] = itemName;
            for (int i = 1; i < startPoint + 1; i++)
            {
                retValue[i] = "NaN";
            }

            for (int i = startPoint + 1; i <= endPoint + 1; i++)
            {
                retValue[i] = TDD.yData[i - startPoint - 1].ToString();
            }

            for (int i = endPoint + 2; i < lengthCount + 2; i++)
            {
                retValue[i] = "NaN";
            }

            return(retValue);
        }
Beispiel #3
0
        public static plotData[]  GetTddSpec(TDD tdd)
        {
            plotData[] ret  = new plotData[2];
            double     step = (float.Parse(tdd.stopTime) - float.Parse(tdd.startTime)) / (tdd.points - 1);

            float[] timeArray = new float[tdd.points];

            var    cc          = tdd.impedance.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(t => t.Split('#').ToArray()).ToArray();
            double upperPoint1 = double.Parse((cc[0][1]));
            double upperPoint2 = double.Parse((cc[1][1]));
            double upperPoint3 = (double.Parse(tdd.stopTime) - upperPoint2) / 2 + upperPoint2;
            double upperValue1 = double.Parse((cc[0][2]));
            double upperValue2 = double.Parse((cc[1][2]));

            double lowerPoint1 = double.Parse((cc[0][3]));
            double lowerPoint2 = double.Parse((cc[1][3]));
            double lowerPoint3 = (double.Parse(tdd.stopTime) - lowerPoint2) / 2 + lowerPoint2;
            double lowerValue1 = double.Parse((cc[0][4]));
            double lowerValue2 = double.Parse((cc[1][4]));


            List <float> x      = new List <float>();
            List <float> y      = new List <float>();
            double       pointX = upperPoint1;

            while (pointX <= upperPoint2)
            {
                x.Add(float.Parse(pointX.ToString()));
                y.Add(float.Parse(upperValue1.ToString()));
                pointX = pointX + step;
            }
            while (pointX <= upperPoint3)
            {
                x.Add(float.Parse(pointX.ToString()));
                y.Add(float.Parse(upperValue2.ToString()));
                pointX = pointX + step;
            }

            ret[0].xData = x.ToArray();
            ret[0].yData = y.ToArray();

            x.Clear();
            y.Clear();
            pointX = lowerPoint1;
            while (pointX <= lowerPoint2)
            {
                x.Add(float.Parse(pointX.ToString()));
                y.Add(float.Parse(lowerValue1.ToString()));
                pointX = pointX + step;
            }
            while (pointX <= lowerPoint3)
            {
                x.Add(float.Parse(pointX.ToString()));
                y.Add(float.Parse(lowerValue2.ToString()));
                pointX = pointX + step;
            }
            ret[1].xData = x.ToArray();
            ret[1].yData = y.ToArray();
            return(ret);
        }
Beispiel #4
0
        //public static FileSaveConfig getFileSaveConfig(string xmlFilePath)
        //{
        //    XElement xe = XElement.Load(@xmlFilePath);
        //    XElement xle = (from ele in xe.Elements("FileSave") select ele).FirstOrDefault();
        //    FileSaveConfig fsc = new FileSaveConfig();
        //    fsc.savePath = xle.Element("savePath").Value;
        //    return fsc;
        //}

        //public static bool saveFileConfig(string xmlFilePath,string pnSaveFolderPath)
        //{
        //    XElement xe = XElement.Load(@xmlFilePath);
        //    XElement xle = (from ele in xe.Elements("FileSave") select ele).FirstOrDefault();
        //    xle.Element("savePath").Value = pnSaveFolderPath;
        //    xe.Save(xmlFilePath);
        //    return true;
        //}

        //public static bool saveSNClearConfig(string xmlFilePath, string SNClear)
        //{
        //    XElement xe = XElement.Load(@xmlFilePath);
        //    //XElement a = xe.Element("MaxTestNum");
        //    XElement xle = (from ele in xe.Elements("ClearSN") select ele).FirstOrDefault();
        //    xle.Value = SNClear;
        //    xe.Save(xmlFilePath);
        //    return true;
        //}

        //public static bool getSNClearConfig(string xmlFilePath)
        //{
        //    XElement xe = XElement.Load(@xmlFilePath);
        //    //XElement a = xe.Element("MaxTestNum");
        //    XElement xle = (from ele in xe.Elements("ClearSN") select ele).FirstOrDefault();
        //    if (xle.Value == "True")
        //    {
        //        return true;
        //    }
        //    else {
        //        return false;
        //    }
        //}

        //public static int getMaxTestNum(string xmlFilePath)
        //{
        //    XElement xe = XElement.Load(@xmlFilePath);
        //    //XElement a = xe.Element("MaxTestNum");
        //    XElement xle = (from ele in xe.Elements("MaxTestNum") select ele).FirstOrDefault();
        //    return int.Parse(xle.Value);
        //}



        public static plotData read(string FilePath)
        {
            int      start     = -1;
            int      end       = -1;
            int      length    = 0;
            plotData pPlotData = new plotData();

            string[] temp = File.ReadAllLines(FilePath);

            for (int i = 0; i < temp.Length; i++)
            {
                if (temp[i].StartsWith("%"))
                {
                    start = i;
                }
                if (temp[i].StartsWith("END"))
                {
                    end = i;
                }
            }
            if ((start == -1) || (end == -1))
            {
                throw new Exception("can not find start or end from the mdf file!");
            }
            length = end - start - 1;
            float[][] arrayData = temp.Skip(start + 1).Take(length).
                                  Select(x => x.Split(' ').Select(a => (float)Convert.ToDouble(a)).ToArray()).ToArray();
            pPlotData.xData = arrayData.Select(a => a[0]).ToArray();
            pPlotData.yData = arrayData.Select(a => a[1]).ToArray();
            return(pPlotData);
        }
Beispiel #5
0
 private static bool edgeTestLine(plotData data, plotData spec, bool isUpper)
 {
     for (int i = 0; i < data.xData.Length; i++)
     {
         if (!edgeTestPoint(data.xData[i], data.yData[i], spec, isUpper))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #6
0
        public static bool edgeTest(plotData[] data, plotData spec, bool isUpper)
        {
            for (int i = 0; i < data.Length; i++)
            {
                if (!edgeTestLine(data[i], spec, isUpper))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #7
0
        getDiff(Dictionary <string, string[]> testItems, string snpFilepath, SNPPort snpPort, Dictionary <string, plotData> spec, ref bool action, ref string msg)
        {
            //System.GC.Collect();
            Dictionary <string, plotData[]> ret = new Dictionary <string, plotData[]>();

            try
            {
                SNP snpClass = new SNP(snpFilepath, snpPort);
                foreach (var item in testItems)
                {
                    formatedData fData   = snpClass.getDiff(item.Value);
                    int          columns = fData.dB.GetLength(1);
                    int          rows    = fData.dB.GetLength(0);
                    float[]      offset  = new float[rows];
                    if (spec.ContainsKey(item.Key + "_OFFSET"))
                    {
                        for (int row = 0; row < rows; row++)
                        {
                            offset[row] = spec[item.Key + "_OFFSET"].yData[row];
                        }
                    }

                    plotData[] singleItem = new plotData[columns];
                    for (int curveNo = 0; curveNo < columns; curveNo++)
                    {
                        float[] y = new float[rows];
                        for (int row = 0; row < rows; row++)
                        {
                            y[row] = fData.dB[row, curveNo] + offset[row];
                        }
                        singleItem[curveNo].yData = y;
                        singleItem[curveNo].xData = fData.fre;
                        y = null;
                    }
                    ret.Add(item.Key, singleItem);
                    singleItem = null;
                    fData      = new formatedData();
                }
                snpClass = null;
                //System.GC.Collect();
                action = true;
                return(ret);
            }
            catch (Exception ex)
            {
                action = false;
                msg    = ex.Message;
                //MessageBoxEx.Show(ex.Message);
                return(null);
            }
        }
Beispiel #8
0
        public static Dictionary <string, bool> judge(Dictionary <string, plotData> spec, Dictionary <string, plotData[]> data)
        {
            Dictionary <string, bool> ret = new Dictionary <string, bool>();

            foreach (var item in data)
            {
                bool blUpper = true;
                bool blLower = true;
                if (spec.ContainsKey(item.Key + "_UPPER"))
                {
                    plotData specSingle = spec[item.Key + "_UPPER"];
                    blUpper = edgeTest(item.Value, specSingle, true);
                }
                if (spec.ContainsKey(item.Key + "_LOWER"))
                {
                    plotData specSingle = spec[item.Key + "_LOWER"];
                    blLower = edgeTest(item.Value, specSingle, false);
                }
                ret.Add(item.Key, blUpper && blLower);
            }
            return(ret);
        }
Beispiel #9
0
        getAnalyzedData(List <TestItem> testItems, string snpFilepath, SNPPort snpPort, Dictionary <string, plotData> spec,
                        TDD[] tdds,
                        ref bool action, ref string msg, ref Dictionary <string, string[]> pairNameDictionary)
        {
            int pairNum = 8;

            pairNameDictionary.Clear();
            string[] pairNames = new string[pairNum];
            Dictionary <string, plotData[]> ret = new Dictionary <string, plotData[]>();

            try
            {
                SNP snpClass = new SNP(snpFilepath, snpPort);
                foreach (var testItem in testItems)
                {
                    string item = testItem.testName.ToUpper();
                    if (item.StartsWith("T"))
                    {
                        TDD            tdd      = item.Equals("TDD11") ? tdds[0] : tdds[1];
                        timeDomainData tData    = snpClass.EasyGetTimeData(item, out pairNames, double.Parse(tdd.riseTime), (double.Parse(tdd.stopTime) - double.Parse(tdd.startTime)) / (tdd.points - 1), tdd.points, double.Parse(tdd.offset));
                        int            tColumns = tData.resistance.GetLength(1);
                        int            tRows    = tData.resistance.GetLength(0);
                        float[]        offset   = new float[tRows];
                        if (spec.ContainsKey(item + "_OFFSET"))
                        {
                            for (int row = 0; row < tRows; row++)
                            {
                                offset[row] = spec[item + "_OFFSET"].yData[row];
                            }
                        }

                        plotData[] tItem = new plotData[tColumns];
                        for (int curveNo = 0; curveNo < tColumns; curveNo++)
                        {
                            float[] y = new float[tRows];
                            for (int row = 0; row < tRows; row++)
                            {
                                y[row] = tData.resistance[row, curveNo] + offset[row];
                            }
                            tItem[curveNo].yData = y;
                            tItem[curveNo].xData = tData.time;
                            y = null;
                        }

                        ret.Add(item, tItem);
                        pairNameDictionary.Add(item, pairNames);
                    }
                    else if (item.Equals("SINGLE"))
                    {
                        string[] pairNameSingles = new[]
                        {
                            "S1_17", "S2_18", "S3_19", "S4_20",
                            "S5_21", "S6_22", "S7_23", "S8_24",
                            "S9_25", "S10_26", "S11_27", "S12_28",
                            "S13_29", "S14_30", "S15_31", "S16_32"
                        };
                        formatedData sfData     = snpClass.getSingle(pairNameSingles);
                        int          sColumns   = sfData.dB.GetLength(1);
                        int          sRows      = sfData.dB.GetLength(0);
                        plotData[]   singleItem = new plotData[sColumns];
                        for (int curveNo = 0; curveNo < sColumns; curveNo++)
                        {
                            float[] y = new float[sRows];
                            for (int row = 0; row < sRows; row++)
                            {
                                y[row] = sfData.dB[row, curveNo];
                            }
                            singleItem[curveNo].yData = y;
                            singleItem[curveNo].xData = sfData.fre;
                            y = null;
                        }
                        ret.Add(item, singleItem);
                        pairNameDictionary.Add(item, pairNameSingles);
                    }
                    else if (item.Equals("ILD"))
                    {
                        formatedData fData   = snpClass.EasyGetILD(testItem.IldSpec, out pairNames);
                        int          columns = fData.dB.GetLength(1);
                        int          rows    = fData.dB.GetLength(0);
                        float[]      offset  = new float[rows];
                        if (spec.ContainsKey(item + "_OFFSET"))
                        {
                            for (int row = 0; row < rows; row++)
                            {
                                offset[row] = spec[item + "_OFFSET"].yData[row];
                            }
                        }

                        plotData[] diffItem = new plotData[columns];
                        for (int curveNo = 0; curveNo < columns; curveNo++)
                        {
                            float[] y = new float[rows];
                            for (int row = 0; row < rows; row++)
                            {
                                y[row] = fData.dB[row, curveNo] + offset[row];
                            }
                            diffItem[curveNo].yData = y;
                            diffItem[curveNo].xData = fData.fre;
                            y = null;
                        }
                        ret.Add(item, diffItem);
                        diffItem = null;
                        fData    = new formatedData();
                        pairNameDictionary.Add(item, pairNames);
                    }
                    else
                    {
                        formatedData fData   = snpClass.EasyGetfreData(item, out pairNames);
                        int          columns = fData.dB.GetLength(1);
                        int          rows    = fData.dB.GetLength(0);
                        float[]      offset  = new float[rows];
                        if (spec.ContainsKey(item + "_OFFSET"))
                        {
                            for (int row = 0; row < rows; row++)
                            {
                                offset[row] = spec[item + "_OFFSET"].yData[row];
                            }
                        }

                        plotData[] diffItem = new plotData[columns];
                        for (int curveNo = 0; curveNo < columns; curveNo++)
                        {
                            float[] y = new float[rows];
                            for (int row = 0; row < rows; row++)
                            {
                                if (!float.IsNaN(offset[row]))
                                {
                                    y[row] = fData.dB[row, curveNo] + offset[row];
                                }
                                else
                                {
                                    y[row] = fData.dB[row, curveNo];
                                }
                            }
                            diffItem[curveNo].yData = y;
                            diffItem[curveNo].xData = fData.fre;
                            y = null;
                        }
                        ret.Add(item, diffItem);
                        diffItem = null;
                        fData    = new formatedData();
                        pairNameDictionary.Add(item, pairNames);
                    }
                }
                snpClass = null;
                //System.GC.Collect();
                action = true;
                return(ret);
            }
            catch (Exception ex)
            {
                action = false;
                msg    = ex.Message;
                //MessageBoxEx.Show(ex.Message);
                return(null);
            }
        }
Beispiel #10
0
        public static Dictionary <string, plotData> GetPnSpec(string PN, ref TDD[] tdds, ref string description, ref string[][] freSpec, ref string TDDSpec, bool DBoffline, ref List <TestItem> testItems, ref bool eprWrite)
        {
            if (!PingIpOrDomainName("172.20.23.107") && !DBoffline)
            {
                MessageBoxEx.Show("无法连接到IP地址172.20.23.107,请检查网络");
                return(null);
            }
            string strSql = "select frequency,TDR,general,project,label from vna32port where LuxsharePN='" + PN + "'";
            //DataTable dt= DbHelperOleDb.Query(strSql,DB_HTPSDBConnectionString).Tables[0];
            DataTable dt = null;

            try
            {
                dt = DBoffline
                    ? SqlLite.ExecuteDataTable(strSql)
                    : DbHelperOleDb.Query(strSql, DB_HTPSDBConnectionString).Tables[0];
            }
            catch (Exception e)
            {
                MessageBoxEx.Show(e.Message);
            }

            if (dt.Rows.Count != 1)
            {
                return(null);
            }

            string labelStr = dt.Rows[0]["Label"].ToString();
            string ers      = labelStr.Split('\t')[4].ToUpper().Trim();

            eprWrite = ers.Equals("TRUE");
            string freSpecStr = dt.Rows[0]["frequency"].ToString();
            string tdr        = dt.Rows[0]["TDR"].ToString();
            string general    = dt.Rows[0]["general"].ToString();

            description = general.Split('\t')[5];
            tdds        = getTdd(tdr);
            testItems   = getTestItems(dt.Rows[0]["project"].ToString());
            plotData[] tdd1 = GetTddSpec(tdds[0]);
            plotData[] tdd2 = GetTddSpec(tdds[1]);
            string     bb   = freSpecStr.Split('\t')[0];

            freSpec = bb.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(t => t.Split('#').ToArray()).ToArray();
            Dictionary <string, plotData> ret = new Dictionary <string, plotData>();

            for (int i = 1; i < freSpec[0].Length; i++)
            {
                plotData     temp = new plotData();
                List <float> x    = new List <float>();
                List <float> y    = new List <float>();
                for (int j = 1; j < freSpec.Length; j++)
                {
                    if (freSpec[j][0] != "NaN")
                    {
                        x.Add((float)(double.Parse(freSpec[j][0])));
                    }
                    else
                    {
                        break;
                    }

                    if (freSpec[j][i] != "NaN")
                    {
                        y.Add((float)(double.Parse(freSpec[j][i])));
                    }
                    else
                    {
                        y.Add(float.NaN);
                    }
                }
                temp.xData = x.ToArray();
                temp.yData = y.ToArray();
                ret.Add(freSpec[0][i].ToUpper(), temp);
            }
            ret.Add("TDD11_UPPER", tdd1[0]);
            ret.Add("TDD11_LOWER", tdd1[1]);
            ret.Add("TDD22_UPPER", tdd2[0]);
            ret.Add("TDD22_LOWER", tdd2[1]);

            string[]   temStrings0 = getTDDString(tdd1[0], tdds[0], "TDD11_UPPER");
            string[]   temStrings1 = getTDDString(tdd1[1], tdds[0], "TDD11_LOWER");
            string[]   temStrings2 = getTDDString(tdd2[0], tdds[1], "TDD22_UPPER");
            string[]   temStrings3 = getTDDString(tdd2[1], tdds[1], "TDD22_LOWER");
            string[][] TDDArray    = { temStrings0, temStrings1, temStrings2, temStrings3 };
            TDDSpec = getTDDString(TDDArray);

            return(ret);
        }