HumitureBean.cs
8.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OnlineStore.DeviceLibrary
{
public class HumitureBean
{
private string PortName = "";
private string Name = "";
public HumitureParam LastData = new HumitureParam(0, 0);
internal HumitureBean(string port,string deviceName)
{
this.Name = deviceName;
this.PortName = port;
}
public HumitureParam QueryData()
{
HumitureParam param = HumitureController.QueryData(PortName);
LastData = param;
return LastData;
}
internal void ProcessHumidityCMD(Operation resultOperation)
{
Dictionary<string, string> data = resultOperation.data;
if (data != null && data.ContainsKey(ParamDefine.maxHumidity) && data.ContainsKey(ParamDefine.maxTemperature))
{
string maxHumidity = data[ParamDefine.maxHumidity];
string maxTemp = data[ParamDefine.maxTemperature];
LogUtil.info( Name+"收到服务器温湿度预警值:maxHumidity=" + maxHumidity + ",maxTemperature=" + maxTemp);
try
{
this.Max_Humidity = (float)Convert.ToDouble(maxHumidity);
this.Max_Temperature = (float)Convert.ToDouble(maxTemp);
LogUtil.info(Name+"保存温湿度预警值:Max_Humidity=" + Max_Humidity + ",Max_Temperature=" + Max_Temperature);
}
catch (Exception ex)
{
LogUtil.error(Name+"转换温湿度失败:" + ex.ToString());
}
}
}
#region 温湿度处理
/// <summary>
/// 湿度标准,超过后需要报警
/// </summary>
private float Max_Humidity = 0;
/// <summary>
/// 温度标准,超过后需要报警
/// </summary>
private float Max_Temperature = 0;
private bool IsInBlowing = false;
private DateTime LastBeginBlowTime = DateTime.Now;
private DateTime LastEndBlowTime = new DateTime(1997, 1, 1);
private DateTime preLogTime = DateTime.Now;
public bool TempOrHumidityIsAlarm = false;
public DateTime TempAlarmTime = DateTime.Now;
private float StartBlowValue = (float)Setting_Init.StartBlowValue;
private float StopBlowValue = (float)Setting_Init.StopBlowValue;
public string currTempStr = "";
internal void HumidityProcess(AC_BOX_Bean box)
{
try
{
if ((DateTime.Now - preLogTime).TotalSeconds > (8+box.DeviceID))
{
preLogTime = DateTime.Now;
//用最大的湿度判断是否需要吹气,开始吹气的值=发过来的值-4
//温湿度
//ASTemperateParam param = HumitureServer.GetTemperateParam(Config.GetTempAddrList());
HumitureParam param = QueryData();
double humidity = 0;
double temp = 0;
if (param != null)
{
humidity = param.Humidity;
temp = param.Temperate;
currTempStr = Name + ("湿度:" + humidity.ToString() + ",温度:" + temp);
}
//double currMaxHumidity = HumitureServer.GetMaxHumidity(Config.GetTempAddrList());
double currMaxHumidity = param.Humidity;
float startBlowHumidity = Max_Humidity - StartBlowValue;
float stopBlowHumidity = Max_Humidity - StopBlowValue;
//判断是否需要吹气
if (startBlowHumidity > 0 && startBlowHumidity < currMaxHumidity && IsInBlowing.Equals(false))
{
//判断是否距离上次结束指定的时间
TimeSpan span = DateTime.Now - LastEndBlowTime;
if (span.TotalMinutes > box.Config.BlowAir_Interval)
{
LogUtil.info(Name + "当前最大湿度:" + currMaxHumidity.ToString() + ",开始吹气湿度:" + startBlowHumidity + ",当前不在吹气中,且间隔超过" + box.Config.BlowAir_Interval + "分钟,开始吹气!");
IsInBlowing = true;
//Thread.Sleep(100);
box.IOMove(IO_Type.StartOrStopBlow, IO_VALUE.HIGH);
LastBeginBlowTime = DateTime.Now;
LastEndBlowTime = DateTime.Now;
}
}
if (IsInBlowing && stopBlowHumidity > currMaxHumidity)
{
LogUtil.info(Name + "当前最大湿度:" + currMaxHumidity.ToString() + ",停止吹气湿度:" + stopBlowHumidity + ",停止吹气!");
IsInBlowing = false;
box.IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
LastEndBlowTime = DateTime.Now;
}
if (IsInBlowing)
{
//判断是否需要结束吹气
TimeSpan span = DateTime.Now - LastBeginBlowTime;
if (span.TotalMinutes > box.Config.BlowAir_Time)
{
LogUtil.info(Name + "已经吹气" + span.TotalMinutes + "分钟,超过配置的吹气时间" + box.Config.BlowAir_Time + "分钟,停止吹气!");
IsInBlowing = false;
//Thread.Sleep(100);
box.IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
LastEndBlowTime = DateTime.Now;
}
}
bool needAlarm = false;
//如果开始吹气并且当前达到报警值
if (IsInBlowing && humidity > Max_Humidity)
{
needAlarm = true;
}
else if (temp > Max_Temperature && Max_Temperature > 0)
{
LogUtil.info(Name + "当前温度【" + param.Temperate + "】超过最高温度【" + Max_Temperature + "】,开始报警!");
needAlarm = true;
//Thread.Sleep(100);
box.IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
}
else if (temp < Max_Temperature)
{
if (IsInBlowing.Equals(false) && TempOrHumidityIsAlarm)
{
LogUtil.info(Name + "不在吹气中,且当前温度【" + param.Temperate + "】低于【" + Max_Temperature + "】,关闭报警!");
TempOrHumidityIsAlarm = false;
//Thread.Sleep(100);
box.IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
}
}
else
{
TempOrHumidityIsAlarm = false;
}
if (needAlarm)
{
HTAlarm();
}
}
}
catch (Exception ex)
{
LogUtil.error(Name + "HumidityProcess出错:" + ex.ToString());
}
}
private void HTAlarm()
{
if (TempOrHumidityIsAlarm)
{
return;
}
TempAlarmTime = DateTime.Now;
TempOrHumidityIsAlarm = true;
}
internal bool NeedGetTem()
{
if (Max_Humidity <= 0 || (Max_Temperature <= 0))
{
return true;
}
return false;
}
#endregion
}
}