添加项目文件。

This commit is contained in:
2024-07-04 17:42:03 +08:00
parent dc72862945
commit 1bd6cd358f
71 changed files with 7218 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
using CapMachine.Wpf.PrismEvent;
using Prism.Events;
using Prism.Mvvm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CapMachine.Wpf.Services
{
public class PlcRtDataService:BindableBase
{
/// <summary>
/// 事件聚合器
/// </summary>
private IEventAggregator _EventAggregator { get; set; }
/// <summary>
/// ScanTask扫描Task
/// </summary>
static Task ScanTask { get; set; }
/// <summary>
/// 扫描线程使能
/// </summary>
public bool ThreadEnable { get; set; } = true;
public PlcRtDataService(IEventAggregator eventAggregator)
{
//事件服务
_EventAggregator = eventAggregator;
PubRtDataStart();
}
private Random random = new Random();
/// <summary>
///发布实时数据
/// </summary>
private void PubRtDataStart()
{
ScanTask = Task.Run(async () =>
{
while (ThreadEnable)
{
try
{
await Task.Delay(1000);
_EventAggregator.GetEvent<ChartRtEvent>().Publish(new List<Models.ChartRtValue>()
{
new Models.ChartRtValue(){Name="室温0",Value=random.NextDouble()*100,Unit="℃"},
new Models.ChartRtValue(){Name="室温1",Value=random.NextDouble()*100,Unit="℃"},
new Models.ChartRtValue(){Name="室温2",Value=random.NextDouble()*100,Unit="℃"},
new Models.ChartRtValue(){Name="室温3",Value=random.NextDouble()*100,Unit="℃"},
new Models.ChartRtValue(){Name="室温4",Value=random.NextDouble()*100,Unit="℃"},
new Models.ChartRtValue(){Name="室温5",Value=random.NextDouble()*100,Unit="℃"},
});
}
catch (Exception ex)
{
var dd = 1;
}
}
});
}
}
}