private void Analyze(TaskSnp taskSnp, ConsumerParams cpParams) { SNP temp = new SNP(taskSnp.SnpPath, SNPPort.X1324); // Thread.Sleep(2000); foreach (var testItem in taskSnp.AnalyzeItem) { object tempChart = cpParams.ChartDic[testItem]; plotData offset = new plotData(); if (cpParams.Spec.ContainsKey(testItem + "_OFFSET")) { offset = cpParams.Spec[testItem + "_OFFSET"]; } plotData plotData = GetPlotdata(temp, testItem, taskSnp, cpParams, offset); string savePath = cpParams.SaveTxtPath + "\\" + testItem + ".txt"; SaveTxt(plotData, savePath); cpParams.FormUi.AddStatus(savePath + " " + LanguageHelper.GetMsgText("写入成功")); InsertTestData(plotData, testItem, taskSnp.PairName); DrawSpec(testItem, cpParams, tempChart); bool result = Code.Utility.Convert.Judge(cpParams.Spec, plotData, testItem); cpParams.FormUi.AddStatus(testItem + " " + taskSnp.PairName + ":" + (result ? "PASS" : "Fail")); InsertTestJudge(testItem, result, taskSnp.PairName); cpParams.FormUi.SetCheckItem(taskSnp.PairName, taskSnp.ClbType); cpParams.FormUi.SetCheckItem(testItem, ClbType.TestItem); cpParams.AChart.DrawLine(tempChart, plotData, taskSnp.PairName, testItem.StartsWith("TDD") ? LineType.Time : LineType.Fre); } }
public static Dictionary <string, plotData> GetPnSpec(Project pnProject) { Dictionary <string, plotData> ret = new Dictionary <string, plotData>(); DataTable dt = Serializer.Json2DataTable(pnProject.FreSpec); int frePoints = dt.Rows.Count; int specNum = dt.Columns.Count; for (int i = 1; i < specNum; i++) { plotData temp = new plotData(); List <float> x = new List <float>(); List <float> y = new List <float>(); string itemName = dt.Columns[i].ColumnName.ToString().ToUpper(); if (itemName.Contains("OFFSET")) { for (int j = 0; j < frePoints; j++) { var cellValue = dt.Rows[j][i]; x.Add(float.Parse((string)dt.Rows[j][0])); if (!(cellValue is DBNull)) { y.Add(float.Parse((string)cellValue)); } else { y.Add(0); } } } else { for (int j = 0; j < frePoints; j++) { var cellValue = dt.Rows[j][i]; if (!(cellValue is DBNull)) { x.Add(float.Parse((string)dt.Rows[j][0])); y.Add(float.Parse((string)cellValue)); } } } temp.xData = x.ToArray(); temp.yData = y.ToArray(); ret.Add(itemName, temp); } plotData[] tdd1 = GetTddSpec(pnProject.Tdd11); plotData[] tdd2 = GetTddSpec(pnProject.Tdd22); ret.Add("TDD11_UPPER", tdd1[0]); ret.Add("TDD11_LOWER", tdd1[1]); ret.Add("TDD22_UPPER", tdd2[0]); ret.Add("TDD22_LOWER", tdd2[1]); SaveSpec(dt, tdd1, tdd2); return(ret); }
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); }
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); }
private void DataConsumer(object data) { try { ConsumerParams cpParams = (ConsumerParams)data; foreach (var variable in cpParams.TestConfigs) { if (variable.ItemType == ItemType.Last) { foreach (var testItem in variable.AnalyzeItems) { object tempChart = cpParams.ChartDic[testItem]; List <PairData> itemPairDatas = new List <PairData>(); if (testItem == "MDNEXT") { itemPairDatas = GetMdNext(); _testData.Add("MDNEXT", itemPairDatas); } if (testItem == "MDFEXT") { itemPairDatas = GetMdFext(); _testData.Add("MDFEXT", itemPairDatas); } if (testItem == "ICR") { itemPairDatas = GetIcr(); _testData.Add("ICR", itemPairDatas); } DrawSpec(testItem, cpParams, tempChart); foreach (var pairData in itemPairDatas) { plotData plotData = new plotData(); plotData.xData = pairData.XData; plotData.yData = pairData.YData; bool result = Code.Utility.Convert.Judge(cpParams.Spec, plotData, testItem); cpParams.FormUi.AddStatus(testItem + " " + pairData.PairName + ":" + (result ? "PASS" : "Fail")); InsertTestJudge(testItem, result, pairData.PairName); cpParams.FormUi.SetCheckItem(testItem, ClbType.TestItem); cpParams.AChart.DrawLine(tempChart, plotData, pairData.PairName, testItem.StartsWith("TDD") ? LineType.Time : LineType.Fre); string savePath = cpParams.SaveTxtPath + "\\" + testItem + ".txt"; SaveTxt(plotData, savePath); cpParams.FormUi.AddStatus(savePath + " " + LanguageHelper.GetMsgText("写入成功")); } } } } } catch (Exception e) { Ui.MessageBoxMuti(e.Message); } }
public static bool Judge(Dictionary <string, plotData> spec, plotData data, string testItem) { Dictionary <string, bool> ret = new Dictionary <string, bool>(); bool blUpper = true; bool blLower = true; if (spec.ContainsKey(testItem + "_UPPER")) { plotData specSingle = spec[testItem + "_UPPER"]; blUpper = edgeTestLine(data, specSingle, true); } if (spec.ContainsKey(testItem + "_LOWER")) { plotData specSingle = spec[testItem + "_LOWER"]; blLower = edgeTestLine(data, specSingle, false); } return(blUpper && blLower); }
public void DrawLine(object tChart, plotData temp, string seriName, LineType lineType) { ZedGraphControl chart = (ZedGraphControl)tChart; GraphPane myPane = chart.GraphPane; if (chart.InvokeRequired) { SetDrawLineCallBack d = DrawLine; chart.Invoke(d, new object[] { chart, temp, seriName, lineType }); } else { PointPairList list = new PointPairList(); //int length = temp.xData.Length; //for (int i = 0; i < length; i++) //{ // list.Add(temp.xData[i],temp.yData[i]); //} //double[]a=new double[100]; // Generate a blue curve with circle symbols, and "My Curve 2" in the legend LineItem myCurve1 = new LineItem(seriName, temp.xData.Select(x => (double)x).ToArray(), temp.yData.Select(x => (double)x).ToArray(), lineType == LineType.Spec ? Color.Red : Util.getRandomColor(), SymbolType.None, 0.1f); myCurve1.Line.IsSmooth = true; myCurve1.Line.SmoothTension = 0.1F; myCurve1.Line.GradientFill.Type = FillType.Brush; myPane.CurveList.Add(myCurve1); // myPane.AddCurve(seriName, temp.xData.Select(x => (double)x).ToArray(), temp.yData.Select(x => (double)x).ToArray(), lineType == LineType.Spec ? Color.Red : Util.getRandomColor(), SymbolType.None); myPane.Legend.Position = LegendPos.InsideBotRight; chart.AxisChange(); //chart.IsAntiAlias = true; chart.Refresh(); } }
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); }
private void InsertTestData(plotData plotData, string testItem, string pairName) { if (_testData.ContainsKey(testItem)) { PairData pairData = new PairData(); pairData.YData = plotData.yData; pairData.XData = plotData.xData; pairData.PairName = pairName; _testData[testItem].Add(pairData); //cpParams.addStatus(testItem + ":num:" + _testData[testItem].Count); } else { List <PairData> temps = new List <PairData>(); PairData pairData = new PairData(); pairData.YData = plotData.yData; pairData.XData = plotData.xData; pairData.PairName = pairName; temps.Add(pairData); _testData.Add(testItem, temps); } }
private static bool edgeTestPoint(double x, double y, plotData spec, bool isUpper) { for (int i = 0; i < spec.xData.Length; i++) { if (Math.Abs(x - spec.xData[i]) < float.Epsilon) { if (isUpper) { if (y >= spec.yData[i]) { return(false); } } else { if (y <= spec.yData[i]) { return(false); } } } } return(true); }
private void SaveTxt(plotData plotData, string saveFilePath) { if (File.Exists(saveFilePath)) { var allLines = File.ReadAllLines(saveFilePath); int length = allLines.Length; string[] addedLines = new string[length]; for (int i = 0; i < length; i++) { addedLines[i] = allLines[i] + "\t" + plotData.yData[i]; } File.WriteAllLines(saveFilePath, addedLines); } else { int length = plotData.xData.Length; string[] addedLines = new string[length]; for (int i = 0; i < length; i++) { addedLines[i] = plotData.xData[i] + "\t" + plotData.yData[i]; } File.WriteAllLines(saveFilePath, addedLines); } }
private plotData GetPlotdata(SNP snp, string itemName, TaskSnp taskSnp, ConsumerParams cpParams, plotData offset) { plotData dataSeries = new plotData(); List <TdrParam> tdrParams = cpParams.TestConfigs[0].TdrParams; switch (taskSnp.ItemType) { case ItemType.Loss: if (itemName.StartsWith("S")) { itemName = GetReverseItem(itemName, !taskSnp.FirstHalf && taskSnp.Srevert); // cpParams.FormUi.AddStatus("analyze:"+itemName); string[] outPairs = new string[1]; var data = snp.EasyGetfreData(itemName, out outPairs); float[] x = SConvert.indexArray(data.dB, 0, false); dataSeries.xData = data.fre; dataSeries.yData = x; } else if (itemName.StartsWith("TDD")) { itemName = GetReverseItem(itemName, !taskSnp.FirstHalf && taskSnp.Trevert); // cpParams.FormUi.AddStatus("analyze:" + itemName); TdrParam tdrParam = tdrParams[int.Parse(itemName.Substring(3, 1)) - 1]; string[] outPairs = new string[1]; double timeStep = (tdrParam.EndTime - tdrParam.StartTime) / (tdrParam.Points - 1); var data = snp.EasyGetTimeData(itemName, out outPairs, tdrParam.RiseTime, timeStep, tdrParam.Points, tdrParam.Offset); float[] x = SConvert.indexArray(data.resistance, 0, false); dataSeries.xData = data.time; dataSeries.yData = x; } else if (itemName.Equals("ILD", StringComparison.OrdinalIgnoreCase)) { string[] outPairs = new string[1]; var data = snp.EasyGetILD(cpParams.TestConfigs[0].IldSpec, out outPairs); float[] x = SConvert.indexArray(data.dB, 0, false); dataSeries.xData = data.fre; dataSeries.yData = x; } break; case ItemType.Next: if (itemName.StartsWith("NEXT")) { // cpParams.FormUi.AddStatus("analyze:" + itemName); string[] outPairs = new string[1]; var data = snp.EasyGetfreData("SDD21", out outPairs); float[] x = SConvert.indexArray(data.dB, 0, false); dataSeries.xData = data.fre; dataSeries.yData = x; } break; case ItemType.Fext: if (itemName.StartsWith("FEXT")) { // cpParams.FormUi.AddStatus("analyze:" + itemName); string[] outPairs = new string[1]; var data = snp.EasyGetfreData("SDD21", out outPairs); float[] x = SConvert.indexArray(data.dB, 0, false); dataSeries.xData = data.fre; dataSeries.yData = x; } break; } if (offset.yData != null) { int length = dataSeries.yData.Length < offset.yData.Length ? dataSeries.yData.Length : offset.yData.Length; for (int i = 0; i < length; i++) { dataSeries.yData[i] = dataSeries.yData[i] + offset.yData[i]; } } return(dataSeries); }
public static plotData[] GetTddSpec(TdrParam tdrParam) { plotData[] ret = new plotData[2]; double step = (tdrParam.EndTime - tdrParam.StartTime) / (tdrParam.Points - 1); float[] timeArray = new float[tdrParam.Points]; double upperPoint1 = tdrParam.UperTimePoints[0]; double upperPoint2 = tdrParam.UperTimePoints[1]; double upperPoint3 = (tdrParam.EndTime - upperPoint2) / 2 + upperPoint2; double upperValue1 = tdrParam.UperResi[0]; double upperValue2 = tdrParam.UperResi[1]; double lowerPoint1 = tdrParam.LowerTimePoints[0]; double lowerPoint2 = tdrParam.LowerTimePoints[1]; double lowerPoint3 = (tdrParam.EndTime - lowerPoint2) / 2 + lowerPoint2; double lowerValue1 = tdrParam.LowerResi[0]; double lowerValue2 = tdrParam.LowerResi[1]; List <float> x = new List <float>(); List <float> y = new List <float>(); double pointX = 0; while (pointX < upperPoint1) { x.Add(float.Parse(pointX.ToString())); y.Add(float.NaN); pointX = pointX + step; } 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; } while (pointX <= tdrParam.EndTime + step / 2) { x.Add(float.Parse(pointX.ToString())); y.Add(float.NaN); pointX = pointX + step; } ret[0].xData = x.ToArray(); ret[0].yData = y.ToArray(); x.Clear(); y.Clear(); pointX = 0; while (pointX < lowerPoint1) { x.Add(float.Parse(pointX.ToString())); y.Add(float.NaN); pointX = pointX + step; } 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; } while (pointX <= tdrParam.EndTime + step / 2) { x.Add(float.Parse(pointX.ToString())); y.Add(float.NaN); pointX = pointX + step; } ret[1].xData = x.ToArray(); ret[1].yData = y.ToArray(); return(ret); }
public void DrawLine(object oChart, plotData temp, string seriName, LineType lineType) { Chart chart = (Chart)oChart; if (chart.InvokeRequired) { SetDrawLineCallBack d = DrawLine; chart.Invoke(d, new object[] { chart, temp, seriName, lineType }); } else { //绑定数据 int index = chart.Series.Count; chart.Series.Add(seriName); Series currentSeries = chart.Series[index]; //chart.Titles[index].Alignment = System.Drawing.ContentAlignment.TopRight; currentSeries.XValueType = ChartValueType.Single; //设置X轴上的值类型 //currentSeries.Label = "#VAL"; //设置显示X Y的值 //currentSeries.LabelForeColor = Color.Black; currentSeries.ToolTip = "#VALX:#VAL"; //鼠标移动到对应点显示数值 currentSeries.ChartType = SeriesChartType.FastLine; //图类型(折线) //currentSeries.ChartType = SeriesChartType.Line; //图类型(折线) currentSeries.IsValueShownAsLabel = false; currentSeries.LegendText = seriName; currentSeries.IsVisibleInLegend = true; //chart.Legends[seriName].Enabled = true; //chart.Legends[seriName].MaximumAutoSize = 15; //chart.Series[0].IsValueShownAsLabel = true; // currentSeries.LabelForeColor = Color.Black; // currentSeries.CustomProperties = "DrawingStyle = Cylinder"; currentSeries.Points.DataBindXY(temp.xData, temp.yData); switch (lineType) { case LineType.Fre: for (int i = 1; i < 10; i++) { CustomLabel label = new CustomLabel(); label.Text = (i * 5).ToString() + "Ghz"; label.ToPosition = i * 10000000000; chart.ChartAreas[0].AxisX.CustomLabels.Add(label); label.GridTicks = GridTickTypes.Gridline; } break; case LineType.Time: for (int i = 1; i < 10; i++) { CustomLabel label = new CustomLabel(); label.Text = (i * 1).ToString() + "ns"; label.ToPosition = (float)i * 2; chart.ChartAreas[0].AxisX.CustomLabels.Add(label); label.GridTicks = GridTickTypes.Gridline; } break; } //chart.Visible = true; } }