|
@@ -19,6 +19,7 @@ using System.Configuration;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Linq.Expressions;
|
|
using System.Text;
|
|
using System.Text;
|
|
|
|
+using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows;
|
|
using WPFDevelopers.Controls.Runtimes.Shell32;
|
|
using WPFDevelopers.Controls.Runtimes.Shell32;
|
|
@@ -70,14 +71,22 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
PreviousCommand = new DelegateCommand<object>(Previous);
|
|
PreviousCommand = new DelegateCommand<object>(Previous);
|
|
NextCommand = new DelegateCommand<object>(Next);
|
|
NextCommand = new DelegateCommand<object>(Next);
|
|
DoneCommand = new DelegateCommand<object>(Done);
|
|
DoneCommand = new DelegateCommand<object>(Done);
|
|
|
|
+ UnLoadCommand = new DelegateCommand(Unload);
|
|
ItemChangeCommand = new DelegateCommand(ItemChange);
|
|
ItemChangeCommand = new DelegateCommand(ItemChange);
|
|
ResetCommand = new DelegateCommand(Reset);
|
|
ResetCommand = new DelegateCommand(Reset);
|
|
BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
InConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
InConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
OutConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
OutConList = new ObservableCollection<BasPlcItemConfigDto>();
|
|
GetConfigOption();
|
|
GetConfigOption();
|
|
-
|
|
|
|
|
|
+ ReadPreTask();//读取前置项线程
|
|
|
|
+ m2.Set();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void Unload()
|
|
|
|
+ {
|
|
|
|
+ tokensource.Cancel(); //取消读取前置项的线程
|
|
}
|
|
}
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 选中测试项
|
|
/// 选中测试项
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -91,6 +100,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
globalSchDetailId = id;
|
|
globalSchDetailId = id;
|
|
globalSort = findDtlMsg.sort;
|
|
globalSort = findDtlMsg.sort;
|
|
GetDetailInfo(id);
|
|
GetDetailInfo(id);
|
|
|
|
+ m2.Set(); //继续线程(读取前置项)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -289,6 +299,57 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
#region 私有发方法
|
|
#region 私有发方法
|
|
|
|
+ CancellationTokenSource tokensource = new CancellationTokenSource(); //声明令牌
|
|
|
|
+ ManualResetEvent m2 = new ManualResetEvent(true); //实例化阻塞事件
|
|
|
|
+ private void ReadPreTask()
|
|
|
|
+ {
|
|
|
|
+ CancellationToken cancellationToken = tokensource.Token;
|
|
|
|
+ Task.Run(async()=>
|
|
|
|
+ {
|
|
|
|
+ while(true)
|
|
|
|
+ {
|
|
|
|
+ if (cancellationToken.IsCancellationRequested)
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ m2.WaitOne(); //当m等于true,才会往下执行,否则一直在此等待
|
|
|
|
+ System.Windows.Application.Current.Dispatcher.Invoke((delegate
|
|
|
|
+ {
|
|
|
|
+ foreach (var item in BeforeConList.OrderBy(x => x.Id))
|
|
|
|
+ {
|
|
|
|
+ string plcAddress = item.PlcAddress;
|
|
|
|
+ string plcAddType = item.PlcAddType;
|
|
|
|
+ string plcValue = item.PlcValue;
|
|
|
|
+
|
|
|
|
+ switch (plcAddType)
|
|
|
|
+ {
|
|
|
|
+ case "bool":
|
|
|
|
+ string readResult = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Bit);
|
|
|
|
+ ///实时值记录
|
|
|
|
+
|
|
|
|
+ item.RealValue = readResult;
|
|
|
|
+ item.TestTime = DateTime.Now;
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+ case "word":
|
|
|
|
+ string readResult2 = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Word);
|
|
|
|
+ ///实时值记录
|
|
|
|
+
|
|
|
|
+ item.RealValue = readResult2;
|
|
|
|
+ item.TestTime = DateTime.Now;
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }));
|
|
|
|
+
|
|
|
|
+ await Task.Delay(2000);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }, cancellationToken);//绑定令牌到多线程;
|
|
|
|
+ }
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 增加或更新测试记录
|
|
/// 增加或更新测试记录
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -587,12 +648,14 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
private void Done(object obj)
|
|
private void Done(object obj)
|
|
{
|
|
{
|
|
endTime = DateTime.Now;
|
|
endTime = DateTime.Now;
|
|
|
|
+ tokensource.Cancel(); //取消读取前置项的线程
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private void Next(object obj)
|
|
private void Next(object obj)
|
|
{
|
|
{
|
|
|
|
+ m2.Set(); //继续线程(读取前置项)
|
|
StepIndex = 0;
|
|
StepIndex = 0;
|
|
long maxSort = allSchDtlsById.Select(x => x.sort).Max();
|
|
long maxSort = allSchDtlsById.Select(x => x.sort).Max();
|
|
///查找方案下的所有方案明细,并排序,
|
|
///查找方案下的所有方案明细,并排序,
|
|
@@ -653,6 +716,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
|
|
|
|
private void Previous(object obj)
|
|
private void Previous(object obj)
|
|
{
|
|
{
|
|
|
|
+ m2.Set(); //继续线程(读取前置项)
|
|
StepIndex = 0;
|
|
StepIndex = 0;
|
|
int maxSort = allSchDtlsById.Select(x => x.sort).Max();
|
|
int maxSort = allSchDtlsById.Select(x => x.sort).Max();
|
|
if(maxSort!=0)
|
|
if(maxSort!=0)
|
|
@@ -715,8 +779,8 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
/// <param name="obj"></param>
|
|
/// <param name="obj"></param>
|
|
private async void Start(object obj)
|
|
private async void Start(object obj)
|
|
{
|
|
{
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ m2.Reset(); //阻塞线程(不再读取前置项)
|
|
StartEnalbe = false;
|
|
StartEnalbe = false;
|
|
_logger.LogInformation($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
|
|
_logger.LogInformation($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
|
|
SendLogToDis($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
|
|
SendLogToDis($"开始手动测试。方案名{ScheduleName},测试项{TestName}");
|
|
@@ -739,6 +803,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
{
|
|
{
|
|
MessageBoxResult boxResult = MessageBox.Show("前置项条件不满足,请确认前置条件!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
MessageBoxResult boxResult = MessageBox.Show("前置项条件不满足,请确认前置条件!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
StartEnalbe = true;
|
|
StartEnalbe = true;
|
|
|
|
+ m2.Set(); //继续线程(读取前置项)
|
|
return;
|
|
return;
|
|
|
|
|
|
}
|
|
}
|
|
@@ -870,6 +935,20 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case "word":
|
|
case "word":
|
|
|
|
+ string readResult2 = PLCConnectionFactory.CreatePLCCont().ReadPlcObject(plcAddress, VarType.Word);
|
|
|
|
+ ///实时值记录
|
|
|
|
+
|
|
|
|
+ item.RealValue = readResult2;
|
|
|
|
+ item.TestTime = DateTime.Now;
|
|
|
|
+ if (readResult2.Trim() == plcValue?.Trim())
|
|
|
|
+ {
|
|
|
|
+ item.TestResult = "通过";
|
|
|
|
+ countCond++;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ item.TestResult = "不通过";
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
|
|
|
|
}
|
|
}
|
|
@@ -1327,10 +1406,10 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
/// </summary>
|
|
/// </summary>
|
|
private void Close()
|
|
private void Close()
|
|
{
|
|
{
|
|
- MessageBoxResult boxResult = MessageBox.Show("确认退出自动测试", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
|
|
|
|
|
|
+ MessageBoxResult boxResult = MessageBox.Show("确认退出测试", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Information);
|
|
if (boxResult == MessageBoxResult.OK)
|
|
if (boxResult == MessageBoxResult.OK)
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+ tokensource.Cancel(); //取消读取前置项的线程
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1389,7 +1468,10 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
|
|
public DelegateCommand<object> DoneCommand { set; get; }
|
|
public DelegateCommand<object> DoneCommand { set; get; }
|
|
public DelegateCommand ItemChangeCommand { set; get; }
|
|
public DelegateCommand ItemChangeCommand { set; get; }
|
|
public DelegateCommand ResetCommand { set; get; }
|
|
public DelegateCommand ResetCommand { set; get; }
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ public DelegateCommand UnLoadCommand { set; get; }
|
|
|
|
+
|
|
|
|
+
|
|
#endregion
|
|
#endregion
|
|
#region 变量绑定
|
|
#region 变量绑定
|
|
/// <summary>
|
|
/// <summary>
|