void DrawData() { plot.Model.Axes[0].Minimum = double.NaN; plot.Model.Axes[0].Maximum = double.NaN; for (int valueIndex = 0; valueIndex < ValuesCount; valueIndex++) { if (DataStructureList[valueIndex].EnablePlot == false) { dataSeries[valueIndex].Points.Clear(); continue; } dataSeries[valueIndex].Points.Clear(); for (int i = 0; i < DataItemsCount; i++) { double y = ProcessedData[valueIndex, i]; dataSeries[valueIndex].Points.Add(new DataPoint(i, y)); } } plot.Refresh(); }
protected override void OnResize(EventArgs e) { base.OnResize(e); if (mPlot == null) { return; } mPlot.Height = panel1.Height; mPlot.Width = panel1.Width; mPlot.Refresh(); }
private void timer1_Tick(object sender, EventArgs e) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL + "pressure"); request.Timeout = 300; request.ContentType = "application/json; charset=utf-8"; try { HttpWebResponse response = request.GetResponse() as HttpWebResponse; using (Stream responseStream = response.GetResponseStream()) { StreamReader reader = new StreamReader(responseStream, Encoding.UTF8); String data = reader.ReadToEnd(); response.Close(); Console.WriteLine(data); try { PressureReading psr = JsonConvert.DeserializeObject <PressureReading>(data); mmin = Math.Min((double)mmin, (double)psr.pressure); mmax = Math.Max((double)mmax, (double)psr.pressure); model.DefaultYAxis.Zoom(mmin - 0.05 * Math.Abs(mmin), mmax + 0.05 * Math.Abs(mmax)); ss.Points.Add(new DataPoint(ttt, psr.pressure)); ttt++; if (ttt > 90) { double panStep = model.DefaultXAxis.Transform(-1 + model.DefaultXAxis.Offset); model.DefaultXAxis.Pan(panStep); } myPlot.Refresh(); } catch (Exception ex) { } } } catch (Exception ex) { } }
private void DrawScope() { if (!Controls.Contains(Scope)) { Scope.Location = new Point(30, 180); Scope.Size = new Size(900, 470); Controls.Add(Scope); } PlotModel Model = new PlotModel { Title = "", DefaultFont = afont, DefaultFontSize = fontsize, LegendTitle = "", PlotType = PlotType.XY, TitleFont = afont, Culture = System.Globalization.CultureInfo.CurrentCulture, LegendSymbolLength = 24, Padding = new OxyThickness(0, 20, 30, 0) }; Model.InvalidatePlot(true); Scope.Model = Model; LinearAxis YAxis = new LinearAxis { Position = AxisPosition.Left, Minimum = -20, Maximum = 20, MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot, Title = "Điện áp (V)", MajorStep = 4, Font = afont, FontSize = fontsize, LabelFormatter = _formatter }; LinearAxis XAxis = new LinearAxis { Position = AxisPosition.Bottom, Minimum = 0, Maximum = 400, MajorGridlineStyle = LineStyle.Solid, MinorGridlineStyle = LineStyle.Dot, Title = "Thời gian (µs) ", MajorStep = 50, Font = afont, FontSize = fontsize, LabelFormatter = _time_formatter }; Scope.Model.Axes.Add(XAxis); Scope.Model.Axes.Add(YAxis); //Timer 32bit, 100MHz, 50 MIPS, 2*(10^-8) sec/step,2*(10^-8)*50 = 1 µs if (TimerValue > 0) { double TimeRange = TimerValue * Math.Pow(10, 6) * TimerStep; //Micro Second step = TimeRange / SampleCount; //Micro Second for (int dt = 0; dt < SampleCount; dt++) { try { ChannelAVoltage[dt] = CalculateVoltage(ChannelA[dt], CHAX, GainA, CHAOffset, ErrA); ChannelBVoltage[dt] = CalculateVoltage(ChannelB[dt], CHBX, GainB, CHBOffset, ErrB); } catch (Exception e) { TextBoxRawData.Text = e.Message + " Voltage\r\n"; } } double MaxA = ChannelAVoltage.Max(); double MinA = ChannelAVoltage.Min(); double MaxB = ChannelBVoltage.Max(); double MinB = ChannelBVoltage.Min(); double MidA = (MaxA + MinA) / 2; double MidB = (MaxB + MinB) / 2; if (ToggleA.Checked == true) { LabelMaxAV.Text = String.Format("{0:0.00}V", ChannelAVoltage.Max()); LabelMinAV.Text = String.Format("{0:0.00}V", ChannelAVoltage.Min()); } if (ToggleB.Checked == true) { LabelMaxBV.Text = String.Format("{0:0.00}V", ChannelBVoltage.Max()); LabelMinBV.Text = String.Format("{0:0.00}V", ChannelBVoltage.Min()); } double MaxY = Math.Max(MaxA, MaxB); if (MaxY == 0) { MaxY = 20; } MaxY = Math.Abs(Math.Min(MinA, MinB)) > MaxY?Math.Abs(Math.Min(MinA, MinB)) + Math.Abs(Math.Min(MinA, MinB)) : MaxY + MaxY; if (CheckBoxAUP.Checked || CheckBoxBUP.Checked) { MaxY = 3 * MaxY; } double MinY = -MaxY; CalculateFreqAndRMS(); double FmaxA = 0, FmaxB = 0; double Fmax = 0; double Fzmax = 0; if (ka == true) { double[] DemA = new double[inpA.Length]; for (int i = 0; i < inpA.Length; i++) { DemA[i] = Complex.Abs(inpA[i]) / 10; } FmaxA = DemA.Max(); } if (kb == true) { double[] DemB = new double[inpB.Length]; for (int i = 0; i < inpB.Length; i++) { DemB[i] = Complex.Abs(inpB[i]) / 10; } FmaxB = DemB.Max(); } if (FmaxA > FmaxB) { Fmax = FmaxA; } else { Fmax = FmaxB; } if (ka == true && kb == false) { Fzmax = FreqA; } else if (ka == false && kb == true) { Fzmax = FreqB; } else if (ka == true && kb == true) { if (FreqA > FreqB) { Fzmax = FreqA; } else { Fzmax = FreqB; } } if (Kaaaaa == true) { YAxis.Maximum = Fmax; YAxis.Minimum = 0; YAxis.MajorStep = Fmax / 5; YAxis.Title = "Biên Độ (V)"; XAxis.Minimum = 0; XAxis.Maximum = Fzmax; XAxis.MajorStep = Fzmax / 12; XAxis.Title = "Tầng Số (Hz)"; XAxis.LabelFormatter = _time_formatter1; } else { YAxis.Maximum = MaxY; YAxis.Minimum = MinY; YAxis.MajorStep = MaxY / 5; XAxis.Minimum = 0; XAxis.Maximum = TimeRange; XAxis.MajorStep = TimeRange / 12; } var CHA = new LineSeries { Color = OxyColors.Blue, MarkerType = MarkerType.None, MarkerSize = 1, MarkerStroke = OxyColors.White, MarkerFill = OxyColors.Black, MarkerStrokeThickness = 1, LineStyle = LineStyle.Solid, Smooth = false, StrokeThickness = 1, Title = "KÊNH A", TrackerFormatString = "{0}\n{1}: {2:0.00}\n{3}: {4:0.00}" }; var CHB = new LineSeries { Color = OxyColors.Red, MarkerType = MarkerType.None, MarkerSize = 1, MarkerStroke = OxyColors.White, MarkerFill = OxyColors.Teal, MarkerStrokeThickness = 1, LineStyle = LineStyle.Solid, Smooth = false, StrokeThickness = 1, Title = "KÊNH B", TrackerFormatString = "{0}\n{1}: {2:0.00}\n{3}: {4:0.00}" }; if (Kaaaaa == false) { for (int dt = 0; dt < SampleCount; dt++) { if ((MinA >= 0) && (CheckBoxGNDA.Checked == true)) { ChannelAVoltage[dt] = ChannelAVoltage[dt] - MinA; } if ((MinB >= 0) && (CheckBoxGNDB.Checked == true)) { ChannelBVoltage[dt] = ChannelBVoltage[dt] - MinB; } try { if (CheckBoxAUP.Checked) { CHA.Points.Add(new DataPoint(step * dt, ChannelAVoltage[dt] + 3 * MaxB)); CHB.Points.Add(new DataPoint(step * dt, ChannelBVoltage[dt])); } else if (CheckBoxBUP.Checked) { CHA.Points.Add(new DataPoint(step * dt, ChannelAVoltage[dt])); CHB.Points.Add(new DataPoint(step * dt, ChannelBVoltage[dt] + 3 * MaxA)); } else { CHA.Points.Add(new DataPoint(step * dt, ChannelAVoltage[dt])); CHB.Points.Add(new DataPoint(step * dt, ChannelBVoltage[dt])); } } catch (Exception e) { TextBoxRawData.AppendText(e.Message + "Points"); } } } else { if (ka == true) { for (int i = 0; i < inpA.Length; i++) { CHA.Points.Add(new DataPoint(FreqA * i / inpA.Length, Complex.Abs(inpA[i]) / 10)); } } if (kb == true) { for (int i = 0; i < inpB.Length; i++) { CHB.Points.Add(new DataPoint(FreqB * i / inpB.Length, Complex.Abs(inpB[i]) / 10)); } } } if (ToggleA.Checked == true) { Scope.Model.Series.Add(CHA); } if (ToggleB.Checked == true) { Scope.Model.Series.Add(CHB); } CalculateFreqAndRMS(); Scope.Update(); Scope.Refresh(); } }