tx
2025-04-10 2538101febc78f525945da72c7cdcb2589f9e6ea
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
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();
        }
    }
}