tx
2025-04-09 fa7510e1ed63df0366787fa4ed1b3db6426d2b46
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
using DevExpress.Charts.Native;
using DevExpress.XtraCharts;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
 
namespace TProduct.WinFrmUI.TPump
{
    public partial class FeatTestRealTimeChart : DevExpress.XtraEditors.XtraUserControl
    {
        internal ChartControl ChartControl { get { return chart; } }
        protected TProduct.Model.TestProjectItemView _testItem = null;
        protected Eventech.Model.UnitP power_unit = Eventech.Model.UnitP.KW;
        protected Eventech.Model.UnitQ flow_unit = Eventech.Model.UnitQ.M3H;
        protected Eventech.Model.UnitH head_unit = Eventech.Model.UnitH.M;
        protected Eventech.Model.UnitH press_unit = Eventech.Model.UnitH.MPa;
        public FeatTestRealTimeChart()
        {
            InitializeComponent();
 
            power_unit = TProduct.UserSetting.Setting.PumpTest.UnitPower;
            flow_unit = TProduct.UserSetting.Setting.PumpTest.UnitFlow;
            head_unit = TProduct.UserSetting.Setting.PumpTest.UnitHead;
            press_unit = TProduct.UserSetting.Setting.PumpTest.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 InletPress { get; set; }
            public double OutletPress { get; set; }
            public double WenDu { get; set; }//温度
            public double KaiDu { get; set; }//开度
            internal FeatTestRealTimeItem() { }
            internal FeatTestRealTimeItem(
                DateTime timeStamp,
                double power,
                double flow,
                double inlet_press,
                double outlet_press,
                double wendu,
                double kaidu)
            {
                this.TimeStamp = timeStamp;
                this.Power = power;
                this.Flow = flow;
                this.InletPress = inlet_press;
                this.OutletPress = outlet_press;
                this.WenDu = wendu;
                this.KaiDu = kaidu;
            }
        }
 
 
        private void RealTimeChart_Load(object sender, EventArgs e)
        {
 
        }
        void Chart_CustomPaint(object sender, CustomPaintEventArgs e)
        {
 
        }
        TProduct.Model.WorkBenchMonitorPoint _monitorPoint进口压力 = null;
        TProduct.Model.WorkBenchMonitorPoint _monitorPoint出口压力 = null;
        TProduct.Model.WorkBenchMonitorPoint _monitorPoint流量 = null;
        TProduct.Model.WorkBenchMonitorPoint _monitorPoint功率 = null;
        TProduct.Model.WorkBenchMonitorPoint _monitorPoint温度 = null;
        TProduct.Model.WorkBenchMonitorPoint _monitorPoint开度 = null;
 
        MonitorValveIngRecordHelper _monitorValveIngRecordHelper = null;
 
        private bool isShowPress = true;
        private bool isShowWenDu = true;
        //private bool isShowPower = true;
        private bool isShowKaiDu = true;
 
        internal bool SetBindingData(
            List<TProduct.Model.WorkBenchMonitorPoint> monitorPoints,
            MonitorValveIngRecordHelper monitorValveIngRecordHelper)
        {
            _dataSouce = new ObservableCollection<FeatTestRealTimeItem>();
            chart.DataSource = _dataSouce;
 
            var diagram = this.chart.Diagram as SwiftPlotDiagram;
 
 
            _monitorPoint进口压力 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.压力 &&
             x.Property == Model.MonitorTypeProperty.进口);
            _monitorPoint出口压力 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.压力 &&
             x.Property == Model.MonitorTypeProperty.出口);
            
            if(_monitorPoint进口压力==null|| _monitorPoint进口压力.DispInRealChart != 1)
            {
                this.chart.Series["SeriesInletPress"].Visible = false;
                isShowPress = false;
            }
            else
            {
                isShowPress = true ;
            }
            if (_monitorPoint出口压力 == null || _monitorPoint出口压力.DispInRealChart != 1)
            {
                this.chart.Series["SeriesOutletPress"].Visible = false;
                isShowPress = false;
            }
            else
            {
                isShowPress = true;
            }
            if (isShowPress == false)
            {
                diagram.Panes[1].Visibility = ChartElementVisibility.Hidden;
                diagram.SecondaryAxesY["AxisPress"].Visibility = DevExpress.Utils.DefaultBoolean.False;
            }
 
            _monitorPoint流量 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.流量); 
            _monitorPoint功率 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.功率); 
            _monitorPoint温度 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.介质温度 );
            if(_monitorPoint温度 == null || _monitorPoint温度.DispInRealChart != 1)
            {
                isShowWenDu = false;
                diagram.SecondaryAxesY["AxisWendu"].Visibility = DevExpress.Utils.DefaultBoolean.False;
                this.chart.Series["SeriesWendu"].Visible = false;
            }
            else
            {
                isShowWenDu = true ;
            }
             
            
            _monitorPoint开度 = monitorPoints.Find(x => x.MonitorType == Model.eMonitorType.阀门开度);
            if (_monitorPoint开度 == null || _monitorPoint开度.DispInRealChart != 1)
            {
                isShowWenDu = false;
                diagram.SecondaryAxesY["AxisKaidu"].Visibility = DevExpress.Utils.DefaultBoolean.False;
                this.chart.Series["SeriesKaidu"].Visible = false;
            }
            else
            {
                isShowKaiDu = true;
            }
             
            this._monitorValveIngRecordHelper = monitorValveIngRecordHelper;
 
            return true;
        }
         
        ObservableCollection<FeatTestRealTimeItem> _dataSouce = null; 
        System.Windows.Forms.Timer synchronousTimer;
        public void Start()
        {
            if (synchronousTimer != null)
                synchronousTimer.Stop();
            MaxDataPointsCount = TProduct.UserSetting.Setting.PumpTest.RealTimeChartMaxPtCount;
            if (MaxDataPointsCount < 100)
                MaxDataPointsCount = 200;
            synchronousTimer = new System.Windows.Forms.Timer();
            synchronousTimer.Interval = 1500;
            synchronousTimer.Tick += new System.EventHandler(this.synchronousTimer_Tick);
            synchronousTimer.Enabled = false;
            synchronousTimer.Start();
             
        }
          int MaxDataPointsCount = 3600; 
        
        void synchronousTimer_Tick(object sender, EventArgs e)
        {
            var value_list = this._monitorValveIngRecordHelper.GetRealValueList();
            FeatTestRealTimeItem point = new FeatTestRealTimeItem();
            point.TimeStamp = DateTime.Now;
            if (_monitorPoint进口压力 != null)
            {
                var v进口压力 = value_list.Find(x => x.ID == this._monitorPoint进口压力.ID);
                if (v进口压力 != null && v进口压力.Value != null)
                    point.InletPress = 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.OutletPress = 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.Power = Eventech.Common.UnitPHelper.fromKW(this.power_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);
            }
            if( _monitorPoint温度 != null && this.isShowWenDu)
            {
                var v温度 = value_list.Find(x => x.ID == this._monitorPoint温度.ID);
                if (v温度 != null && v温度.Value != null)
                    point.WenDu =  v温度.Value.Value ;
            }
            if (_monitorPoint开度 != null && this.isShowKaiDu)
            {
                var v开度 = value_list.Find(x => x.ID == this._monitorPoint开度.ID);
                if (v开度 != null && v开度.Value != null)
                    point.KaiDu  = v开度.Value.Value;
            } 
            {
                _dataSouce.Add(point); 
                if (_dataSouce.Count > MaxDataPointsCount)
                    _dataSouce.RemoveAt(0); 
            }
          
        }
        public void Stop()
        {
            if (synchronousTimer != null)
            {
                synchronousTimer.Stop();
                synchronousTimer = null;
            } 
        }
 
        private void 清空ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _dataSouce.Clear();
        }
    }
}