Browse Source

修改曲线图控件,暂时写死流程运行

HT 3 weeks ago
parent
commit
9da2cdf010

+ 6 - 0
BuildProcess.sln

@@ -35,6 +35,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LogicalElement", "LogicalEl
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomModule", "CustomModule\CustomModule.csproj", "{E0A4F990-AD05-4797-AAA8-5784F7A73C40}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LooseChart", "C:\Users\HT\Desktop\LooseChart-master\src\LooseChart\LooseChart.csproj", "{10B9A473-8383-2DB0-23D2-9D91D68F7A75}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -105,6 +107,10 @@ Global
 		{E0A4F990-AD05-4797-AAA8-5784F7A73C40}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{E0A4F990-AD05-4797-AAA8-5784F7A73C40}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{E0A4F990-AD05-4797-AAA8-5784F7A73C40}.Release|Any CPU.Build.0 = Release|Any CPU
+		{10B9A473-8383-2DB0-23D2-9D91D68F7A75}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{10B9A473-8383-2DB0-23D2-9D91D68F7A75}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{10B9A473-8383-2DB0-23D2-9D91D68F7A75}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{10B9A473-8383-2DB0-23D2-9D91D68F7A75}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 1 - 0
BuildProcess/BuildProcess.csproj

@@ -26,6 +26,7 @@
     <ProjectReference Include="..\TcpModbusSlaveModule\TcpModbusSlaveModule.csproj" />
     <ProjectReference Include="..\TcpServerModule\TcpServerModule.csproj" />
     <ProjectReference Include="..\WpfControlLibrary\WpfControlLibrary.csproj" />
+    <ProjectReference Include="C:\Users\HT\Desktop\LooseChart-master\src\LooseChart\LooseChart.csproj" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="Automation.BDaq4">

+ 24 - 12
BuildProcess/ViewModels/LiveChartsViewModel.cs

@@ -15,9 +15,9 @@ namespace BuildProcess.ViewModels
 {
     public class LiveChartsViewModel : BindableBase
     {
-        private ChartValues<int> dataXCenters;
+        private ChartValues<double> dataXCenters;
 
-        public ChartValues<int> DataXCenters
+        public ChartValues<double> DataXCenters
         {
             get { return dataXCenters; }
             set { dataXCenters = value; RaisePropertyChanged(); }
@@ -42,14 +42,16 @@ namespace BuildProcess.ViewModels
             set { indexData = value; RaisePropertyChanged(); }
         }
 
+        Thread timer;
 
         public LiveChartsViewModel()
         {
-            DataXCenters = new ChartValues<int>() { 1, 2, 3, 4, 5, 6, 2, 3, 2, 2, 3, 4, 6, 2, 3, 4, 1, 2, 3, 4, 5, 6, 2, 3, 2, 2, 3, 4, 6, 2, 3, 4 };
+            DataXCenters = new ChartValues<double>() { 1, 2, 3, 4, 5, 6, 2, 3, 2, 2, 3, 4, 6, 2, 3, 4, 1, 2, 3, 4, 5, 6, 2, 3, 2, 2, 3, 4, 6, 2, 3, 4 };
             DataYCenters = new ChartValues<int>() { 2, 4, 6, 8, 10, 12, 18, 19, 16, 12, 13, 14, 18, 10, 12, 12, 2, 4, 6, 8, 10, 12, 18, 19, 16, 12, 13, 14, 18, 10, 12, 12 };
-            System.Timers.Timer timer = new System.Timers.Timer();
-            timer.Interval = 500;
-            timer.Elapsed += Timer_Elapsed;
+
+
+            timer = new Thread(new ThreadStart(Timer_Elapsed));
+            //timer.Start();
             // 
             //IndexData = new ObservableCollection<IndexXamlModel>();
             //for ( int i = 0; i < 10; i++ )
@@ -59,16 +61,26 @@ namespace BuildProcess.ViewModels
 
         }
 
-        private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
+        private void Timer_Elapsed()
         {
-            if ( InternalStorage.ischange )
+            while (true)
             {
-                List<int> ints = new List<int>();
-                for ( int i = 0; i < InternalStorage.Buffs.Length; i++ )
+                if (InternalStorage.ischange)
                 {
-                    ints.Add(Convert.ToInt32( InternalStorage.Buffs[i]));
+
+                    List<double> ints = new List<double>();
+                    if (InternalStorage.Buffs != null)
+                        for (int i = 0; i < InternalStorage.Buffs.Length-1; i++)
+                        {
+                            if(Math.Abs(InternalStorage.Buffs[i]- InternalStorage.Buffs[i+1])>0.2)
+                                ints.Add(InternalStorage.Buffs[i]);
+                           
+                        }
+                    DataXCenters = new ChartValues<double>(ints);
+                    InternalStorage.ischange = false;
                 }
-                DataXCenters = new ChartValues<int>(ints);
+                Thread.Sleep(500);
+                    
             }
         }
     }

+ 164 - 1
BuildProcess/ViewModels/MainWindowViewModel.cs

@@ -1,13 +1,26 @@
-using FlowChartModule.绘制模块;
+using CommonUtils.Log4;
+using CommonUtils.Tcp.TcpSocket;
+using CommonUtils.内部存储;
+using CommonUtils.运行信号量;
+using CustomModule.ViewModels;
+using FlowChartModule.绘制模块;
 using ParentService.ParentService;
 using Prism.Commands;
 using Prism.Ioc;
 using Prism.Mvvm;
 using Prism.Regions;
+using S7.Net.Types;
+using S7NetModule.Model;
+using S7NetModule.S7;
 using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
 using System.Threading;
 using System.Windows;
 using System.Windows.Controls;
+using TcpClientModule.Model;
+using TcpClientModule.ViewModels;
 
 namespace BuildProcess.ViewModels
 {
@@ -40,14 +53,22 @@ namespace BuildProcess.ViewModels
 
         public int CurrentRegionWidth { get => _CurrentRegionWidth; set { SetProperty(ref _CurrentRegionWidth, value); } }
 
+
+        private Thread RuningStart;
+
         public MainWindowViewModel(IContainerProvider container, IRegionManager regionManager)
         {
             _container = container;
             _regionManager= regionManager;
+
+
         }
 
         public void OnLoad(Canvas canvas)
         {
+            RuningStart = new Thread(new ThreadStart(RunMethod));
+            RuningStart.Name = "任务运行线程";
+            RuningStart.IsBackground = true;
             Element   element=new Element("Start",_container);
             element.parentClass = _container.Resolve<StartService>();
             element._Name = "Start";
@@ -177,8 +198,150 @@ namespace BuildProcess.ViewModels
         {
 
             _regionManager.Regions[ "ContentRegion" ].RequestNavigate("LiveChartsView");
+            if (RuningStart.ThreadState != ThreadState.Running)
+            {
+                StaticManualResetEvent.ManualisStopEvent.Set();
+                RuningStart.Start();
+            }
         }
 
+       static TcpSocketClient tcpSocketClient = new TcpSocketClient();
+        public void RunMethod()
+        {
+
 
+
+            tcpSocketClient.Connect("192.168.0.111", 2268);
+            tcpSocketClient.StartReceive();
+            tcpSocketClient.ReceiveData += TcpSocketClient_ReceiveData;
+            LogHelper.Info("客户端已连接");
+
+
+            S7Plc s7Plc = new S7Plc();
+            s7Plc.model = new S7PlcModel() { IpAddress = "192.168.0.10", CpuType = S7.Net.CpuType.S71200, Port = 102, Rack = 0, Slot = 1 };
+            s7Plc.Open();
+            LogHelper.Info("Plc已连接");
+
+            AsynchronousOneBufferedAI.Init();
+            while (StaticManualResetEvent.ManualisStopEvent.WaitOne(100))
+            {
+                string str = "SOUR:CURR:SLEW:RIS 0.2\r\n";
+                byte[] bytes = Encoding.Default.GetBytes(str);
+                tcpSocketClient.Send(bytes);
+                Thread.Sleep(200);
+                 str = "SOUR:CURR:SLEW:FALL 0.2\r\n";
+                bytes = Encoding.Default.GetBytes(str);
+                tcpSocketClient.Send(bytes);
+                bool res = true;
+                while (StaticManualResetEvent.ManualisStopEvent.WaitOne(100))
+                {
+                    res = s7Plc.ReadBool(new S7ReadModel() { Db = 1090, StartByteAdr = 0, BitAdr = 0, VarCount = 1, VarType = S7.Net.VarType.Bit });
+                    if (res)
+                    {
+                        Thread.Sleep(200);
+                        AsynchronousOneBufferedAI.isEnd = true;
+                        AsynchronousOneBufferedAI.RunTest();
+                        Thread.Sleep(200);
+                        bytes = Encoding.Default.GetBytes("OUTP ON\r\n");
+                        tcpSocketClient.Send(bytes);
+                        Thread.Sleep(1000);
+                        bytes = Encoding.Default.GetBytes("OUTP OFF\r\n");
+                        tcpSocketClient.Send(bytes);
+
+                        break;
+                    }
+                    Thread.Sleep(50);
+                }
+
+                while (StaticManualResetEvent.ManualisStopEvent.WaitOne(100))
+                {
+
+                    if (!AsynchronousOneBufferedAI.isEnd)
+                    {
+                       
+                        break;
+                    }
+                    Thread.Sleep(50);
+                }
+                Thread.Sleep(5000);
+                continue;
+                while (StaticManualResetEvent.ManualisStopEvent.WaitOne(100))
+                {
+                    s7Plc.WriteBool(new S7WriteModel() { Db = 1090, StartByteAdr = 6, BitAdr = 0, VarType = S7.Net.VarType.Bit, Value = true });
+                    Thread.Sleep(100);
+                    res = s7Plc.ReadBool(new S7ReadModel() { Db = 1090, StartByteAdr = 6, BitAdr = 0, VarCount = 1, VarType = S7.Net.VarType.Bit });
+                    if (res)
+                    {
+
+                        break;
+                    }
+                    Thread.Sleep(50);
+                }
+
+               
+                //Db2   262 string 
+
+
+                while (StaticManualResetEvent.ManualisStopEvent.WaitOne(100))
+                {
+                    s7Plc.WriteBool(new S7WriteModel() { Db = 1090, StartByteAdr = 6, BitAdr = 1, VarType = S7.Net.VarType.Bit, Value = true });
+                    Thread.Sleep(100);
+                    res = s7Plc.ReadBool(new S7ReadModel() { Db = 1090, StartByteAdr = 6, BitAdr = 1, VarCount = 1, VarType = S7.Net.VarType.Bit });
+                    if (res)
+                    {
+                        
+                        break;
+                    }
+                    Thread.Sleep(50);
+                }
+
+               
+
+                while (StaticManualResetEvent.ManualisStopEvent.WaitOne(100))
+                {
+                    res = s7Plc.ReadBool(new S7ReadModel() { Db = 1090, StartByteAdr = 0, BitAdr = 0, VarCount = 1, VarType = S7.Net.VarType.Bit });
+                    if (!res)
+                    {
+                        break;
+                    }
+                    Thread.Sleep(50);
+                }
+
+
+                while (StaticManualResetEvent.ManualisStopEvent.WaitOne(100))
+                {
+                    s7Plc.WriteBool(new S7WriteModel() { Db = 1090, StartByteAdr = 6, BitAdr = 1, VarType = S7.Net.VarType.Bit, Value = false });
+                    Thread.Sleep(100);
+                    res = s7Plc.ReadBool(new S7ReadModel() { Db = 1090, StartByteAdr = 6, BitAdr = 1, VarCount = 1, VarType = S7.Net.VarType.Bit });
+                    if (!res)
+                    {
+
+                        break;
+                    }
+                    Thread.Sleep(50);
+                }
+
+                while (StaticManualResetEvent.ManualisStopEvent.WaitOne(100))
+                {
+                    s7Plc.WriteBool(new S7WriteModel() { Db = 1090, StartByteAdr = 6, BitAdr = 0, VarType = S7.Net.VarType.Bit, Value = false });
+                    Thread.Sleep(100);
+                    res = s7Plc.ReadBool(new S7ReadModel() { Db = 1090, StartByteAdr = 6, BitAdr = 0, VarCount = 1, VarType = S7.Net.VarType.Bit });
+                    if (!res)
+                    {
+                        Thread.Sleep(200);
+
+                        break;
+                    }
+                    Thread.Sleep(50);
+                }
+
+                Thread.Sleep(50);
+            }
+        }
+
+        private void TcpSocketClient_ReceiveData(System.Net.IPEndPoint remote, byte[] buffer, int count)
+        {
+            
+        }
     }
 }

+ 12 - 0
BuildProcess/Views/DataBaseView.xaml

@@ -0,0 +1,12 @@
+<UserControl x:Class="BuildProcess.Views.DataBaseView"
+             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:local="clr-namespace:BuildProcess.Views"
+             mc:Ignorable="d" 
+             d:DesignHeight="450" d:DesignWidth="800">
+    <Grid>
+            
+    </Grid>
+</UserControl>

+ 28 - 0
BuildProcess/Views/DataBaseView.xaml.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+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.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace BuildProcess.Views
+{
+    /// <summary>
+    /// DataBaseView.xaml 的交互逻辑
+    /// </summary>
+    public partial class DataBaseView : UserControl
+    {
+        public DataBaseView()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 57 - 6
BuildProcess/Views/LiveChartsView.xaml

@@ -4,6 +4,7 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
              xmlns:local="clr-namespace:BuildProcess.Views"
+               xmlns:chart="clr-namespace:LooseChart;assembly=LooseChart"
              xmlns:prism="http://prismlibrary.com/"
              xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
              prism:ViewModelLocator.AutoWireViewModel="True"
@@ -11,12 +12,59 @@
              Background="White"
              d:DesignHeight="450"
              d:DesignWidth="800">
+    <UserControl.Resources>
+        <chart:AxisRange x:Key="DateTimeRange">
+            <chart:AxisRange.Min>0</chart:AxisRange.Min>
+            <chart:AxisRange.Max>500</chart:AxisRange.Max>
+        </chart:AxisRange>
+        <chart:AxisRange x:Key="LogRange">
+            <chart:AxisRange.Min>-1</chart:AxisRange.Min>
+            <chart:AxisRange.Max>4</chart:AxisRange.Max>
+        </chart:AxisRange>
+    </UserControl.Resources>
     <Grid>
         <Grid.RowDefinitions>
             <RowDefinition Height="auto" />
             <RowDefinition />
+            <RowDefinition />
         </Grid.RowDefinitions>
-        <ItemsControl Grid.Row="0"
+        <Grid ClipToBounds="True" Grid.Row="0">
+            <Grid.RowDefinitions>
+                <RowDefinition />
+                <RowDefinition Height="40" />
+            </Grid.RowDefinitions>
+            <Grid.ColumnDefinitions>
+                <ColumnDefinition Width="40" />
+                <ColumnDefinition />
+                <ColumnDefinition Width="40" />
+            </Grid.ColumnDefinitions>
+            <chart:LinearAxis
+             x:Name="yaxis"
+             AxisType="Y"
+             Range="{StaticResource LogRange}" />
+            <chart:LinearAxis
+             x:Name="y2axis"
+             Grid.Column="2"
+             AxisType="Y2"
+             Range="{StaticResource LogRange}" />
+            <chart:LinearAxis
+             x:Name="xaxis"
+             Grid.Row="1"
+             Grid.Column="1"
+             AxisType="X"
+             Range="{StaticResource DateTimeRange}" />
+            <Grid Grid.Column="1" ClipToBounds="True">
+                <chart:LineSeries
+                 x:Name="series1"
+                 PointLength="1"
+                 ShowFill="True"
+                 ShowStroke="True"
+                    Height="500"
+                 XAxis="{Binding ElementName=xaxis}"
+                 YAxis="{Binding ElementName=yaxis}" />
+            </Grid>
+        </Grid>
+        <ItemsControl Grid.Row="1"
                       ItemsSource="{Binding IndexData}">
             <ItemsControl.ItemsPanel>
                 <ItemsPanelTemplate>
@@ -58,7 +106,9 @@
         </ItemsControl>
 
 
-        <lvc:CartesianChart Grid.Row="1"
+        <lvc:CartesianChart Grid.Row="2"
+                            
+                            DisableAnimations="True"
                             LegendLocation="Top"
                             Margin="0,12">
             <lvc:CartesianChart.Series>
@@ -68,21 +118,21 @@
                                 StrokeDashArray="1"
                                 Title="payCount"
                                 Values="{Binding DataXCenters}" />
-                <lvc:LineSeries LineSmoothness="1"
+                <!--<lvc:LineSeries LineSmoothness="1"
                                 DataLabels="False"
                                 Title="totalCount"
-                                Values="{Binding DataYCenters}" />
+                                Values="{Binding DataYCenters}" />-->
             </lvc:CartesianChart.Series>
             <!--定义Y轴-->
             <lvc:CartesianChart.AxisY>
                 <!-- 定义Y轴名称 -->
-                <lvc:Axis Title="单位/"></lvc:Axis>
+                <lvc:Axis Title="单位/V" MaxValue="5"></lvc:Axis>
             </lvc:CartesianChart.AxisY>
 
             <!--定义X轴-->
             <lvc:CartesianChart.AxisX>
                 <!-- 定义X轴名称 -->
-                <lvc:Axis Title="单位/次"></lvc:Axis>
+                <lvc:Axis Title="单位/次"  ></lvc:Axis>
             </lvc:CartesianChart.AxisX>
             <!--<lvc:CartesianChart.VisualElements>
                 <lvc:VisualElement X="{Binding MinX}" Y="{Binding MaxY}">
@@ -95,5 +145,6 @@
             </lvc:CartesianChart.VisualElements>-->
 
         </lvc:CartesianChart>
+       
     </Grid>
 </UserControl>

+ 46 - 1
BuildProcess/Views/LiveChartsView.xaml.cs

@@ -1,7 +1,11 @@
-using System;
+using CommonUtils.内部存储;
+using ImTools;
+using LiveCharts;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using System.Threading;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
@@ -12,6 +16,7 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using static System.Net.Mime.MediaTypeNames;
 
 namespace BuildProcess.Views
 {
@@ -20,9 +25,49 @@ namespace BuildProcess.Views
     /// </summary>
     public partial class LiveChartsView : UserControl
     {
+
+        Thread MyThread;
         public LiveChartsView()
         {
             InitializeComponent();
+            MyThread = new Thread(new ThreadStart(CanvasRun));
+            MyThread.Start();
+        }
+
+        List<double> XList = new List<double>();
+        void CanvasRun() 
+        {
+            while (true)
+            {
+                if (InternalStorage.ischange)
+                {
+                    if (XList.Count != InternalStorage.Buffs.Length)
+                    {
+                        XList.Clear();
+                        for (int i = 0; i < InternalStorage.Buffs.Length; i++)
+                        {
+                            XList.Add(i);
+                        }
+                    }
+                    this.Dispatcher.Invoke(new Action(() =>
+                    {
+                        this.series1.XSource = XList;
+                        this.series1.YSource = InternalStorage.Buffs;
+
+                    }));
+
+                    //Application.Current.Dispatcher
+                       
+                 
+
+
+                    InternalStorage.ischange = false;
+                }
+                Thread.Sleep(500);
+
+            }
+
+
         }
     }
 }

+ 67 - 59
CustomModule/ViewModels/ViewAViewModel.cs

@@ -5,6 +5,7 @@ using Prism.Mvvm;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Net.Sockets;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
@@ -50,9 +51,17 @@ namespace CustomModule.ViewModels
 
     public class AsynchronousOneBufferedAI
     {
-        public static void RunTest()
+        public static bool isEnd = false;
+        public static WaveformAiCtrl waveformAiCtrl = new WaveformAiCtrl();
+        public static ErrorCode errorCode = ErrorCode.Success;
+        // Step 1: Create a 'WaveformAiCtrl' for Streaming AI function.
+        public static void Init()
         {
-            ErrorCode errorCode = ErrorCode.Success;
+
+            waveformAiCtrl.Stopped += new EventHandler<BfdAiEventArgs>(waveformAiCtrl_Stopped);
+
+
+           
             //-----------------------------------------------------------------------------------
             // Configure the following parameters before running the demo
             //-----------------------------------------------------------------------------------
@@ -60,23 +69,16 @@ namespace CustomModule.ViewModels
             string profilePath = "../../../profile/PCI-1711.xml";
             int startChannel = 0;
             int channelCount = 1;
-            int sectionLength = 1024;
+            int sectionLength = 300;
             int sectionCount = 1;
-            double convertClkRate = 1000.0;
-
-            // Step 1: Create a 'WaveformAiCtrl' for Streaming AI function.
-            WaveformAiCtrl waveformAiCtrl = new WaveformAiCtrl();
-
-            // Step 2: Set the notification event Handler by which we can known the state of operation effectively.
-            waveformAiCtrl.Stopped += new EventHandler<BfdAiEventArgs>(waveformAiCtrl_Stopped);
-
+            double convertClkRate = 100;
             try
             {
                 // Step 3: Select a device by device number or device description and specify the access mode.
                 // in this example we use ModeWrite mode so that we can fully control the device, including configuring, sampling, etc.
                 waveformAiCtrl.SelectedDevice = new DeviceInformation(deviceDescription);
                 errorCode = waveformAiCtrl.LoadProfile(profilePath);//Loads a profile to initialize the device.
-                if ( BioFailed(errorCode) )
+                if (BioFailed(errorCode))
                 {
                     throw new Exception();
                 }
@@ -92,7 +94,7 @@ namespace CustomModule.ViewModels
 
                 // Step 5: prepare the buffered AI. 
                 errorCode = waveformAiCtrl.Prepare();
-                if ( BioFailed(errorCode) )
+                if (BioFailed(errorCode))
                 {
                     throw new Exception();
                 }
@@ -100,69 +102,72 @@ namespace CustomModule.ViewModels
                 // Step 6: start Asynchronous Buffered AI, 'Asynchronous' means the method returns immediately
                 // after the acquisition has been started. The 'bufferedAiCtrl_Stopped' method will be called
                 // after the acquisition is completed.
-                errorCode = waveformAiCtrl.Start();
-                if ( BioFailed(errorCode) )
-                {
-                    throw new Exception();
-                }
 
+            }
+            catch
+            {
+            }
+        }
 
-                Console.WriteLine(" AsynchronousOneBufferedAI is in progress...\n");
+        // Step 2: Set the notification event Handler by which we can known the state of operation effectively.
 
-                // Step 7: The device is acquiring data.
-                do
+        public static void RunTest()
+        {
+            try
+            {
+                errorCode = waveformAiCtrl.Start();
+                if (BioFailed(errorCode))
                 {
-                    Thread.Sleep(1000);
-                } while ( !Console.KeyAvailable );
-
-                // step 8: Stop the operation if it is running.
-                //waveformAiCtrl.Stop();
-
+                    throw new Exception();
+                }
 
             }
-            catch ( Exception e )
+            catch (Exception e)
             {
                 // Something is wrong
-                string errStr = BioFailed(errorCode)? " Some error occurred. And the last error code is " + errorCode.ToString()
-                                                   :e.Message;
+                string errStr = BioFailed(errorCode) ? " Some error occurred. And the last error code is " + errorCode.ToString()
+                                                   : e.Message;
                 Console.WriteLine(errStr);
             }
-            finally
-            {
-                // Step 9: close device, release any allocated resource before quit.
-                waveformAiCtrl.Dispose();
-                Console.ReadKey(false);
-            }
+           
         }
 
         //  process the acquired data
         static void waveformAiCtrl_Stopped(object sender, BfdAiEventArgs e)
         {
-            Console.Write(" Acquisition has completed, sample count is " + e.Count.ToString() + ".\n");
-            WaveformAiCtrl waveformAiCtrl = (WaveformAiCtrl)sender;
-            Int32 channelCountMax = waveformAiCtrl.Features.ChannelCountMax;
-            Int32 startChan = waveformAiCtrl.Conversion.ChannelStart;
-            Int32 channelCount = waveformAiCtrl.Conversion.ChannelCount;
-            Int32 sectionLength = waveformAiCtrl.Record.SectionLength;
-            Int32 bufSize = sectionLength * channelCount;
-            Int32 getDataCount = 0, returnedCount = 0;
-            Int32 remainingCount = e.Count;
-            // e.Count notifys that how many samples had been gathered in the 'Stopped' event. 
-            Double[] allChanData = new Double[bufSize];
-
-            do
+            try
             {
-                getDataCount = Math.Min(bufSize, remainingCount);
-                waveformAiCtrl.GetData(getDataCount, allChanData, 0, out returnedCount);
-                remainingCount -= returnedCount;
-            } while ( remainingCount > 0 );
-
-            InternalStorage.Buffs = allChanData;
-            InternalStorage.ischange = true;
-            Console.WriteLine(" Show each channel's new data:");
-            for ( int i = 0; i < channelCount; ++i )
+                Console.Write(" Acquisition has completed, sample count is " + e.Count.ToString() + ".\n");
+                WaveformAiCtrl waveformAiCtrl = (WaveformAiCtrl)sender;
+                Int32 channelCountMax = waveformAiCtrl.Features.ChannelCountMax;
+                Int32 startChan = waveformAiCtrl.Conversion.ChannelStart;
+                Int32 channelCount = waveformAiCtrl.Conversion.ChannelCount;
+                Int32 sectionLength = waveformAiCtrl.Record.SectionLength;
+                Int32 bufSize = sectionLength * channelCount;
+                Int32 getDataCount = 0, returnedCount = 0;
+                Int32 remainingCount = e.Count;
+                // e.Count notifys that how many samples had been gathered in the 'Stopped' event. 
+                Double[] allChanData = new Double[bufSize];
+
+                do
+                {
+                    getDataCount = Math.Min(bufSize, remainingCount);
+                    waveformAiCtrl.GetData(getDataCount, allChanData, 0, out returnedCount);
+                    remainingCount -= returnedCount;
+                } while (remainingCount > 0);
+
+                InternalStorage.Buffs = allChanData;
+                InternalStorage.ischange = true;
+                isEnd = false;
+                Console.WriteLine(" Show each channel's new data:");
+                for (int i = 0; i < channelCount; ++i)
+                {
+                    Console.WriteLine(" Channel {0}: {1,13:f8}", (i % channelCount + startChan) % channelCountMax, allChanData[i]);
+                }
+            }
+            catch 
             {
-                Console.WriteLine(" Channel {0}: {1,13:f8}", ( i % channelCount + startChan ) % channelCountMax, allChanData[ i ]);
+                isEnd = false;
             }
         }
 
@@ -170,5 +175,8 @@ namespace CustomModule.ViewModels
         {
             return err < ErrorCode.Success && err >= ErrorCode.ErrorHandleNotValid;
         }
+
+
+      
     }
 }

+ 3 - 1
S7NetModule/Model/S7ReadModel.cs

@@ -18,7 +18,7 @@ namespace S7NetModule.Model
         private int  varCount=0;
         private byte bitAdr=0;
         private VarType varType=  VarType.Byte;
-             
+        private bool refPass = false;    
         public S7ReadModel() 
         {
         }
@@ -28,5 +28,7 @@ namespace S7NetModule.Model
         public int VarCount { get => varCount; set { SetProperty(ref varCount, value); } }
         public byte BitAdr { get => bitAdr; set { SetProperty(ref bitAdr, value); } }
         public VarType VarType { get => varType; set { SetProperty(ref varType, value); } }
+
+        public bool RefPass { get => refPass; set { SetProperty(ref refPass, value); } }
     }
 }

+ 1 - 1
S7NetModule/S7/S7Plc.cs

@@ -77,7 +77,7 @@ namespace S7NetModule.S7
                     }
                     else
                     {
-                        boolValue=( bool ) plc.Read(DataType.DataBlock, model.Db, model.StartByteAdr, VarType.Bit, model.VarCount, 0);
+                        boolValue=( bool ) plc.Read(DataType.DataBlock, model.Db, model.StartByteAdr, VarType.Bit, model.VarCount, model.BitAdr);
                     }
                 }
             }

+ 57 - 40
S7NetModule/ViewModels/S7ReadlViewModel.cs

@@ -21,6 +21,9 @@ namespace S7NetModule.ViewModels
 
         private string _OutMsg="";
 
+        public bool[] Res_Pass = new bool[] {true,false };
+
+         
         public string OutMsg
         {
             get => _OutMsg;
@@ -81,47 +84,61 @@ namespace S7NetModule.ViewModels
         {
             try
             {
-                switch ( Read_Model.VarType )
+                while (true)
                 {
-                    case VarType.Bit:
-
-                        OutMsg = S7NetModels[ 0 ].plcClient.ReadBool(Read_Model).ToString();
-                        break;
-                    case VarType.Byte:
-
-                        break;
-                    case VarType.Word:
-                        break;
-                    case VarType.DWord:
-                        break;
-                    case VarType.Int:
-                        OutMsg = S7NetModels[ 0 ].plcClient.ReadInt(Read_Model).ToString();
-                        break;
-                    case VarType.DInt:
-                        OutMsg = S7NetModels[ 0 ].plcClient.ReadDInt(Read_Model).ToString();
-                        break;
-                    case VarType.Real:
-                        OutMsg = S7NetModels[ 0 ].plcClient.ReadReal(Read_Model).ToString();
-                        break;
-                    case VarType.LReal:
-                        break;
-                    case VarType.String:
-                        OutMsg = S7NetModels[ 0 ].plcClient.ReadString(Read_Model).ToString();
-                        break;
-                    case VarType.S7String:
-                        break;
-                    case VarType.S7WString:
-                        break;
-                    case VarType.Timer:
-                        break;
-                    case VarType.Counter:
-                        break;
-                    case VarType.DateTime:
-                        break;
-                    case VarType.DateTimeLong:
-                        break;
-                    default:
-                        break;
+                    switch (Read_Model.VarType)
+                    {
+                        case VarType.Bit:
+                            OutMsg = S7NetModels[0].plcClient.ReadBool(Read_Model).ToString();
+                            break;
+                        case VarType.Byte:
+
+                            break;
+                        case VarType.Word:
+                            break;
+                        case VarType.DWord:
+                            break;
+                        case VarType.Int:
+                            OutMsg = S7NetModels[0].plcClient.ReadInt(Read_Model).ToString();
+                            break;
+                        case VarType.DInt:
+                            OutMsg = S7NetModels[0].plcClient.ReadDInt(Read_Model).ToString();
+                            break;
+                        case VarType.Real:
+                            OutMsg = S7NetModels[0].plcClient.ReadReal(Read_Model).ToString();
+                            break;
+                        case VarType.LReal:
+                            break;
+                        case VarType.String:
+                            OutMsg = S7NetModels[0].plcClient.ReadString(Read_Model).ToString();
+                            break;
+                        case VarType.S7String:
+                            break;
+                        case VarType.S7WString:
+                            break;
+                        case VarType.Timer:
+                            break;
+                        case VarType.Counter:
+                            break;
+                        case VarType.DateTime:
+                            break;
+                        case VarType.DateTimeLong:
+                            break;
+                        default:
+                            break;
+                    }
+
+                    if (Read_Model.VarType == VarType.Bit)
+                    {
+                        if (OutMsg == Read_Model.RefPass.ToString())
+                        {
+                            break;
+                        }
+                    }
+                    else 
+                    {
+                        break;
+                    }
                 }
 
             }catch (Exception ex)

+ 13 - 2
S7NetModule/Views/S7ReadlView.xaml

@@ -33,6 +33,7 @@
                 <RowDefinition Height="50" />
                 <RowDefinition Height="50" />
                 <RowDefinition Height="50" />
+                <RowDefinition Height="50" />
                 <RowDefinition />
             </Grid.RowDefinitions>
             <!--  DB号   -->
@@ -83,11 +84,21 @@
                 <TextBox  Width="{Binding ElementName=ip,Path=ActualWidth}"
                           Text="{Binding Read_Model.BitAdr}" />
             </StackPanel>
+            <!--  数据类型   -->
+            <StackPanel Orientation="Horizontal"
+            VerticalAlignment="Center"
+            Grid.Row="5">
+                <TextBlock Text="结果比对:"
+               Style="{ StaticResource TextBlackStyle}" />
+                <ComboBox   Width="{Binding ElementName=ip,Path=ActualWidth}"
+                ItemsSource="{Binding Res_Pass}"
+                SelectedItem ="{Binding Read_Model.RefPass}" />
+            </StackPanel>
             <StackPanel Orientation="Horizontal"
                         Width="{Binding ElementName=ip,Path=ActualWidth}"
                         VerticalAlignment="Center"
                         HorizontalAlignment="Right"
-                        Grid.Row="5">
+                        Grid.Row="6">
                 <Button  Content="读取"
                          Width="100"
                          Height="50"
@@ -97,7 +108,7 @@
             <StackPanel Orientation="Horizontal"
                         VerticalAlignment="Center"
                         HorizontalAlignment="Center"
-                        Grid.Row="6">
+                        Grid.Row="7">
                 <RichTextBox  Width="{Binding ElementName=ip,Path=ActualWidth}">
                     <FlowDocument>
                         <Paragraph>