private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { Selected_Reg_line = comboBox1.Text; ACOK.SipRegisters sel = EnumDescriptor.ToEnum <ACOK.SipRegisters>(Selected_Reg_line); }
public void button6_Click(object sender, EventArgs e) { string selected = comboBox1.Text; ACOK.SipRegisters sel = EnumDescriptor.ToEnum <ACOK.SipRegisters>(selected); //if (selected == "Data1") //{ // Dispdata(); //} //richTextBox2.Text += Data.GetVal(sel).ToString(); //richTextBox2.Text += " "; //i++; }
private void Rangscale(ACOK.SipRegisters sel1) { zedGraphControl1.AxisChange(); GraphPane myPane = zedGraphControl1.GraphPane; double tmpymax, tmpymin; if (axisflag == 1) { myPane.YAxis.Max = 5; myPane.YAxis.Min = -5; myPane.XAxis.Max = 5; myPane.XAxis.Min = -5; } if (i + 5 > myPane.XAxis.Max) { myPane.XAxis.Max += 10; axisflag = 0; } if (Data.GetVal(sel1) == 0) { axisflag = 1; } tmpymax = myPane.YAxis.Max; tmpymin = myPane.YAxis.Min; if ((Data.GetVal(sel1) > myPane.YAxis.Max) & axisflag == 0) { myPane.YAxis.Max = (Data.GetVal(sel1) * 1.3); myPane.YAxis.Min = (Data.GetVal(sel1) * 0.4); axisflag = 0; } double res = tmpymax - Data.GetVal(sel1) * 0.2; if (Math.Abs(res) > Data.GetVal(sel1) & axisflag == 0) { myPane.YAxis.Min = (Data.GetVal(sel1) * 0.4); myPane.YAxis.Max = (Data.GetVal(sel1) * 1.3); } }
private void button1_Click_1(object sender, EventArgs e) { GraphPane myPane = zedGraphControl1.GraphPane; PointPairList listPointsTwo = new PointPairList(); string selected = comboBox1.Text; ACOK.SipRegisters sel = EnumDescriptor.ToEnum <ACOK.SipRegisters>(selected); if (selected == "Data1") { Dispdata(sel); //button6_Click(this, null); } if (selected != "Data1") { //if (axisflag == 1) //{ // myPane.YAxis.Max = 40; // myPane.YAxis.Min = 0; // myPane.XAxis.Min = 0; // myPane.XAxis.Max = 50; //} if (i * yscalectrl > myPane.XAxis.Max - 5) { myPane.XAxis.Max = (i + 10); axisflag = 0; } i++; Sipval[(i - 1)] = Data.GetVal(sel); zedGraphControl1.AxisChange(); zedGraphControl1.Refresh(); myPane.ScaledGap(1); Rangscale(sel); myPane.IsFontsScaled = true; PointPairList approx2 = new PointPairList(); if (i > 1) { a = (sumxy * (i - 1) - sumy * sumx) / (sumx2 * (i - 1) - Math.Pow(sumx, 2)); b = (sumy - a * sumx) / (i - 1); for (double x = i - 1; x <= i; x += 0.5) { approx2.Add(x, a1 * x + b1); } } sumx += i; sumy += Data.GetVal(sel); sumx2 += Math.Pow(i, 2); sumxy += i * Data.GetVal(sel); a = (sumxy * i - sumy * sumx) / (sumx2 * i - Math.Pow(sumx, 2)); b = (sumy - a * sumx) / i; PointPairList approx1 = new PointPairList(); approx1.Clear(); for (double x = 1; x <= i; x += 0.5) { approx1.Add(x, a * x + b); } /* * LineItem f1_curve = myPane.AddCurve(null, approx1, Color.Black, SymbolType.None); */ myPane.CurveList.Clear(); for (int u = 0; u < Sipval.Length; u++) { listPointsTwo.Add(u + 1, Sipval[u]); } LineItem myCurveTwo = myPane.AddCurve("real T", listPointsTwo, Color.Black, SymbolType.None); if (i > 2) { bezcurv(Sipval, i); } Array.Resize <double>(ref Sipval, Sipval.Length + 1); //byte[] temBuf = new byte[4]; //int index = 0; //private void COM3_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e) //{ // ////byte[] tempval = new byte[3]; // //int[] tempval = new int[3];// tempval[3]; // //int j = 0; // int count = COM3.BytesToRead; // while (count > 0) // { // byte[] buf = new byte[count]; // COM3.Read(buf, 0, count); // int wrCount = ((temBuf.Length - index) < count) ? count : count; //(temBuf.Length - index); // Array.Copy(buf, 0, temBuf, index, wrCount); // index += wrCount; // if (index >= temBuf.Length) // { // index = 0; // float temp = 0; // try // { // temp = BitConverter.ToSingle(temBuf, 0); // } // catch {} // richTextBox1.Invoke(new Action(() => // { // richTextBox2.Text = string.Format("{0:F3}", temp); ; // })); // } // //tempval[j]= COM3.Read(buf, 0, count); // //richTextBox4.Text += tempval[j]; // //j++; // //if (j > 2) // //{ // // j = 0; // //}; // //string strB = ""; // //for (int i = 0; i < count; i++) // //{ // // strB += string.Format("{0:X2}", buf[i]); // // strB += "\t"; // //} // //richTextBox1.Invoke(new Action(() => // //{ // // richTextBox2.Text += strB; // //})); // count = COM3.BytesToRead; // } // } //private void COM3_ErrorReceived(object sender, System.IO.Ports.SerialErrorReceivedEventArgs e) //{ //} // #endregion // Events //------------------------------------------------------------------------- //button1_Click_1(this, null); } }
//double[] filtval = new double[RegistersCountMax - 257]; //double[] filtval1 = new double[RegistersCountMax - 257]; //double[] filtval2 = new double[RegistersCountMax - 257]; // int upshift = 0; internal void Dispdata(ACOK.SipRegisters sel2) { GraphPane myPane = zedGraphControl1.GraphPane; PointPairList listPoints = new PointPairList(); PointPairList filtpoints = new PointPairList(); PointPairList filtpoints1 = new PointPairList(); PointPairList filtpoints2 = new PointPairList(); //filtval[0] = rdBuf[257]; //filtval2[0] = rdBuf[257]; if (axisflag == 1 & yscalectrl == 1) { myPane.YAxis.Max = 2500; myPane.YAxis.Min = -10; myPane.XAxis.Max = 20; myPane.XAxis.Min = 0; } myPane.CurveList.Clear(); //for(int yr =0; yr<rdBuf.Length; yr++) //{ // rdBuf[yr] /= 13; //} //for (int t = 1; t < RegistersCountMax-258; t++) //{ // filtval[t] =B * (t) + A * rdBuf[t + 257 - 1]; // filtpoints.Add((t)/51.2, filtval[t]/26.2); // filtval1[t] = (rdBuf[t + 257 - 1] + rdBuf[t + 257] + rdBuf[t + 257 + 1])/3; // filtpoints1.Add((t)/51.2, filtval1[t]/26.2); // filtval2[t] = (rdBuf[t+257-1] + rdBuf[t+257]) / 2; // filtpoints2.Add(t/51.2, filtval2[t]/26.2); //} ////double xfilt = 0; ////double yfilt = 0; ////for(int t =0; t < RegistersCountMax-257; t++) ////{ //// for(int j =0; j < t; j++) //// { //// yfilt = yfilt + rdBuf[j + 258-1]; //// xfilt += j; //// } //// xfilt -= t; //// filtpoints2.Add(t, B * xfilt - A * yfilt); ////} //LineItem FiltLine = myPane.AddCurve("Filtered data", filtpoints, Color.Black, SymbolType.None); //LineItem Filtline1 = myPane.AddCurve("Filtered data1", filtpoints1, Color.Blue, SymbolType.None); //LineItem Filtline2 = myPane.AddCurve("Filtered data2", filtpoints2, Color.Green, SymbolType.None); double[] apprBuf = new double[8]; for (int t = 257; t < RegistersCountMax; t++) { if (t < RegistersCountMax - 4 & t > 260) { for (int l = -3; l < 5; l++) { apprBuf[l + 3] = rdBuf[t + l]; } } filtpoints.Add((t - 257) / 51.2, apprBuf.Average() / 26.2); //SIP.SipRegisters trx = t; listPoints.Add((t - 257) / 51.2, rdBuf[t] / 26.2); // approxL[t - 257] = rdBuf[t]; } // bezcurv(approxL, RegistersCountMax - 257); //upshift++; //LineItem midline = myPane.AddCurve(null, cX, cY, Color.Blue, SymbolType.Star); LineItem Dataline = myPane.AddCurve("Data", listPoints, Color.Coral, SymbolType.None); LineItem Filtline = myPane.AddCurve("Averaged data", filtpoints, Color.Black, SymbolType.None); Dataline.Line.Width = 3; zedGraphControl1.Refresh(); zedGraphControl1.AxisChange(); //sleeptime = 1000; }