陈子杰 6 hónapja
szülő
commit
ab4fe6d204

+ 1 - 1
SCADA_DAQ/Customer/Models/DaqSettingModel.cs

@@ -16,7 +16,7 @@ namespace SCADA_DAQ.Customer.Models
         /// </summary>
         /// 
         [AutoViewProperty("采集周期-ms",Icon = "Autorenew")]
-        [Range(50,99999)]
+        [Range(50,1000)]
         public int AcquisitionCycle
         {
             get { return _AcquisitionCycle; }

+ 72 - 18
SCADA_DAQ/Customer/UctFrmMain.xaml.cs

@@ -57,6 +57,8 @@ namespace SCADA_DAQ.Customer
 
         private PoweMeterReuslt poweMeterReuslt { get; set; }
 
+        private System.Timers.Timer _timer = new System.Timers.Timer();
+
         public DateTime StartTime { get; set; }
 
         private bool PumpIsRun = false;
@@ -67,12 +69,17 @@ namespace SCADA_DAQ.Customer
 
         private double CurrentFlow {  get; set; }
 
+        public int SpeedIndex = 0;
+
         /// <summary>
         /// /
         /// </summary>
         public UctFrmMain()
         {
             InitializeComponent();
+            //_timer.Interval = 1000;
+  
+            //_timer.Elapsed += _timer_Elapsed;
             ToolBar.Visibility = Visibility.Collapsed;
             DataToExcel.Columns.Add("Time", typeof(DateTime));
             DataToExcel.Columns.Add("Index");
@@ -91,8 +98,9 @@ namespace SCADA_DAQ.Customer
             DataToExcel.Columns.Add("Pressure3");
             DataToExcel.Columns.Add("Power");
             DataToExcel.Columns.Add("FlowRate");
-            DataToExcel.Columns.Add("RPM");
+            DataToExcel.Columns.Add("FlowSpeed");
             DataToExcel.Columns.Add("Pump");
+
             CustomerEnv.DaqSettingValue.PropertyChanged += DaqSettingValue_PropertyChanged;
             DaqInfo.StartCtrl = new Action(() =>
             {
@@ -101,27 +109,28 @@ namespace SCADA_DAQ.Customer
                     MsChart1.ClearDatas();
                     MsChart2.ClearDatas();
                     ClearFlowToPlc();
+                    _timer.Start();
                     Dispatcher.Invoke(() =>
                     {
                         Check.IsEnabled = false;
 
                     });
                     //MsChart.mainChart.ChartAreas[0].AxisX.po
-                    StartFlag = true;
+                    StartFlag = true;              
                     var startTime = DateTime.Now;
                     double index = 0d;
                     while (StartFlag)
                     {
                         if ((DateTime.Now - startTime).TotalSeconds >= CustomerEnv.DaqSettingValue.TimeOut)
                         {
-                            StartFlag = false;
-                            ExportToExcel();
-                            DataToExcel.Rows.Clear();
+
+                            Stop();
                             Dispatcher.Invoke(() =>
                             {
                                 DaqInfo.StopBtn.IsEnabled = false;
                                 DaqInfo.StartBtn.IsEnabled = true;
                             });
+                           
                             MessageBox.Show("采样时间已超出设定的超时时间,采样已结束!");
                         }
                         else
@@ -136,19 +145,42 @@ namespace SCADA_DAQ.Customer
 
             DaqInfo.EndCtrl = new Action(() =>
             {
-                
+                Stop();
+            });
+            plc3.BaseDevice.RegReadValueChanged += BaseDevice_RegReadValueChanged;
+            //Env.Schedual.DateTimeChanged += Schedual_DateTimeChanged;
+        }
+
+        public void Stop()
+        {
+            //_timer.Stop();
+            SpeedIndex = 0;
+            StartFlag = false;
+            ExportToExcel();
+            DataToExcel.Rows.Clear();
+            CurrentFlow = 0;
+            FlowRate = 0;
+            Dispatcher.Invoke(() =>
+            {
+                Check.IsEnabled = true;
+
+            });
+        }
+
+        private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
+        {
+            if (StartFlag == true && Check.TypeChecks2[3] == true)
+            {
+                var value = plc3.GetListenReg("D20").ScaleValue.Value;
+                FlowRate = value - CurrentFlow; 
+                SpeedIndex++;
+                CurrentFlow = value;
                 Dispatcher.Invoke(() =>
                 {
-                    Check.IsEnabled = true;
-
+                    MsChart2.mainChart.Series[4].Points.AddXY(SpeedIndex, FlowRate);
+                    DataToExcel.Rows[DataToExcel.Rows.Count - 1][17] = FlowRate;
                 });
-                StartFlag = false;
-                FlowRate = 0;
-                ExportToExcel();
-                DataToExcel.Rows.Clear();
-            });
-            plc3.BaseDevice.RegReadValueChanged += BaseDevice_RegReadValueChanged;
-            Env.Schedual.DateTimeChanged += Schedual_DateTimeChanged;
+            }
         }
 
         private void Schedual_DateTimeChanged(object sender, DateTimeChangedArgs e)
@@ -159,7 +191,13 @@ namespace SCADA_DAQ.Customer
                 {
                     var value = plc3.GetListenReg("D20").ScaleValue.Value;
                     FlowRate = value - CurrentFlow;
+                    SpeedIndex++;
                     CurrentFlow = value;
+                    Dispatcher.Invoke(() =>
+                    {
+                        MsChart2.mainChart.Series[4].Points.AddXY(SpeedIndex, FlowRate);
+                        DataToExcel.Rows[DataToExcel.Rows.Count - 1][17] = FlowRate;
+                    });
                 }
             }
         }
@@ -251,7 +289,6 @@ namespace SCADA_DAQ.Customer
                 }
                
             }
-            var a = DateTime.Now - starttime;
 
             for (int i = 0; i < MsChart2.mainChart.Series.Count - 2; i++)
             {
@@ -279,14 +316,28 @@ namespace SCADA_DAQ.Customer
                   
                 rowValue[i + 2 + MsChart1.mainChart.Series.Count] = value;
             }
+            var speedIndex =Math.Round( index,0) % 1.0d;
+
             if (Check.TypeChecks2[3] == true)
             {
                 var value = Math.Round(plc3.GetListenReg("D20").ScaleValue.Value, 1);
                 rowValue[16] = value;
+                rowValue[17] = 0;
+
                 Dispatcher.Invoke(() =>
                 {
                     MsChart2.mainChart.Series[3].Points.AddXY(Math.Round(index, 1), value);
-                    MsChart2.mainChart.Series[4].Points.AddXY(Math.Round(index, 1), FlowRate);
+                    if (speedIndex == 0 && index != 0)
+                    {
+                        var Plcvalue = plc3.GetListenReg("D20").ScaleValue.Value;
+                        FlowRate = Plcvalue - CurrentFlow;
+                        SpeedIndex++;
+                        CurrentFlow = Plcvalue;
+                        MsChart2.mainChart.Series[4].Points.AddXY(index, FlowRate);
+               
+                        DataToExcel.Rows[DataToExcel.Rows.Count - 1][17] = FlowRate;
+
+                    }
 
                 });
             }
@@ -312,7 +363,6 @@ namespace SCADA_DAQ.Customer
                     MsChart2.mainChart.ChartAreas[0].AxisX.ScaleView.Position = 0;
                 }
             });
-            rowValue[16] = 0;
             rowValue[0] = DateTime.Now.Format();
             rowValue[1] = index;
             
@@ -447,7 +497,11 @@ namespace SCADA_DAQ.Customer
         protected override void CloseThis()
         {
             base.CloseThis();
+            //_timer.Stop();
+            //_timer.Dispose();
+            Env.Schedual.DateTimeChanged -= Schedual_DateTimeChanged;
             StartFlag = false;
         }
+
     }
 }

+ 5 - 3
SCADA_DAQ/Customer/Views/Uct/UctMsChart.xaml.cs

@@ -44,7 +44,9 @@ namespace SCADA_DAQ.Customer.Views.Uct
             //宽度和高度为百分比
             ca.Position = new ElementPosition(0f, 0f, 100f, 100f);
             ca.Area3DStyle.Enable3D = false;
-            ca.AxisX.LabelStyle.Format = @"{0:0.00}"; ;
+            //ca.AxisX.LabelStyle.Format = @"{0:0.00}"; ;
+            ca.AxisX.LabelStyle.Format = @"{0:0}";
+
 
             //ca.AxisX.ScaleView.Zoomable = true;
             //ca.AxisX.ScaleView.Position = 0;
@@ -215,7 +217,7 @@ namespace SCADA_DAQ.Customer.Views.Uct
 
 
                 //曲线宽度
-                line.BorderWidth = 2;
+                line.BorderWidth = 1;
 
                 //以哪条Y轴做基准
                 line.YAxisType = AxisType.Primary;
@@ -225,7 +227,7 @@ namespace SCADA_DAQ.Customer.Views.Uct
                 line.IsVisibleInLegend = false;
                 //数据点形状
                 line.MarkerStyle = MarkerStyle.Square;
-                line.MarkerSize = 3;
+                line.MarkerSize = 2;
                 line.ToolTip = "第#VALX秒\n" + strList[i] + ":#VALY";
                 //line.ToolTip =  strList[i] + ":#VALY";
 

+ 6 - 3
SCADA_DAQ/Customer/Views/Uct/UctMsChart1.xaml.cs

@@ -44,7 +44,7 @@ namespace SCADA_DAQ.Customer.Views.Uct
             //宽度和高度为百分比
             ca.Position = new ElementPosition(0f, 0f, 100f, 100f);
             ca.Area3DStyle.Enable3D = false;
-            //ca.AxisX.LabelStyle.Format = @"{0:0.00}"; 
+            ca.AxisX.LabelStyle.Format = @"{0:0}";
 
             //ca.AxisX.ScaleView.Zoomable = true;
             //ca.AxisX.ScaleView.Position = 0;
@@ -72,6 +72,9 @@ namespace SCADA_DAQ.Customer.Views.Uct
             ca.AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.All;
             //ca.AxisX.IntervalOffset = 1.00D;
             ca.AxisX.Minimum = 0;
+            ca.AxisY.Interval = 1;
+            ca.AxisY2.Interval = 5;
+
 
             //ca.AxisX.LabelStyle.IsStaggered = true;
 
@@ -213,7 +216,7 @@ namespace SCADA_DAQ.Customer.Views.Uct
 
 
                 //曲线宽度
-                line.BorderWidth = 2;
+                line.BorderWidth = 1;
 
                 //以哪条Y轴做基准
                 line.YAxisType = AxisType.Primary;
@@ -223,7 +226,7 @@ namespace SCADA_DAQ.Customer.Views.Uct
                 line.IsVisibleInLegend = false;
                 //数据点形状
                 line.MarkerStyle = MarkerStyle.Square;
-                line.MarkerSize = 3;
+                line.MarkerSize = 2;
                 line.ToolTip = "第#VALX秒\n" + strList[i] + ":#VALY";
                 //line.ToolTip =  strList[i] + ":#VALY";