Browse Source

增加图表显示

陈子杰 2 months ago
parent
commit
881fcc4d4a

BIN
SCADA_DAQ/Customer/Doc/例程.png


+ 3 - 1
SCADA_DAQ/Customer/Service/CustomerService.cs

@@ -1,7 +1,9 @@
 using SCADA.CommonLib;
 using SCADA.CommonLib.Service;
+using SCADA_DAQ.Customer.ART;
 using System;
 using System.ComponentModel;
+using static SCADA_DAQ.Customer.ART.USB5621AE;
 
 namespace SCADA_DAQ.Customer.Service
 {
@@ -52,7 +54,7 @@ namespace SCADA_DAQ.Customer.Service
         {
             if (IsRunning) { return false; }
             RpcService.GetInstance().Regiseter(this);   //将服务中方法注册到RPC服务器,可以给WebApi调用
-
+            
             return base.Start();
         }
 

+ 23 - 2
SCADA_DAQ/Customer/UctFrmMain.xaml

@@ -7,8 +7,29 @@
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:SCADA_DAQ.Customer"
              mc:Ignorable="d" 
-             xmlns:annHelper="clr-namespace:SCADA.CommonCtrl.AnimationHelper;assembly=SCADA.CommonCtrl"
-             d:DesignHeight="450" d:DesignWidth="800">
+             xmlns:annHelper="clr-namespace:SCADA.CommonCtrl.AnimationHelper;assembly=SCADA.CommonCtrl" 
+    xmlns:uct="clr-namespace:SCADA_DAQ.Customer.Views.Uct"
+    d:DesignHeight="450" d:DesignWidth="800">
     <Grid>
+        <Grid.ColumnDefinitions>
+            <ColumnDefinition Width="5*"/>
+            <ColumnDefinition/>
+        </Grid.ColumnDefinitions>
+        <uct:UctMsChart x:Name="DataChart"/>
+        <Grid Grid.Column="1">
+            <StackPanel VerticalAlignment="Bottom">
+                <StackPanel.Resources>
+                    <Style TargetType="wpfcontrol:IconButton">
+                        <Setter Property="Margin" Value="5"/>
+                        <Setter Property="FontWeight" Value="Bold"/>
+                        <Setter Property="Width" Value="230"/>
+                        <Setter Property="FontSize" Value="28"/>
+                    </Style>
+                </StackPanel.Resources>
+                <wpfcontrol:IconButton ButtonKind="EthernetButton" Title="连接采集模块" Click="IconButton_Click"/>
+                <wpfcontrol:IconButton ButtonKind="StartButton" Title="开始采集" x:Name="StartBtn" IsEnabled="False" Click="IconButton_Click_1"/>
+                <wpfcontrol:IconButton ButtonKind="StopButton" Title="结束采集" x:Name="StopBtn" IsEnabled="False" Click="IconButton_Click_2"/>
+            </StackPanel>
+        </Grid>
     </Grid>
 </wpfcontrol:BaseUctFrm>

+ 298 - 3
SCADA_DAQ/Customer/UctFrmMain.xaml.cs

@@ -1,4 +1,5 @@
 using NPOI.XSSF.UserModel;
+using SCADA;
 using SCADA.CommonCtrl;
 using SCADA.CommonCtrl.AnimationHelper;
 using SCADA.CommonCtrl.WpfControl;
@@ -6,11 +7,15 @@ using SCADA.CommonLib.Data.DIL;
 using SCADA.CommonLib.Data.DIL.MSSql;
 using SCADA.CommonLib.Data.DIL.MySql;
 using SCADA.CommonLib.Data.DIL.Oracle;
+using SCADA.CommonLib.Helper;
 using SCADA_DAQ.Customer.ART;
+using SCADA_DAQ.Customer.Service;
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using System.Threading;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Media.Animation;
@@ -24,15 +29,305 @@ namespace SCADA_DAQ.Customer
     [UctMenu("主页", Icon = "主页")]
     public partial class UctFrmMain : BaseUctFrm
     {
+        /// <summary>
+        /// 连接句柄
+        /// </summary>
+        private IntPtr hDevice;
+
+        public static USB5621AE_AI_PARAM AIParam;
+
+        private bool IsRunning { get; set; }
+
+        UInt16[] nBinArray = new UInt16[32768];
+        UInt32 nReadSampsPerChan = 1024;
+        UInt32 nSampsPerChanRead = 0;
+        UInt32 nReadableSamps = 0;
+        double fTimeout = 10.0;
+
         /// <summary>
         /// /
         /// </summary>
         public UctFrmMain()
         {
             InitializeComponent();
-            var ptr = USB5621AE.USB5621AE_DEV_CreateA("192.168.1.4", 5, 5);
-            var info = new DEVICE_NET_INFO_A();
-            var res = USB5621AE.USB5621AE_GetNetCfgA(ptr, ref info);
+            ToolBar.Visibility = Visibility.Collapsed;
+            SetAIParams();
+            //for (int i = 0; i < 50; i++)
+            //{
+            //    DataChart.mainChart.Series[0].Points.Add(RandomHelper.Next(0, 100));
+            //}
+        }
+
+        private void IconButton_Click(object sender, RoutedEventArgs e)
+        {
+            hDevice = USB5621AE_DEV_CreateA("192.168.1.4", 10, 10);
+            if (hDevice == (IntPtr)(-1))
+            {
+                //Console.WriteLine("USB5621AE_DEV_Create Error");
+                Log.Error("创建设备链接失败!");
+                return; // 如果创建设备对象失败,则返回
+            }
+            else
+            {
+                if (!USB5621AE_AI_VerifyParam(hDevice, ref AIParam))
+                {
+                    Log.Info("参数有误,已被调整为合法值");
+                }
+                StartBtn.IsEnabled = true;
+                StopBtn.IsEnabled = true;
+            }
+            //var info = new DEVICE_NET_INFO_A();
+            //var res = USB5621AE_GetNetCfgA(hDevice, ref info);
+        }
+
+        protected override void CloseThis()
+        {
+            StopTask();
+            if (hDevice != (IntPtr)0)
+            {
+                USB5621AE_DEV_Release(hDevice);
+
+            }
+            base.CloseThis();
+        }
+
+        private void SetAIParams()
+        {
+            // 通道参数
+            AIParam.nSampChanCount = 4;
+
+            AIParam.CHParam0.nChannel = 0;
+            AIParam.CHParam0.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam0.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam0.nReserved0 = 0;
+            AIParam.CHParam0.nReserved1 = 0;
+            AIParam.CHParam0.nReserved2 = 0;
+
+            AIParam.CHParam1.nChannel = 1;
+            AIParam.CHParam1.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam1.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam1.nReserved0 = 0;
+            AIParam.CHParam1.nReserved1 = 0;
+            AIParam.CHParam1.nReserved2 = 0;
+
+            AIParam.CHParam2.nChannel = 2;
+            AIParam.CHParam2.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam2.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam2.nReserved0 = 0;
+            AIParam.CHParam2.nReserved1 = 0;
+            AIParam.CHParam2.nReserved2 = 0;
+
+            AIParam.CHParam3.nChannel = 3;
+            AIParam.CHParam3.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam3.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam3.nReserved0 = 0;
+            AIParam.CHParam3.nReserved1 = 0;
+            AIParam.CHParam3.nReserved2 = 0;
+
+            AIParam.CHParam4.nChannel = 4;
+            AIParam.CHParam4.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam4.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam4.nReserved0 = 0;
+            AIParam.CHParam4.nReserved1 = 0;
+            AIParam.CHParam4.nReserved2 = 0;
+
+            AIParam.CHParam5.nChannel = 5;
+            AIParam.CHParam5.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam5.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam5.nReserved0 = 0;
+            AIParam.CHParam5.nReserved1 = 0;
+            AIParam.CHParam5.nReserved2 = 0;
+
+            AIParam.CHParam6.nChannel = 6;
+            AIParam.CHParam6.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam6.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam6.nReserved0 = 0;
+            AIParam.CHParam6.nReserved1 = 0;
+            AIParam.CHParam6.nReserved2 = 0;
+
+            AIParam.CHParam7.nChannel = 7;
+            AIParam.CHParam7.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam7.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam7.nReserved0 = 0;
+            AIParam.CHParam7.nReserved1 = 0;
+            AIParam.CHParam7.nReserved2 = 0;
+
+            AIParam.CHParam8.nChannel = 8;
+            AIParam.CHParam8.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam8.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam8.nReserved0 = 0;
+            AIParam.CHParam8.nReserved1 = 0;
+            AIParam.CHParam8.nReserved2 = 0;
+
+            AIParam.CHParam9.nChannel = 9;
+            AIParam.CHParam9.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam9.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam9.nReserved0 = 0;
+            AIParam.CHParam9.nReserved1 = 0;
+            AIParam.CHParam9.nReserved2 = 0;
+
+            AIParam.CHParam10.nChannel = 10;
+            AIParam.CHParam10.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam10.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam10.nReserved0 = 0;
+            AIParam.CHParam10.nReserved1 = 0;
+            AIParam.CHParam10.nReserved2 = 0;
+
+            AIParam.CHParam11.nChannel = 11;
+            AIParam.CHParam11.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam11.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam11.nReserved0 = 0;
+            AIParam.CHParam11.nReserved1 = 0;
+            AIParam.CHParam11.nReserved2 = 0;
+
+            AIParam.CHParam12.nChannel = 12;
+            AIParam.CHParam12.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam12.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam12.nReserved0 = 0;
+            AIParam.CHParam12.nReserved1 = 0;
+            AIParam.CHParam12.nReserved2 = 0;
+
+            AIParam.CHParam13.nChannel = 13;
+            AIParam.CHParam13.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam13.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam13.nReserved0 = 0;
+            AIParam.CHParam13.nReserved1 = 0;
+            AIParam.CHParam13.nReserved2 = 0;
+
+            AIParam.CHParam14.nChannel = 14;
+            AIParam.CHParam14.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam14.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam14.nReserved0 = 0;
+            AIParam.CHParam14.nReserved1 = 0;
+            AIParam.CHParam14.nReserved2 = 0;
+
+            AIParam.CHParam15.nChannel = 15;
+            AIParam.CHParam15.nSampleGain = USB5621AE.USB5621AE_AI_SAMPGAIN_1MULT;
+            AIParam.CHParam15.nRefGround = USB5621AE.USB5621AE_AI_REFGND_RSE;
+            AIParam.CHParam15.nReserved0 = 0;
+            AIParam.CHParam15.nReserved1 = 0;
+            AIParam.CHParam15.nReserved2 = 0;
+
+            AIParam.nReserved0 = 0;
+            AIParam.nReserved1 = 0;
+
+            AIParam.nChanScanMode = USB5621AE.USB5621AE_AI_CHAN_SCANMODE_CONTINUOUS;
+            AIParam.nGroupLoops = 1;
+            AIParam.nGroupInterval = 1;
+            AIParam.nSampleSignal = USB5621AE.USB5621AE_AI_SAMPSIGNAL_AI;
+            AIParam.nSampleRange = USB5621AE.USB5621AE_AI_SAMPRANGE_0_P10V;
+
+            // 时钟参数
+            AIParam.nSampleMode = USB5621AE.USB5621AE_AI_SAMPMODE_CONTINUOUS;
+            //缓存点数
+            AIParam.nSampsPerChan = 1024;
+            //采集间隔
+            AIParam.fSampleRate = 10000.0;
+            AIParam.nClockSource = USB5621AE.USB5621AE_AI_CLKSRC_LOCAL;
+            AIParam.bClockOutput = 0;
+
+
+            // 开始触发参数
+            AIParam.bDTriggerEn = 1;
+            AIParam.nDTriggerDir = USB5621AE.USB5621AE_AI_TRIGDIR_FALLING;
+            AIParam.bATriggerEn = 1;
+            AIParam.nATriggerDir = USB5621AE.USB5621AE_AI_TRIGDIR_FALLING;
+            AIParam.fTriggerLevel = 0;
+            AIParam.nTriggerSens = 5;
+
+
+            // 其他参数
+            AIParam.nReserved1 = 0;
+            AIParam.nReserved2 = 0;
+            AIParam.nReserved3 = 0;
+        }
+
+        private void StopTask()
+        {
+            IsRunning = false;
+            // 第六步 停止AI采集任务
+            if (!USB5621AE_AI_StopTask(hDevice))
+            {
+                Log.Error("停止采集任务失败!\n");
+ 
+            }
+
+            // 第七步 释放AI采集任务
+            if (!USB5621AE_AI_ReleaseTask(hDevice))
+            {
+                Log.Error("释放采集任务失败!\n");
+            }
+        }
+
+        private void IconButton_Click_1(object sender, RoutedEventArgs e)
+        {
+            foreach (var item in DataChart.mainChart.Series)
+            {
+                item.Points.Clear();
+            }
+            // 第二步 初始化AI采集任务
+            if (!USB5621AE_AI_InitTask(hDevice, ref AIParam, (IntPtr)null))
+            {
+                Log.Error("初始化采集任务失败!\n");
+                return;
+
+            }
+
+            // 第三步 开始AI采集任务
+            if (!USB5621AE_AI_StartTask(hDevice))
+            {
+                Log.Error("开始采集任务失败!\n");
+                return;
+            }
+
+            // 第四步 发送软件触发事件(硬件外触发时不需要)
+            if (!USB5621AE_AI_SendSoftTrig(hDevice))
+            {
+                Console.WriteLine("发送软件触发事件失败!\n");
+                return;
+
+            }
+            IsRunning = true;
+
+            Task.Run(() =>
+            {
+                // 第五步 循环读取AI数据
+                while (IsRunning)
+                {
+                    if (USB5621AE.USB5621AE_AI_ReadBinary(hDevice, nBinArray, nReadSampsPerChan, ref nSampsPerChanRead, ref nReadableSamps, fTimeout) == false)
+                    {
+                        Log.Error("读取数据失败!");
+                        IsRunning = false;
+                    }
+                    else
+                    {
+                        var data = nBinArray.TakeWhile(t=>t != 0).ToList();
+                        //AIParam设置了获取4个通道的数据
+                        for (int nIndex = 0; nIndex < (data.Count / 4); nIndex++)
+                        {
+                            for (int nChannel = 0; nChannel < 4; nChannel++)
+                            {
+                                Dispatcher.Invoke(new Action(() =>
+                                {
+                                    DataChart.mainChart.Series[nChannel].Points.Add(data[nChannel + nIndex * 4]);
+
+                                    DataChart.mainChart.ChartAreas[0].AxisX.ScaleView.Position = DataChart.mainChart.Series[0].Points.Count - DataChart.mainChart.ChartAreas[0].AxisX.ScaleView.Size;
+
+                                }));
+
+                            }
+                        }
+                    }
+                    Thread.Sleep(50);
+                }
+            });
+            
+        }
+
+        private void IconButton_Click_2(object sender, RoutedEventArgs e)
+        {
+            StopTask();
         }
     }
 }
+

+ 30 - 0
SCADA_DAQ/Customer/Views/Uct/UctMsChart.xaml

@@ -0,0 +1,30 @@
+<wpfcontrol:BaseUserControl  xmlns:wpfcontrol="clr-namespace:SCADA.CommonCtrl.WpfControl;assembly=SCADA.CommonCtrl"
+                             x:Class="SCADA_DAQ.Customer.Views.Uct.UctMsChart"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+                             xmlns:Charting="clr-namespace:System.Windows.Forms.DataVisualization.Charting;assembly=System.Windows.Forms.DataVisualization" xmlns:uct="clr-namespace:SCADA_DAQ.Customer.Views.Uct"
+                             mc:Ignorable="d" 
+             d:DesignHeight="450" d:DesignWidth="800" >
+    <Grid>
+        <!--<Grid.ColumnDefinitions>
+            <ColumnDefinition/>
+            <ColumnDefinition Width="9*"/>
+        </Grid.ColumnDefinitions>-->
+        <!--<StackPanel x:Name="Legends">
+           
+        </StackPanel>-->
+        <WindowsFormsHost x:Name="WFHCHART" Grid.Column="1">
+            <Charting:Chart  x:Name="mainChart"  Text="测试CHART" MouseMove="mainChart_MouseMove_1">
+                <Charting:Chart.Titles>
+                    <!--<Charting:Title Text="WTF"/>-->
+                </Charting:Chart.Titles>
+                
+            </Charting:Chart>
+
+        </WindowsFormsHost>
+   
+
+    </Grid>
+</wpfcontrol:BaseUserControl>

+ 279 - 0
SCADA_DAQ/Customer/Views/Uct/UctMsChart.xaml.cs

@@ -0,0 +1,279 @@
+using Microsoft.DwayneNeed.Win32.Gdi32;
+using Microsoft.DwayneNeed.Win32.User32;
+using SCADA.CommonCtrl.WpfControl;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Forms.DataVisualization.Charting;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace SCADA_DAQ.Customer.Views.Uct
+{
+    /// <summary>
+    /// UctMsChart.xaml 的交互逻辑
+    /// </summary>
+    public partial class UctMsChart : BaseUserControl
+    {
+        private bool MouseDown = false;
+        //private Point ptDown;
+        //private Point ptUp;
+
+        private int MarkSize = 13;
+        private bool IsShowData = false;
+        private bool isMouseDown = false;
+
+        //public List<string> Titles { get; set; } = new List<string>();
+        //private Point mouseOffset; //记录鼠标指针的坐标
+
+        public UctMsChart()
+        {
+            InitializeComponent();
+            //mainChart = WFHCHART.Child as Chart;
+            ChartArea ca = new ChartArea("ChartArea1");
+            //宽度和高度为百分比
+            ca.Position = new ElementPosition(8f, 0f, 92f, 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;
+            //当x轴为时间时需要将sizetype的属性设置一下,才能实现滚轮缩放
+            //ca.AxisX.ScaleView.SizeType = DateTimeIntervalType.Seconds;
+            ca.AxisX.MajorGrid.LineDashStyle = ChartDashStyle.NotSet;
+            ca.AxisX.LabelStyle.Enabled = true;
+            //chart1.ChartAreas[0].AxisX.ScrollBar.IsPositionedInside = true;//指滚动条位于图表区内还是图表区外
+            //chart1.ChartAreas[0].AxisX.ScrollBar.Enabled = true;
+            //chart1.ChartAreas[0].AxisX.ScaleView.Position;//指当前(最右边)显示的是第几个点,可以设为当前一共的数据减去Size;
+            //chart1.ChartAreas[0].AxisX.ScaleView.Size = 5;//视野范围内共有多少个数据点
+
+            //ca.AxisX.IntervalType = DateTimeIntervalType.Seconds;
+            //ca.AxisX.Interval = DateTime.Parse("00:00:24").Second;
+            ca.AxisX.Interval = 2;
+            ca.AxisX.Title = "S";
+            ca.AxisX.IsStartedFromZero = true;
+            //ca.AxisX.lab
+            //ca.AxisX.Minimum = 0;
+
+            //////显示视图的数据点的数量
+            //ca.AxisX.ScaleView.Size = CustomerEnv.DaqSettingValue.XaxisSize;
+            ca.AxisX.ScaleView.Size = 50;
+
+            ca.AxisX.ScrollBar.IsPositionedInside = false;
+            ca.AxisX.ScrollBar.Enabled = true;
+            ca.AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.All;
+            //ca.AxisX.IntervalOffset = 1.00D;
+            ca.AxisX.Minimum = 0;
+            ca.AxisY.MajorGrid.LineColor = System.Drawing.Color.LightGray;
+            ca.AxisY2.MajorGrid.LineColor = System.Drawing.Color.LightGray;
+
+            
+
+            //ca.AxisY.Title = "电压";
+            //ca.AxisY2.Title = "功率W/电流A";
+            ca.AxisY.Minimum = 0;
+            //ca.AxisY.Maximum = 200;
+            ca.AxisY2.Minimum = 0;
+            //ca.AxisY2.Maximum = 2000;
+
+            ca.AxisY2.TitleAlignment = System.Drawing.StringAlignment.Near;
+            ca.AxisY.TitleAlignment = System.Drawing.StringAlignment.Far;
+
+            ca.CursorX.IsUserEnabled = true;
+            ca.CursorY.IsUserEnabled = true;
+            ca.CursorX.IsUserSelectionEnabled = true;
+            //ca.CursorY.IsUserSelectionEnabled = true;
+            ca.CursorX.LineColor = System.Drawing.Color.Black;
+            ca.CursorY.LineColor = System.Drawing.Color.Black;
+            //ca.CursorX.Interval =  (double)CustomerEnv.DaqSettingValue.AcquisitionCycle / 1000;
+            ca.CursorX.Interval = 0.1d;
+
+            ca.CursorY.Interval = 0.1d;
+
+
+
+
+            //背景色
+            ca.BackColor = System.Drawing.Color.FromArgb(231, 231, 231);
+            mainChart.ChartAreas.Add(ca);
+            //Legends.Background = new SolidColorBrush(System.Windows.Media.Color.FromRgb(231, 231, 231));
+            mainChart.BackColor = System.Drawing.Color.FromArgb(231, 231, 231);
+
+            var strList = new List<string> { "通道一", "通道二", "通道三", "通道四", "通道五", "通道六", "通道七", "通道八", "通道九", "通道十" };
+            var colorList = new List<System.Drawing.Color> {
+                    System.Drawing.Color.Red,
+                    System.Drawing.Color.Blue,
+                    System.Drawing.Color.Purple,
+                    System.Drawing.Color.ForestGreen,
+             
+                    System.Drawing.Color.OrangeRed,
+                    System.Drawing.Color.Black,
+                    System.Drawing.Color.Pink,
+                    System.Drawing.Color.Magenta,
+                    System.Drawing.Color.Cyan,
+                    System.Drawing.Color.Lime,
+                    System.Drawing.Color.Gray,
+               
+                    System.Drawing.Color.YellowGreen,
+                    System.Drawing.Color.Orange,
+                    System.Drawing.Color.PeachPuff,
+                    System.Drawing.Color.Azure,
+                };
+            for (int i = 0; i < strList.Count; i++)
+            {
+                //var legend = new UctLegend()
+                //{
+                //    Title = strList[i],
+                //};
+                //legend.Color = GetMediaColorFromDrawingColor(colorList[i]);
+                //legend.Margin = new Thickness(10, 10, 0, 0);
+                //Legends.Children.Add(legend);
+                //电压图例
+                Legend legend = new Legend(strList[i]);
+                //图例文本大小自动调节
+                legend.IsTextAutoFit = false;
+
+                legend.BackColor = System.Drawing.Color.FromArgb(231, 231, 231); ;
+                legend.BackGradientStyle = GradientStyle.TopBottom;
+                legend.BackSecondaryColor = System.Drawing.Color.FromArgb(231, 231, 231);
+                //图例位置
+                legend.Docking = Docking.Top;
+                legend.LegendStyle = LegendStyle.Column;
+                legend.TableStyle = LegendTableStyle.Wide;
+                //legend.DockedToChartArea = "Top";
+                //legend.Title = "电压";
+                legend.Alignment = System.Drawing.StringAlignment.Near;
+                legend.Position.Auto = true;
+                legend.MaximumAutoSize = 12;
+                legend.AutoFitMinFontSize = 8;
+
+
+                mainChart.Legends.Add(legend);
+
+                //电压曲线
+                Series line = new Series($"line{i}");
+                //曲线范围,与上述ca一致
+                line.ChartArea = "ChartArea1";
+                //设置图标类型,曲线、柱状、点 等
+                line.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Spline;
+                //图例是否显示
+                line.IsVisibleInLegend = true;
+                //选择哪个图例
+                line.Legend = strList[i];
+                //图例名称
+                line.LegendText = strList[i];
+                //   line.XValueMember = "Time";
+                //  line.YValueMembers = "Processor";
+                //图例颜色-线条或柱状或点  等
+                line.Color = colorList[i];
+
+                line.ShadowOffset = 1;
+                //line.ShadowColor = colorList[i];
+
+                //x轴的数据类型 
+                line.XValueType = ChartValueType.Int64;
+
+
+                //曲线宽度
+                line.BorderWidth = 1;
+
+                //以哪条Y轴做基准
+                line.YAxisType = AxisType.Primary;
+
+                line.IsValueShownAsLabel = IsShowData;//显示数据点的值
+
+                line.IsVisibleInLegend = true;
+                //数据点形状
+                line.MarkerStyle = MarkerStyle.Square;
+                line.MarkerSize = 2;
+                line.ToolTip = "第#VALX秒\n" + strList[i] + ":#VALY";
+                //line.ToolTip =  strList[i] + ":#VALY";
+
+                //if (i == 0)
+                //{
+                //    line.YAxisType = AxisType.Secondary;
+                //}
+                mainChart.Series.Add(line);
+
+            }
+
+            mainChart.ChartAreas[0].AxisX.LabelStyle.Angle = 0;
+            mainChart.ChartAreas[0].AxisY.LabelStyle.Format = "0.00";
+
+            mainChart.MouseMove += mainChart_MouseMove;
+
+
+
+        }
+
+
+
+        public System.Windows.Media.Brush GetMediaColorFromDrawingColor(System.Drawing.Color color)
+        {
+            return new SolidColorBrush(System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B));
+        }
+      
+        private void mainChart_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
+        {
+            var _currentPointX = e.X;
+            var _currentPointY = e.Y;
+
+            //MsChart.Refresh();没啥效果
+
+            mainChart.ChartAreas[0].CursorX.SetCursorPixelPosition(new PointF(_currentPointX, _currentPointY), true);
+            mainChart.ChartAreas[0].CursorY.SetCursorPixelPosition(new PointF(_currentPointX, _currentPointY), true);
+
+        }
+
+        public void ClearDatas()
+        {
+            for (int i = 0; i < 11; i++)
+            {
+                Dispatcher.Invoke(() =>
+                {
+                    mainChart.Series[i].Points.Clear();
+
+                });
+            }
+        }
+
+        private void mainChart_MouseMove_1(object sender, System.Windows.Forms.MouseEventArgs e)
+        {
+            //try
+            //{
+            //    mainChart.Series["SeriesCursorX"].Points.Clear();
+            //    mainChart.Series["SeriesCursorY"].Points.Clear();
+            //    double cursorX = mainChart.ChartAreas[0].AxisX.PixelPositionToValue(e.X);
+            //    double cursorY = mainChart.ChartAreas[0].AxisY.PixelPositionToValue(e.Y);
+            //    mainChart.Series["SeriesCursorX"].Points.AddXY(cursorX, mainChart.ChartAreas[0].AxisY.Minimum);
+            //    mainChart.Series["SeriesCursorX"].Points.AddXY(cursorX, mainChart.ChartAreas[0].AxisY.Maximum);
+
+            //    mainChart.Series["SeriesCursorY"].Points.AddXY(mainChart.ChartAreas[0].AxisX.Minimum, cursorY);
+            //    mainChart.Series["SeriesCursorY"].Points.AddXY(mainChart.ChartAreas[0].AxisX.Maximum, cursorY);
+
+            //    //DateTime dateTime = DateTime.FromOADate(cursorX);
+
+            //    //labeltooltip.Text = "日期\r\n" + dateTime.ToString("yyyy-MM-dd") +
+            //    //     "\r\n时间\r\n" + dateTime.ToString("HH:mm:ss") +
+            //    //"\r\n报价\r\n" + cursorY.ToString("f2");
+            //}
+            //catch
+            //{
+                
+            //}
+
+        }
+    }
+}

+ 1 - 0
SCADA_DAQ/SCADA_DAQ.csproj

@@ -223,6 +223,7 @@
     <Reference Include="System.Web.Http">
       <HintPath>..\Lib\System.Web.Http.dll</HintPath>
     </Reference>
+    <Reference Include="System.Windows.Forms.DataVisualization" />
     <Reference Include="Xceed.Wpf.Toolkit">
       <HintPath>..\Lib\Xceed.Wpf.Toolkit.dll</HintPath>
       <Private>False</Private>

+ 3 - 0
SCADA_DAQ/SCADA_DAQ.csproj.user

@@ -16,5 +16,8 @@
     <Page Update="Customer\UctFrmParameterSet.xaml">
       <SubType>Designer</SubType>
     </Page>
+    <Page Update="Customer\Views\Uct\UctMsChart.xaml">
+      <SubType>Designer</SubType>
+    </Page>
   </ItemGroup>
 </Project>