Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张东亮
/
SO1057-XLRStore
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 88993a4a
由
张东亮
编写于
2025-12-15 16:47:12 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
温湿度读取失败1,不更新数据
1 个父辈
f3609f30
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
133 行增加
和
127 行删除
source/DeviceLibrary/storeBean/boxBean/Humiture/HumitureBean.cs
source/DeviceLibrary/storeBean/boxBean/Humiture/HumitureController.cs
source/DeviceLibrary/storeBean/boxBean/Humiture/HumitureBean.cs
查看文件 @
88993a4
...
...
@@ -29,21 +29,21 @@ namespace OnlineStore.DeviceLibrary
}
public
HumitureParam
QueryData
()
{
HumitureParam
param
=
HumitureController
.
QueryData
(
PortName
);
updateData
(
PortName
,
param
);
return
param
;
bool
rtn
=
HumitureController
.
QueryData
(
PortName
,
out
HumitureParam
param
);
return
updateData
(
PortName
,
rtn
,
param
);
}
static
void
updateData
(
string
port
,
HumitureParam
param
)
static
HumitureParam
updateData
(
string
port
,
bool
ok
,
HumitureParam
param
)
{
var
find
=
LastData
.
Find
(
s
=>
port
.
Equals
(
s
.
DeviceAddress
));
if
(
find
!=
null
)
if
(
ok
&&
find
!=
null
)
{
find
.
Temperate
=
param
.
Temperate
;
find
.
UpdateTime
=
param
.
UpdateTime
;
find
.
Humidity
=
param
.
Humidity
;
find
.
OxygenV
=
param
.
OxygenV
;
return
find
;
}
return
param
;
}
public
static
double
GetMinOxygenV
()
{
...
...
source/DeviceLibrary/storeBean/boxBean/Humiture/HumitureController.cs
查看文件 @
88993a4
...
...
@@ -44,8 +44,8 @@ namespace OnlineStore.DeviceLibrary
if
(
sb
.
openPort
())
{
serialBeanMap
.
Add
(
port
,
sb
);
var
ht
=
HumitureController
.
QueryData
(
por
t
);
LogUtil
.
info
(
LogName
+
"串口"
+
port
+
"打开成功!
温度:"
+
ht
.
Temperate
+
",湿度:"
+
ht
.
Humidity
);
var
rtn
=
HumitureController
.
QueryData
(
port
,
out
HumitureParam
h
t
);
LogUtil
.
info
(
LogName
+
"串口"
+
port
+
$
"打开成功!{rtn}
温度:"
+
ht
.
Temperate
+
",湿度:"
+
ht
.
Humidity
);
return
true
;
}
else
...
...
@@ -99,9 +99,9 @@ namespace OnlineStore.DeviceLibrary
return
null
;
}
// public static ASTemperateParam LastData = new ASTemperateParam(0, 0);
public
static
HumitureParam
QueryData
(
string
port
)
public
static
bool
QueryData
(
string
port
,
out
HumitureParam
param
)
{
HumitureParam
param
=
new
HumitureParam
(
0
,
0
,
100
);
param
=
new
HumitureParam
(
0
,
0
,
100
);
param
.
DeviceAddress
=
port
;
List
<
double
>
data
=
queryData
(
port
);
if
(
data
.
Count
.
Equals
(
3
))
...
...
@@ -117,7 +117,7 @@ namespace OnlineStore.DeviceLibrary
// else
// data[0] += humidityadjust;
//}
data
[
0
]
=
ProcessHumity
(
port
,
data
[
0
]);
data
[
0
]
=
ProcessHumity
(
port
,
data
[
0
]);
//double tempadjust = (double)ConfigAppSettings.GetNumValue(Setting_Init.Device_TemptureAdjust);
//double templimited = (double)ConfigAppSettings.GetNumValue(Setting_Init.Device_TemptureLimited);
//if (tempadjust != 0 && templimited != 0)
...
...
@@ -129,21 +129,26 @@ namespace OnlineStore.DeviceLibrary
// else
// data[1] += tempadjust;
//}
if
(
data
[
1
]>
80
)
data
[
1
]
=
ProcessTemp
(
port
,
data
[
1
]);
var
maxTemp
=
ConfigHelper
.
Config
.
Get
(
"MaxTempThreshold"
,
60
);
var
minTemp
=
ConfigHelper
.
Config
.
Get
(
"MinTempThreshold"
,
0
);
if
(
data
[
1
]
>=
maxTemp
||
data
[
1
]
<=
minTemp
)
//温度
{
data
[
1
]
=
0
;
return
false
;
}
if
(
data
[
0
]
>
100
)
var
maxHum
=
ConfigHelper
.
Config
.
Get
(
"MaxHumidityThreshold"
,
100
);
var
minHum
=
ConfigHelper
.
Config
.
Get
(
"MinHumidityThreshold"
,
0
);
if
(
data
[
0
]
>=
maxHum
||
data
[
0
]
<=
minHum
)
//湿度
{
data
[
0
]
=
0
;
return
false
;
}
data
[
1
]
=
ProcessTemp
(
port
,
data
[
1
]);
param
=
new
HumitureParam
(
data
[
1
],
data
[
0
],
data
[
2
]);
return
true
;
}
//校准温湿度
return
param
;
return
false
;
}
/// <summary>
/// 温度数据处理
...
...
@@ -182,7 +187,7 @@ namespace OnlineStore.DeviceLibrary
/// </summary>
/// <param name="nowHumity"></param>
/// <returns></returns>
private
static
double
ProcessHumity
(
string
port
,
double
nowHumity
)
private
static
double
ProcessHumity
(
string
port
,
double
nowHumity
)
{
double
temp
=
nowHumity
;
double
minVal
=
ConfigHelper
.
Config
.
Get
(
"HumidityThreshold_Min"
,
5
);
...
...
@@ -242,123 +247,124 @@ namespace OnlineStore.DeviceLibrary
//LogUtil.debug("温湿度控制器发送数据:" + str);
byte
[]
reviceData
=
new
byte
[
9
];
bool
isOk
=
false
;
sb
.
SendCommand
(
sendData
,
ref
reviceData
,
100
,
out
isOk
);
sb
.
SendCommand
(
sendData
,
ref
reviceData
,
200
,
out
isOk
);
LogUtil
.
debug
(
$
"{port}({isOk}):【{AcSerialBean.byteToHexStr(sendData)}】【{AcSerialBean.byteToHexStr(reviceData)}】"
);
return
getReviceData
(
reviceData
);
}
public
static
int
QueryHistoryCount
(
string
port
)
{
AcSerialBean
sb
=
GetSerialBean
(
port
);
if
(
sb
==
null
||
HumitureControllerType
.
Equals
(
2
).
Equals
(
false
))
{
return
-
1
;
}
byte
[]
sendData
=
new
byte
[
8
];
sendData
[
0
]
=
0x01
;
sendData
[
1
]
=
0x04
;
sendData
[
2
]
=
0x20
;
sendData
[
3
]
=
0x00
;
byte
[]
addrByte
=
AcSerialBean
.
StringToByte
(
"2000"
);
if
(
addrByte
.
Length
==
1
)
{
sendData
[
2
]
=
0x00
;
sendData
[
3
]
=
addrByte
[
0
];
}
else
if
(
addrByte
.
Length
==
2
)
{
sendData
[
3
]
=
addrByte
[
1
];
sendData
[
2
]
=
addrByte
[
0
];
}
sendData
[
4
]
=
0x00
;
sendData
[
5
]
=
0x02
;
sendData
[
6
]
=
0x00
;
sendData
[
7
]
=
0x00
;
sendData
=
buildCheckData
(
sendData
,
sendData
.
Length
-
2
);
string
str
=
AcSerialBean
.
byteToHexStr
(
sendData
);
// LogUtil.debug("温湿度控制器发送数据:" + str);
byte
[]
reviceData
=
new
byte
[
9
];
bool
isOk
=
false
;
sb
.
SendCommand
(
sendData
,
ref
reviceData
,
100
,
out
isOk
);
return
getReviceIntData
(
reviceData
);
}
public
static
int
QueryCurrCount
(
string
port
)
{
AcSerialBean
sb
=
GetSerialBean
(
port
);
if
(
sb
==
null
||
HumitureControllerType
.
Equals
(
2
).
Equals
(
false
))
{
return
-
1
;
}
byte
[]
sendData
=
new
byte
[
8
];
sendData
[
0
]
=
0x01
;
sendData
[
1
]
=
0x04
;
sendData
[
2
]
=
0x20
;
sendData
[
3
]
=
0x02
;
sendData
[
4
]
=
0x00
;
sendData
[
5
]
=
0x02
;
sendData
[
6
]
=
0x00
;
sendData
[
7
]
=
0x00
;
sendData
=
buildCheckData
(
sendData
,
sendData
.
Length
-
2
);
string
str
=
AcSerialBean
.
byteToHexStr
(
sendData
);
//LogUtil.debug("温湿度控制器发送数据:" + str);
byte
[]
reviceData
=
new
byte
[
9
];
bool
isOk
=
false
;
sb
.
SendCommand
(
sendData
,
ref
reviceData
,
100
,
out
isOk
);
return
getReviceIntData
(
reviceData
);
}
public
static
List
<
object
>
QueryHistory
(
string
port
)
{
List
<
object
>
list
=
new
List
<
object
>();
AcSerialBean
sb
=
GetSerialBean
(
port
);
if
(
sb
==
null
||
HumitureControllerType
.
Equals
(
2
).
Equals
(
false
))
{
return
list
;
}
byte
[]
sendData
=
new
byte
[
8
];
sendData
[
0
]
=
0x01
;
sendData
[
1
]
=
0x04
;
sendData
[
2
]
=
0x20
;
sendData
[
3
]
=
0x04
;
sendData
[
4
]
=
0x00
;
sendData
[
5
]
=
0x05
;
sendData
[
6
]
=
0x00
;
sendData
[
7
]
=
0x00
;
sendData
=
buildCheckData
(
sendData
,
sendData
.
Length
-
2
);
string
str
=
AcSerialBean
.
byteToHexStr
(
sendData
);
//LogUtil.debug("温湿度控制器发送数据:" + str);
byte
[]
reviceData
=
new
byte
[
15
];
bool
isOk
=
false
;
sb
.
SendCommand
(
sendData
,
ref
reviceData
,
100
,
out
isOk
);
//
public static int QueryHistoryCount(string port)
//
{
//
AcSerialBean sb = GetSerialBean(port);
//
if (sb == null || HumitureControllerType.Equals(2).Equals(false))
//
{
//
return -1;
//
}
//
byte[] sendData = new byte[8];
//
sendData[0] = 0x01;
//
sendData[1] = 0x04;
//
sendData[2] = 0x20;
//
sendData[3] = 0x00;
//
byte[] addrByte = AcSerialBean.StringToByte("2000");
//
if (addrByte.Length == 1)
//
{
//
sendData[2] = 0x00;
//
sendData[3] = addrByte[0];
//
}
//
else if (addrByte.Length == 2)
//
{
//
sendData[3] = addrByte[1];
//
sendData[2] = addrByte[0];
//
}
//
sendData[4] = 0x00;
//
sendData[5] = 0x02;
//
sendData[6] = 0x00;
//
sendData[7] = 0x00;
//
sendData = buildCheckData(sendData, sendData.Length - 2);
//
string str = AcSerialBean.byteToHexStr(sendData);
//
// LogUtil.debug("温湿度控制器发送数据:" + str);
//
byte[] reviceData = new byte[9];
//
bool isOk = false;
//
sb.SendCommand(sendData, ref reviceData, 100, out isOk);
//
return getReviceIntData(reviceData);
//
}
//
public static int QueryCurrCount(string port)
//
{
//
AcSerialBean sb = GetSerialBean(port);
//
if (sb == null || HumitureControllerType.Equals(2).Equals(false))
//
{
//
return -1;
//
}
//
byte[] sendData = new byte[8];
//
sendData[0] = 0x01;
//
sendData[1] = 0x04;
//
sendData[2] = 0x20;
//
sendData[3] = 0x02;
//
sendData[4] = 0x00;
//
sendData[5] = 0x02;
//
sendData[6] = 0x00;
//
sendData[7] = 0x00;
//
sendData = buildCheckData(sendData, sendData.Length - 2);
//
string str = AcSerialBean.byteToHexStr(sendData);
//
//LogUtil.debug("温湿度控制器发送数据:" + str);
//
byte[] reviceData = new byte[9];
//
bool isOk = false;
//
sb.SendCommand(sendData, ref reviceData, 100, out isOk);
//
return getReviceIntData(reviceData);
//
}
//
public static List<object> QueryHistory(string port)
//
{
//
List<object> list = new List<object>();
//
AcSerialBean sb = GetSerialBean(port);
//
if (sb == null || HumitureControllerType.Equals(2).Equals(false))
//
{
//
return list;
//
}
//
byte[] sendData = new byte[8];
//
sendData[0] = 0x01;
//
sendData[1] = 0x04;
//
sendData[2] = 0x20;
//
sendData[3] = 0x04;
//
sendData[4] = 0x00;
//
sendData[5] = 0x05;
//
sendData[6] = 0x00;
//
sendData[7] = 0x00;
//
sendData = buildCheckData(sendData, sendData.Length - 2);
//
string str = AcSerialBean.byteToHexStr(sendData);
//
//LogUtil.debug("温湿度控制器发送数据:" + str);
//
byte[] reviceData = new byte[15];
//
bool isOk = false;
//
sb.SendCommand(sendData, ref reviceData, 100, out isOk);
try
{
if
(
reviceData
!=
null
&&
reviceData
.
Length
>=
9
)
{
//
try
//
{
//
if (reviceData != null && reviceData.Length >= 9)
//
{
string
temp
=
String
.
Format
(
"{0:X2}"
,
reviceData
[
3
])
+
String
.
Format
(
"{0:X2}"
,
reviceData
[
4
]);
string
hum
=
String
.
Format
(
"{0:X2}"
,
reviceData
[
5
])
+
String
.
Format
(
"{0:X2}"
,
reviceData
[
6
]);
double
tempV
=
(
double
)
Convert
.
ToInt32
(
temp
,
16
)
/
10
;
double
humV
=
(
double
)
Convert
.
ToInt32
(
hum
,
16
)
/
10
;
//
string temp = String.Format("{0:X2}", reviceData[3]) + String.Format("{0:X2}", reviceData[4]);
//
string hum = String.Format("{0:X2}", reviceData[5]) + String.Format("{0:X2}", reviceData[6]);
//
double tempV = (double)Convert.ToInt32(temp, 16) / 10;
//
double humV = (double)Convert.ToInt32(hum, 16) / 10;
int
year
=
Convert
.
ToInt32
(
String
.
Format
(
"{0:X2}"
,
reviceData
[
7
]),
16
);
int
mouth
=
Convert
.
ToInt32
(
String
.
Format
(
"{0:X2}"
,
reviceData
[
8
]),
16
);
int
day
=
Convert
.
ToInt32
(
String
.
Format
(
"{0:X2}"
,
reviceData
[
9
]),
16
);
int
hour
=
Convert
.
ToInt32
(
String
.
Format
(
"{0:X2}"
,
reviceData
[
10
]),
16
);
int
minute
=
Convert
.
ToInt32
(
String
.
Format
(
"{0:X2}"
,
reviceData
[
11
]),
16
);
int
second
=
Convert
.
ToInt32
(
String
.
Format
(
"{0:X2}"
,
reviceData
[
12
]),
16
);
//
int year = Convert.ToInt32(String.Format("{0:X2}", reviceData[7]), 16);
//
int mouth = Convert.ToInt32(String.Format("{0:X2}", reviceData[8]), 16);
//
int day = Convert.ToInt32(String.Format("{0:X2}", reviceData[9]), 16);
//
int hour = Convert.ToInt32(String.Format("{0:X2}", reviceData[10]), 16);
//
int minute = Convert.ToInt32(String.Format("{0:X2}", reviceData[11]), 16);
//
int second = Convert.ToInt32(String.Format("{0:X2}", reviceData[12]), 16);
DateTime
time
=
new
DateTime
(
year
,
mouth
,
day
,
hour
,
minute
,
second
);
list
.
Add
(
tempV
);
list
.
Add
(
humV
);
list
.
Add
(
time
);
}
}
catch
(
Exception
ex
)
{
LogUtil
.
info
(
LogName
+
"转换出错:"
+
ex
.
ToString
());
}
return
list
;
}
//
DateTime time = new DateTime(year, mouth, day, hour, minute, second);
//
list.Add(tempV);
//
list.Add(humV);
//
list.Add(time);
//
}
//
}
//
catch (Exception ex)
//
{
//
LogUtil.info(LogName + "转换出错:" + ex.ToString());
//
}
//
return list;
//
}
private
static
byte
[]
buildCheckData
(
byte
[]
sendData
,
int
length
)
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论