Files
YuPu-OrpaonEMS/OrpaonEMS.App/Models/TrigModuleStartRunAction.cs
2025-02-28 22:23:13 +08:00

80 lines
2.3 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
{
/// <summary>
/// 自动触发模块运行模型
/// 比如PCS
/// </summary>
public class TrigModuleStartRunAction
{
/// <summary>
/// 实例化
/// </summary>
public TrigModuleStartRunAction(EnergyStorageService energyStorage)
{
//实例注入
energyStorages = energyStorage;
}
/// <summary>
/// 获取储能的实例
/// </summary>
private EnergyStorageService energyStorages { get; set; }
/// <summary>
/// 线程使能
/// </summary>
private bool PcsAutoTrigThreadEnable = true;
/// <summary>
/// PCS自动触发运行
/// </summary>
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自动触发运行-触发启动成功-结束循环扫描 ");
}
}
});
}
/// <summary>
/// 如果一直触发没有成功的话,则取消即可
/// 关闭触发PCS自动触发运行
/// 可能是报警到其他的状态了,不需要自动触发了
/// 即使没有运行这个触发循环,也可以执行这个函数
/// </summary>
public void PcsAutoTrigClose()
{
PcsAutoTrigThreadEnable = false;
}
}
}