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
{
///
/// 事件聚合器
///
private IEventAggregator _EventAggregator { get; set; }
///
/// ScanTask扫描Task
///
static Task ScanTask { get; set; }
///
/// 扫描线程使能
///
public bool ThreadEnable { get; set; } = true;
public PlcRtDataService(IEventAggregator eventAggregator)
{
//事件服务
_EventAggregator = eventAggregator;
PubRtDataStart();
}
private Random random = new Random();
///
///发布实时数据
///
private void PubRtDataStart()
{
ScanTask = Task.Run(async () =>
{
while (ThreadEnable)
{
try
{
await Task.Delay(1000);
_EventAggregator.GetEvent().Publish(new List()
{
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;
}
}
});
}
}
}