using OrpaonEMS.App.Services; using OrpaonEMS.Core.Enums; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace OrpaonEMS.App.Models { /// /// 自动触发模块运行模型 /// 比如PCS /// public class TrigModuleStartRunAction { /// /// 实例化 /// public TrigModuleStartRunAction(EnergyStorageService energyStorage) { //实例注入 energyStorages = energyStorage; } /// /// 获取储能的实例 /// private EnergyStorageService energyStorages { get; set; } /// /// 线程使能 /// private bool PcsAutoTrigThreadEnable = true; /// /// PCS自动触发运行 /// public void PcsAutoTrigRun() { Console.WriteLine($"时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")}:PCS自动触发运行-开始运行自动触发循环"); //先使能线程的循环的条件 PcsAutoTrigThreadEnable = true; Task.Run(() => { while (PcsAutoTrigThreadEnable) { energyStorages.InPowerPCSDataService.PCSStart(); //延迟6秒 看结果 Thread.Sleep(6000); if (energyStorages.InPowerPCSDataService.PcsRunState.PcsStateInfo != PCSState.Stop) { PcsAutoTrigThreadEnable = false; Console.WriteLine($"时间:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")}:PCS自动触发运行-触发启动成功-结束循环扫描 "); } } }); } /// /// 如果一直触发没有成功的话,则取消即可 /// 关闭触发PCS自动触发运行 /// 可能是报警到其他的状态了,不需要自动触发了 /// 即使没有运行这个触发循环,也可以执行这个函数 /// public void PcsAutoTrigClose() { PcsAutoTrigThreadEnable = false; } } }