using DevExpress.XtraCharts;
|
using System;
|
using System.Collections.Generic;
|
using System.Collections.ObjectModel;
|
|
namespace TProduct.WinFrmUI.TValve
|
{
|
public partial class FeatTestRealTimeChart : DevExpress.XtraEditors.XtraUserControl
|
{
|
internal ChartControl ChartControl { get { return chart; } }
|
protected TProduct.Model.TestProjectItemView _testItem = null;
|
|
protected Eventech.Model.UnitQ flow_unit = Eventech.Model.UnitQ.M3H;
|
protected Eventech.Model.UnitH press_unit = Eventech.Model.UnitH.KPa;
|
public FeatTestRealTimeChart()
|
{
|
InitializeComponent();
|
|
flow_unit = TProduct.UserSetting.Setting.ValveTest.UnitFlow;
|
press_unit = TProduct.UserSetting.Setting.ValveTest.UnitPress;
|
|
//ChartControl.BeginInit();
|
//dataGenerator = new SensorDataGenerator();
|
//dataGenerator.GenerateInitialData();
|
//ChartControl.DataSource = dataGenerator.DataSource;
|
//ColorizeSeries();
|
//dataGenerator.Start();
|
//this.synchronousTimer = new System.Windows.Forms.Timer(this.components);
|
//this.synchronousTimer.Interval = 15;
|
//this.synchronousTimer.Tick += new System.EventHandler(this.synchronousTimer_Tick);
|
////
|
//synchronousTimer.Enabled = true;
|
//ChartControl.EndInit();
|
//SwiftPlotDiagramAxisX axisX = ((SwiftPlotDiagram)ChartControl.Diagram).AxisX;
|
//axisX.VisualRange.SetMinMaxValues((DateTime)axisX.WholeRange.MaxValue - new TimeSpan(0, 0, 10), ((DateTime)axisX.WholeRange.MaxValue).AddSeconds(1));
|
}
|
|
public class FeatTestRealTimeItem
|
{
|
public DateTime TimeStamp { get; set; }
|
public double Power { get; set; }
|
public double Flow { get; set; }
|
public double P1 { get; set; }
|
public double P2 { get; set; }
|
public double P3 { get; set; }
|
internal FeatTestRealTimeItem() { }
|
internal FeatTestRealTimeItem(
|
DateTime timeStamp,
|
double flow,
|
double p1,
|
double p2,
|
double p3)
|
{
|
this.TimeStamp = timeStamp;
|
|
this.Flow = flow;
|
this.P1 = p1;
|
this.P2 = p2;
|
this.P3 = p3;
|
}
|
}
|
|
|
private void RealTimeChart_Load(object sender, EventArgs e)
|
{
|
|
}
|
void Chart_CustomPaint(object sender, CustomPaintEventArgs e)
|
{
|
|
}
|
TProduct.Model.WorkBenchMonitorPoint _monitorPointP1 = null;
|
TProduct.Model.WorkBenchMonitorPoint _monitorPointP2 = null;
|
TProduct.Model.WorkBenchMonitorPoint _monitorPointP3 = null;
|
TProduct.Model.WorkBenchMonitorPoint _monitorPoint流量 = null;
|
|
MonitorValveIngRecordHelper _monitorValveIngRecordHelper = null;
|
|
internal void SetBindingData(
|
List<TProduct.Model.WorkBenchMonitorPoint> monitorPoints,
|
MonitorValveIngRecordHelper monitorValveIngRecordHelper)
|
{
|
_dataSouce = new ObservableCollection<FeatTestRealTimeItem>();
|
chart.DataSource = _dataSouce;
|
|
_monitorPointP1 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.压力 &&
|
x.Property == TProduct.Model.MonitorTypeProperty.P1);
|
_monitorPointP2 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.压力 &&
|
x.Property == TProduct.Model.MonitorTypeProperty.P2);
|
_monitorPointP3 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.压力 &&
|
x.Property == TProduct.Model.MonitorTypeProperty.P3);
|
|
_monitorPoint流量 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.流量);
|
|
this._monitorValveIngRecordHelper = monitorValveIngRecordHelper;
|
}
|
ObservableCollection<FeatTestRealTimeItem> _dataSouce = null;
|
//FeatTestRealTimeGenerator dataGenerator;
|
System.Windows.Forms.Timer synchronousTimer;
|
public void Start()
|
{
|
if (synchronousTimer != null)
|
synchronousTimer.Stop();
|
|
synchronousTimer = new System.Windows.Forms.Timer();
|
synchronousTimer.Interval = 1500;
|
synchronousTimer.Tick += new System.EventHandler(this.synchronousTimer_Tick);
|
synchronousTimer.Enabled = false;
|
synchronousTimer.Start();
|
|
//dataGenerator.GenerateInitialData();
|
//dataGenerator.Start();
|
}
|
const int MaxDataPointsCount = 60 * 60;
|
//readonly object sync = new object();
|
void synchronousTimer_Tick(object sender, EventArgs e)
|
{
|
var value_list = this._monitorValveIngRecordHelper.GetRealValueList();
|
FeatTestRealTimeItem point = new FeatTestRealTimeItem();
|
point.TimeStamp = DateTime.Now;
|
if (_monitorPointP1 != null)
|
{
|
var v压力 = value_list.Find(x => x.ID == this._monitorPointP1.ID);
|
if (v压力 != null && v压力.Value != null)
|
point.P1 = Eventech.Common.UnitHHelper.fromMPa(this.press_unit,
|
v压力.Value.Value);
|
}
|
if (_monitorPointP2 != null)
|
{
|
var v压力 = value_list.Find(x => x.ID == this._monitorPointP2.ID);
|
if (v压力 != null && v压力.Value != null)
|
point.P2 = Eventech.Common.UnitHHelper.fromMPa(this.press_unit,
|
v压力.Value.Value);
|
}
|
if (_monitorPointP3 != null)
|
{
|
var v压力 = value_list.Find(x => x.ID == this._monitorPointP3.ID);
|
if (v压力 != null && v压力.Value != null)
|
point.P3 = Eventech.Common.UnitHHelper.fromMPa(this.press_unit,
|
v压力.Value.Value);
|
}
|
|
if (_monitorPoint流量 != null)
|
{
|
var v流量 = value_list.Find(x => x.ID == this._monitorPoint流量.ID);
|
if (v流量 != null && v流量.Value != null)
|
point.Flow = Eventech.Common.UnitQHelper.fromM3H(this.flow_unit,
|
v流量.Value.Value);
|
}
|
// lock (sync)
|
{
|
_dataSouce.Add(point);
|
//if(_dataSouce.Count() == 10)
|
//{
|
// // SwiftPlotDiagramAxisX axisX = ((SwiftPlotDiagram)chart.Diagram).AxisX;
|
// //axisX.VisualRange.SetMinMaxValues((DateTime)axisX.WholeRange.MaxValue - new TimeSpan(0, 0, 10), ((DateTime)axisX.WholeRange.MaxValue).AddSeconds(1));
|
// // axisX.VisualRange.SetMinMaxValues(DateTime.Now - new TimeSpan(0, 0, 15), DateTime.Now.AddSeconds(2));
|
|
//}
|
if (_dataSouce.Count > MaxDataPointsCount)
|
_dataSouce.RemoveAt(0);
|
//buffer.Clear();
|
//buffer.Add(point);
|
}
|
// if (dataGenerator != null)
|
// dataGenerator.UpdateDataSource();
|
}
|
public void Stop()
|
{
|
if (synchronousTimer != null)
|
{
|
synchronousTimer.Stop();
|
synchronousTimer = null;
|
}
|
}
|
|
private void 清空ToolStripMenuItem_Click(object sender, EventArgs e)
|
{
|
_dataSouce.Clear();
|
}
|
}
|
}
|