HumitureBean.cs
13.0 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
using System;
using System.Collections.Generic;
namespace OnlineStore.DeviceLibrary
{
public class HumitureBean
{
private string PortName = "";
private string Name = "";
public static List<HumitureParam> LastData = new List<HumitureParam>();
static List<HumitureBean> humitureBeans = new List<HumitureBean>();
internal HumitureBean(string port, string deviceName)
{
this.Name = deviceName;
this.PortName = port;
HumitureController.Init(this.PortName);
}
public static void LoadHumitures(string[] ports, string deviceName)
{
for (int i = 0; i < ports.Length; i++)
{
humitureBeans.Add(new HumitureBean(ports[i], deviceName + (i + 1)));
HumitureParam param = new HumitureParam(0, 0, 100);
param.DeviceAddress = ports[i];
LastData.Add(param);
}
}
public HumitureParam QueryData()
{
HumitureParam param = HumitureController.QueryData(PortName);
updateData(PortName, param);
return param;
}
static void updateData(string port, HumitureParam param)
{
var find = LastData.Find(s => port.Equals(s.DeviceAddress));
if (find != null)
{
find.Temperate = param.Temperate;
find.UpdateTime = param.UpdateTime;
find.Humidity = param.Humidity;
find.OxygenV = param.OxygenV;
}
}
public static double GetMinOxygenV()
{
double maxV = 0.0;
foreach (var item in humitureBeans)
{
double val = item.QueryData().OxygenV;
if (val > maxV)
{
maxV = val;
}
}
return maxV;
}
internal static 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("收到服务器温湿度预警值:maxHumidity=" + maxHumidity + ",maxTemperature=" + maxTemp);
try
{
Max_Humidity = (float)Convert.ToDouble(maxHumidity);
Max_Temperature = (float)Convert.ToDouble(maxTemp);
LogUtil.info("保存温湿度预警值:Max_Humidity=" + Max_Humidity + ",Max_Temperature=" + Max_Temperature);
}
catch (Exception ex)
{
LogUtil.error("转换温湿度失败:" + ex.ToString());
}
}
if (data != null && data.ContainsKey(ParamDefine.minHumidity) && data.ContainsKey(ParamDefine.minTemperature))
{
string maxHumidity = data[ParamDefine.minHumidity];
string maxTemp = data[ParamDefine.minTemperature];
LogUtil.info("收到服务器温湿度预警值:minHumidity=" + maxHumidity + ",minTemperature=" + maxTemp);
try
{
Min_Humidity = (float)Convert.ToDouble(maxHumidity);
Min_Temperature = (float)Convert.ToDouble(maxTemp);
LogUtil.info("保存温湿度预警值:Min_Humidity=" + Min_Humidity + ",Min_Temperature=" + Min_Temperature);
}
catch (Exception ex)
{
LogUtil.error("转换温湿度失败:" + ex.ToString());
}
}
}
#region 温湿度处理
/// <summary>
/// 湿度标准,超过后需要报警
/// </summary>
public static float Max_Humidity = 0;
/// <summary>
/// 温度标准,超过后需要报警
/// </summary>
public static float Max_Temperature = 0;
public static float Min_Humidity = 0;
public static float Min_Temperature = 0;
private static bool IsInBlowing = false;
private static DateTime LastBeginBlowTime = DateTime.Now;
private static DateTime LastEndBlowTime = new DateTime(1997, 1, 1);
static DateTime preLogTime = DateTime.Now;
public static bool TempOrHumidityIsAlarm = false;
public static DateTime TempAlarmTime = DateTime.Now;
private static float StartBlowValue = (float)ConfigAppSettings.GetNumValue(Setting_Init.StartBlowValue);
private static float StopBlowValue = (float)ConfigAppSettings.GetNumValue(Setting_Init.StopBlowValue);
public static string currTempStr = "";
public static void ProcessAllHumidity(BoxEquip box)
{
double curMaxHumidity = double.MinValue;
double curMinTemp = double.MaxValue;
foreach (var item in humitureBeans)
{
HumitureParam param = item.QueryData();
if (param.Humidity > curMaxHumidity)
{
curMaxHumidity = param.Humidity;
}
if (param.Temperate < curMinTemp)
{
curMinTemp = param.Temperate;
}
}
HumidityProcess(box, curMaxHumidity, curMinTemp);
}
public static List<HumitureParam> GetHumitureParams()
{
return LastData;
}
internal static void HumidityProcess(BoxEquip box, double currMaxHumidity, double curMinTemp)
{
if (IOManager.IOValue(IO_Type.Air_OpenValve, 1).Equals(IO_VALUE.HIGH) || IOManager.IOValue(IO_Type.LeftDoor_Limit, 2).Equals(IO_VALUE.LOW) || IOManager.IOValue(IO_Type.RightDoor_Limit, 2).Equals(IO_VALUE.LOW) || IOManager.IOValue(IO_Type.BackDoor_Limit, 2).Equals(IO_VALUE.LOW))
{
IOManager.IOMove(IO_Type.Nitrogen_OpenValve, IO_VALUE.HIGH, 1);
return;
}
try
{
if ((DateTime.Now - preLogTime).TotalSeconds > (8 + box.DeviceID))
{
preLogTime = DateTime.Now;
//用最大的湿度判断是否需要吹气,开始吹气的值=发过来的值-4
//温湿度
//ASTemperateParam param = HumitureServer.GetTemperateParam(Config.GetTempAddrList());
//HumitureParam param = QueryData();
float startBlowHumidity = Max_Humidity - StartBlowValue;
float stopBlowHumidity = Max_Humidity - StopBlowValue;
IsInBlowing = IOManager.DOValue(IO_Type.Nitrogen_OpenValve, 1).Equals(IO_VALUE.LOW);
//判断是否需要吹气
if (startBlowHumidity > 0 && startBlowHumidity < currMaxHumidity && IsInBlowing.Equals(false))
{
//判断是否距离上次结束指定的时间
TimeSpan span = DateTime.Now - LastEndBlowTime;
if (span.TotalMinutes > box.Config.BlowAir_Interval)
{
LogUtil.info("当前最大湿度:" + currMaxHumidity.ToString() + ",开始吹气湿度:" + startBlowHumidity + ",当前不在吹气中,且间隔超过" + box.Config.BlowAir_Interval + "分钟,开始吹气!");
IsInBlowing = true;
//Thread.Sleep(100);
IOManager.IOMove(IO_Type.Nitrogen_OpenValve, IO_VALUE.LOW, 1);
LastBeginBlowTime = DateTime.Now;
LastEndBlowTime = DateTime.Now;
}
}
if (IsInBlowing && stopBlowHumidity > currMaxHumidity)
{
LogUtil.info("当前最大湿度:" + currMaxHumidity.ToString() + ",停止吹气湿度:" + stopBlowHumidity + ",停止吹气!");
IsInBlowing = false;
IOManager.IOMove(IO_Type.Nitrogen_OpenValve, IO_VALUE.HIGH, 1);
LastEndBlowTime = DateTime.Now;
}
if (IsInBlowing)
{
//判断是否需要结束吹气
TimeSpan span = DateTime.Now - LastBeginBlowTime;
if (span.TotalMinutes > box.Config.BlowAir_Time)
{
LogUtil.info("已经吹气" + span.TotalMinutes + "分钟,超过配置的吹气时间" + box.Config.BlowAir_Time + "分钟,停止吹气!");
IsInBlowing = false;
//Thread.Sleep(100);
IOManager.IOMove(IO_Type.Nitrogen_OpenValve, IO_VALUE.HIGH, 1);
LastEndBlowTime = DateTime.Now;
}
}
bool needAlarm = false;
//如果开始吹气并且当前达到报警值
if (IsInBlowing && currMaxHumidity > Max_Humidity)
{
needAlarm = true;
}
else if (curMinTemp > Max_Temperature && Max_Temperature > 0)
{
LogUtil.info("当前温度【" + curMinTemp + "】超过最高温度【" + Max_Temperature + "】,开始报警!");
needAlarm = true;
//Thread.Sleep(100);
}
else if (curMinTemp < Max_Temperature)
{
if (IsInBlowing.Equals(false) && TempOrHumidityIsAlarm)
{
LogUtil.info("不在吹气中,且当前温度【" + curMinTemp + "】低于【" + Max_Temperature + "】,关闭报警!");
TempOrHumidityIsAlarm = false;
//Thread.Sleep(100);
IOManager.IOMove(IO_Type.Nitrogen_OpenValve, IO_VALUE.HIGH, 1);
}
}
else
{
TempOrHumidityIsAlarm = false;
}
if (needAlarm)
{
HTAlarm();
}
}
}
catch (Exception ex)
{
LogUtil.error("HumidityProcess出错:" + ex.ToString());
}
}
static void HTAlarm()
{
if (TempOrHumidityIsAlarm)
{
return;
}
TempAlarmTime = DateTime.Now;
TempOrHumidityIsAlarm = true;
}
internal static bool NeedGetTem()
{
if (Max_Humidity <= 0 || (Max_Temperature <= 0))
{
return true;
}
return false;
}
#endregion
}
public class HumitureParam
{
public HumitureParam(string clientipe, string add, string pwd, double wendu, double shidu, DateTime updateTime)
{
this.IpAddress = clientipe;
this.DeviceAddress = add;
this.Password = pwd;
this.Temperate = wendu;
this.Humidity = shidu;
this.UpdateTime = updateTime;
}
//获取平均值时使用此 参数,只做显示用
public HumitureParam(double wendu, double shidu, double oxygenV)
{
this.IpAddress = "";
this.DeviceAddress = "";
this.Password = "";
this.Temperate = wendu;
this.Humidity = shidu;
this.OxygenV = oxygenV;
this.UpdateTime = DateTime.Now;
}
/// <summary>
/// 判断值是否在有效期内。默认有效期是一分钟
/// </summary>
/// <returns></returns>
public bool IsValid()
{
TimeSpan span = DateTime.Now - UpdateTime;
if (span.TotalMinutes > 3)
{
return false;
}
return true;
}
/// <summary>
/// 更新时间
/// </summary>
public DateTime UpdateTime { get; set; }
/// <summary>
/// IP地址
/// </summary>
public string IpAddress { get; set; }
/// <summary>
/// 设备地址
/// </summary>
public string DeviceAddress { get; set; }
/// <summary>
/// 访问密码
/// </summary>
public string Password { get; set; }
/// <summary>
/// 温度
/// </summary>
public double Temperate { get; set; }
/// <summary>
/// 湿度
/// </summary>
public double Humidity { get; set; }
public double OxygenV { get; set; } = 100;
}
}