Files
YuPu-OrpaonEMS/OrpaonEMS.Core/CoolAutoControl.cs
2025-02-28 22:23:13 +08:00

119 lines
3.3 KiB
C#

using OrpaonEMS.Core.Enums;
using OrpaonEMS.Core.EventHandMsg;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrpaonEMS.Core
{
/// <summary>
/// 液冷自动控制
/// </summary>
public class CoolAutoControl
{
public CoolAutoControl()
{
_CurCoolState = CoolState.AutoCycle;
}
/// <summary>
/// 事件
/// </summary>
public event EventHandler<CoolValue> CoolCmdHandler;
/// <summary>
/// 设置的目标温度
/// </summary>
public double SetTargetTemp { get; set; } = 25;
/// <summary>
/// 是否报警
/// </summary>
public bool IsAlarm { get; set; } = false;
/// <summary>
/// 更新液冷状态
/// </summary>
public void UpdateCoolState(bool AlarmState)
{
IsAlarm = AlarmState;
}
/// <summary>
/// 更新回水温度值
/// </summary>
public void UpdateValue(double OutTempValue)
{
//如果报警了,则不要进行下面的设置数据
if (IsAlarm)
{
CurCoolState = CoolState.Stop;
return;
}
if (OutTempValue > 30)//大于30 启动制冷
{
//设置制冷模式
CurCoolState = CoolState.Cool;
return;
}
if (OutTempValue < 20)
{
//设置加热模式
CurCoolState = CoolState.Heat;
return;
}
//达到目标值就会停止
if (OutTempValue <= (SetTargetTemp + 1) && OutTempValue >= (SetTargetTemp - 1))
{
//设置停止模式
CurCoolState = CoolState.Stop;
return;
}
}
private CoolState _CurCoolState;
/// <summary>
/// 当前液冷状态
/// </summary>
public CoolState CurCoolState
{
get { return _CurCoolState; }
set
{
if (_CurCoolState != value)
{
switch (value)
{
case CoolState.Stop:
CoolCmdHandler(this, new CoolValue() { CmdType = CoolState.Stop, TargetTemp = SetTargetTemp });
break;
case CoolState.Cool:
CoolCmdHandler(this, new CoolValue() { CmdType = CoolState.Cool, TargetTemp = SetTargetTemp });
break;
case CoolState.Heat:
CoolCmdHandler(this, new CoolValue() { CmdType = CoolState.Heat, TargetTemp = SetTargetTemp });
break;
case CoolState.AutoCycle:
CoolCmdHandler(this, new CoolValue() { CmdType = CoolState.AutoCycle, TargetTemp = SetTargetTemp });
break;
default:
break;
}
_CurCoolState = value;
}
}
}
}
}