user_lt 1 سال پیش
والد
کامیت
846a093162

+ 1 - 1
BlankApp1/BlankApp1/App.config

@@ -3,7 +3,7 @@
 	<appSettings>
 	<appSettings>
 		<!--连接字符串 SQL Server-->
 		<!--连接字符串 SQL Server-->
 		<add key="MySql" value="Data Source=localhost;Database=plc_point_db;User Id='root';Password='Lt,100186';port=3306;charset=utf8mb4;"/>
 		<add key="MySql" value="Data Source=localhost;Database=plc_point_db;User Id='root';Password='Lt,100186';port=3306;charset=utf8mb4;"/>
-		<add key="PLCIp" value="192.168.250.1"/>
+		<add key="PLCIp" value="192.168.0.20"/>
 		<add key="PLCPort" value="9600"/>
 		<add key="PLCPort" value="9600"/>
 
 
 	</appSettings>
 	</appSettings>

+ 2 - 1
BlankApp1/BlankApp1/Common/PLCCom.cs

@@ -80,7 +80,8 @@ namespace PLCTool.Common
                     {
                     {
                         if(address.Contains("w")|| address.Contains("W"))
                         if(address.Contains("w")|| address.Contains("W"))
                         {
                         {
-                            reSuc = ENT.GetBitState(PlcMemory.WR, address, out rb);
+                            string realAddr = address.Substring(1, address.Length - 1);
+                            reSuc = ENT.GetBitState(PlcMemory.WR, realAddr, out rb);
                             //读取成功
                             //读取成功
                             if (reSuc == 0)
                             if (reSuc == 0)
                             {
                             {

+ 8 - 3
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/AddDetailViewModel.cs

@@ -112,14 +112,19 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         /// <param name="obj"></param>
         /// <param name="obj"></param>
         private void Sure(string obj)
         private void Sure(string obj)
         {
         {
-            if(string.IsNullOrEmpty(PLCItem)|| string.IsNullOrEmpty(PLCAddress))
+            if ( string.IsNullOrEmpty(PLCAddress))
             {
             {
-                MessageBox.Show("请填写PLC变量名或地址!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                MessageBox.Show("请填写PLC地址!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+            if (string.IsNullOrEmpty(PLCItem))
+            {
+                MessageBox.Show("请填写PLC变量名!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                 return;
                 return;
             }
             }
             if (string.IsNullOrEmpty(SelectPLCType) )
             if (string.IsNullOrEmpty(SelectPLCType) )
             {
             {
-                MessageBox.Show("请选择PLC类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                MessageBox.Show("请选择PLC变量类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
                 return;
                 return;
             }
             }
             BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto()
             BasPlcItemConfigDto basPlcItemConfigDto = new BasPlcItemConfigDto()

+ 3 - 3
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/AddOrEditSchViewModel.cs

@@ -364,7 +364,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         {
         {
             if (string.IsNullOrEmpty(ScheduleName))
             if (string.IsNullOrEmpty(ScheduleName))
             {
             {
-                MessageBox.Show("请填写测试名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                MessageBox.Show("请填写测试方案名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                 return;
                 return;
             }
             }
             if (string.IsNullOrEmpty(DeviceName))
             if (string.IsNullOrEmpty(DeviceName))
@@ -412,12 +412,12 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             //输出项
             //输出项
             if (string.IsNullOrEmpty(SelectOutJudge))
             if (string.IsNullOrEmpty(SelectOutJudge))
             {
             {
-                MessageBox.Show("请填写输出项测试项测试类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                MessageBox.Show("请填写结果项测试项测试类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                 return;
                 return;
             }
             }
             if (string.IsNullOrEmpty(OutSelectLogic))
             if (string.IsNullOrEmpty(OutSelectLogic))
             {
             {
-                MessageBox.Show("请填写输出项判定逻辑!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                MessageBox.Show("请填写结果项判定逻辑!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                 return;
                 return;
             }
             }
 
 

+ 1 - 0
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/BaseConfigViewModel.cs

@@ -69,6 +69,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             DeviceName = string.Empty;
             DeviceName = string.Empty;
             TestName = string.Empty;
             TestName = string.Empty;
             SelectTest = string.Empty;
             SelectTest = string.Empty;
+  
         }
         }
         /// <summary>
         /// <summary>
         /// 查询
         /// 查询

+ 39 - 1
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/AutoTestViewModel.cs

@@ -47,6 +47,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private long selctStartDetailId = 0; //当前选择的第一个方案明细id
         private long selctStartDetailId = 0; //当前选择的第一个方案明细id
         private BizTestRecordDtlDto bizTestRecordDtlDto = new BizTestRecordDtlDto(); //测试方案明细表
         private BizTestRecordDtlDto bizTestRecordDtlDto = new BizTestRecordDtlDto(); //测试方案明细表
         private const string TestMode = "自动测试";
         private const string TestMode = "自动测试";
+        private int delayTime = 20;
         ManualResetEvent m = new ManualResetEvent(true); //实例化阻塞事件
         ManualResetEvent m = new ManualResetEvent(true); //实例化阻塞事件
         CancellationTokenSource tokensource = new CancellationTokenSource(); //声明令牌
         CancellationTokenSource tokensource = new CancellationTokenSource(); //声明令牌
         public AutoTestViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordService iBizTestRecordService, IBizTestRecordDtlService iBizTestRecordDtlService, IMapper mapper, ILogger logger)
         public AutoTestViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordService iBizTestRecordService, IBizTestRecordDtlService iBizTestRecordDtlService, IMapper mapper, ILogger logger)
@@ -892,7 +893,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                         //一直读
                         //一直读
                         await Task.Run(async () =>
                         await Task.Run(async () =>
                         {
                         {
-                            while (entryTime.AddMilliseconds(10 * 1000) > DateTime.Now)
+                            while (entryTime.AddMilliseconds(delayTime * 1000) > DateTime.Now)
                             {
                             {
                                 //显示进度条
                                 //显示进度条
                                 System.Windows.Application.Current.Dispatcher.Invoke((delegate
                                 System.Windows.Application.Current.Dispatcher.Invoke((delegate
@@ -925,7 +926,44 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
 
                         break;
                         break;
                     case "word":
                     case "word":
+                        DateTime entryTime2 = DateTime.Now;
+                        string readResult2 = string.Empty;
+                        //一直读
+                        await Task.Run(async () =>
+                        {
+                            while (entryTime2.AddMilliseconds(delayTime * 1000) > DateTime.Now)
+                            {
+                                //显示进度条
+                                System.Windows.Application.Current.Dispatcher.Invoke((delegate
+                                {
+                                    ProVisibility = Visibility.Visible;
+                                }));
+
+                                readResult = PLCCom.GetInstance().ReadPlcObject(plcAddress, VarType.Word);
+                                if (readResult == item.PlcValue)
+                                {
+                                    break;
+                                }
+                                await Task.Delay(1000);
+                            }
+                        });
+
+                        ProVisibility = Visibility.Hidden;
+                        ///实时值记录
+                        item.RealValue = readResult2;
+                        item.TestTime = DateTime.Now;
+                        if (readResult2.Trim() == plcValue?.Trim())
+                        {
+                            item.TestResult = "合格";
+                            countCond++;
+                        }
+                        else
+                        {
+                            item.TestResult = "不合格";
+                        }
+
                         break;
                         break;
+                     
 
 
                 }
                 }
 
 

+ 39 - 2
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ManualTestViewModel.cs

@@ -47,7 +47,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         private long globalSchDetailId = 0; //测试方案明细ID
         private long globalSchDetailId = 0; //测试方案明细ID
         private BizTestRecordDtlDto bizTestRecordDtlDto = new BizTestRecordDtlDto(); //测试方案明细表
         private BizTestRecordDtlDto bizTestRecordDtlDto = new BizTestRecordDtlDto(); //测试方案明细表
         private const string TestMode = "手动测试";
         private const string TestMode = "手动测试";
-    
+        private int delayTime = 20;
         public ManualTestViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordService iBizTestRecordService, IBizTestRecordDtlService iBizTestRecordDtlService,IMapper mapper,ILogger logger)
         public ManualTestViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IBizTestRecordService iBizTestRecordService, IBizTestRecordDtlService iBizTestRecordDtlService,IMapper mapper,ILogger logger)
         {
         {
             _dialog = dialog;
             _dialog = dialog;
@@ -901,7 +901,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                         //一直读
                         //一直读
                         await Task.Run(async () =>
                         await Task.Run(async () =>
                         {
                         {
-                            while (entryTime.AddMilliseconds(10 * 1000) > DateTime.Now)
+                            while (entryTime.AddMilliseconds(delayTime * 1000) > DateTime.Now)
                             {
                             {
                                 //显示进度条
                                 //显示进度条
                                 System.Windows.Application.Current.Dispatcher.Invoke((delegate
                                 System.Windows.Application.Current.Dispatcher.Invoke((delegate
@@ -934,6 +934,43 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
 
 
                         break;
                         break;
                     case "word":
                     case "word":
+                        DateTime entryTime2 = DateTime.Now;
+                        string readResult2 = string.Empty;
+                        //一直读
+                        await Task.Run(async () =>
+                        {
+                            while (entryTime2.AddMilliseconds(delayTime * 1000) > DateTime.Now)
+                            {
+                                //显示进度条
+                                System.Windows.Application.Current.Dispatcher.Invoke((delegate
+                                {
+                                    ProVisibility = Visibility.Visible;
+                                }));
+
+                                readResult = PLCCom.GetInstance().ReadPlcObject(plcAddress, VarType.Word);
+                                if (readResult == item.PlcValue)
+                                {
+                                    break;
+                                }
+                                await Task.Delay(1000);
+                            }
+                        });
+
+                        ProVisibility = Visibility.Hidden;
+                        ///实时值记录
+                        item.RealValue = readResult2;
+                        item.TestTime = DateTime.Now;
+                        if (readResult2.Trim() == plcValue?.Trim())
+                        {
+                            item.TestResult = "合格";
+                            countCond++;
+                        }
+                        else
+                        {
+                            item.TestResult = "不合格";
+                        }
+
+                        break;
                         break;
                         break;
 
 
                 }
                 }

+ 1 - 1
BlankApp1/BlankApp1/Views/BasicConfigView/AddDetailView.xaml

@@ -44,7 +44,7 @@
             <TextBox  Height="28" Width="120" Text="{Binding PLCItem}" />
             <TextBox  Height="28" Width="120" Text="{Binding PLCItem}" />
         </StackPanel>
         </StackPanel>
         <StackPanel Orientation="Horizontal"  Grid.Row="3" HorizontalAlignment="Center">
         <StackPanel Orientation="Horizontal"  Grid.Row="3" HorizontalAlignment="Center">
-            <TextBlock Text="PLC变量类型信息:"  Style="{StaticResource NormalTextBlockStyle}" />
+            <TextBlock Text="PLC变量类型:"  Style="{StaticResource NormalTextBlockStyle}" />
             <ComboBox  Height="28" Width="120" ItemsSource="{Binding PLCTypes}" SelectedItem="{Binding SelectPLCType}" />
             <ComboBox  Height="28" Width="120" ItemsSource="{Binding PLCTypes}" SelectedItem="{Binding SelectPLCType}" />
         </StackPanel>
         </StackPanel>
         <StackPanel Orientation="Horizontal" Grid.Row="4" HorizontalAlignment="Center">
         <StackPanel Orientation="Horizontal" Grid.Row="4" HorizontalAlignment="Center">

+ 1 - 1
BlankApp1/BlankApp1/Views/MainWindow.xaml

@@ -149,7 +149,7 @@
                         </EllipseGeometry>
                         </EllipseGeometry>
                     </Path.Data>
                     </Path.Data>
                 </Path>
                 </Path>
-                <TextBlock Text="V1.0" Style="{StaticResource txtHeadStyle}" Width="60" Margin="30,0,12,0"/>
+                <TextBlock Text="V1.1" Style="{StaticResource txtHeadStyle}" Width="60" Margin="30,0,12,0"/>
             </StackPanel>
             </StackPanel>
           
           
         </Border>
         </Border>