Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
张东亮
/
SO1057-XLRStore
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit e31bcddb
由
张东亮
编写于
2025-08-27 12:19:46 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
温度后台配置修改
1 个父辈
61eae5e4
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
34 行增加
和
26 行删除
source/DeviceLibrary/storeBean/boxBean/Humiture/HumitureController.cs
source/DeviceLibrary/storeBean/boxBean/Humiture/HumitureController.cs
查看文件 @
e31bcdd
...
@@ -5,7 +5,7 @@ using System.Collections.Generic;
...
@@ -5,7 +5,7 @@ using System.Collections.Generic;
using
System.IO.Ports
;
using
System.IO.Ports
;
using
System.Linq
;
using
System.Linq
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Text
;
using
System.Text
;
namespace
OnlineStore.DeviceLibrary
namespace
OnlineStore.DeviceLibrary
{
{
...
@@ -15,16 +15,16 @@ namespace OnlineStore.DeviceLibrary
...
@@ -15,16 +15,16 @@ namespace OnlineStore.DeviceLibrary
public
class
HumitureController
public
class
HumitureController
{
{
//public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
//public static readonly ILog LOGGER = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private
static
int
bautRate
=
4800
;
//波特率
private
static
int
bautRate
=
4800
;
//波特率
private
static
Parity
parity
=
Parity
.
None
;
//校验位
private
static
Parity
parity
=
Parity
.
None
;
//校验位
private
static
int
dataBits
=
8
;
//数据位
private
static
int
dataBits
=
8
;
//数据位
private
static
StopBits
stopBits
=
StopBits
.
One
;
//停止位
private
static
StopBits
stopBits
=
StopBits
.
One
;
//停止位
private
static
string
LogName
=
""
;
private
static
string
LogName
=
""
;
private
static
Dictionary
<
string
,
AcSerialBean
>
serialBeanMap
=
new
Dictionary
<
string
,
AcSerialBean
>();
private
static
Dictionary
<
string
,
AcSerialBean
>
serialBeanMap
=
new
Dictionary
<
string
,
AcSerialBean
>();
public
static
int
HumitureControllerType
=
ConfigAppSettings
.
GetIntValue
(
Setting_Init
.
HumitureControllerType
);
public
static
int
HumitureControllerType
=
ConfigAppSettings
.
GetIntValue
(
Setting_Init
.
HumitureControllerType
);
public
static
bool
Init
(
string
port
)
public
static
bool
Init
(
string
port
)
{
{
if
(
serialBeanMap
.
ContainsKey
(
port
))
if
(
serialBeanMap
.
ContainsKey
(
port
))
...
@@ -32,31 +32,31 @@ namespace OnlineStore.DeviceLibrary
...
@@ -32,31 +32,31 @@ namespace OnlineStore.DeviceLibrary
return
true
;
return
true
;
}
}
LogName
=
"温湿度传感器["
+
port
+
"]"
;
LogName
=
"温湿度传感器["
+
port
+
"]"
;
AcSerialBean
sb
=
null
;
AcSerialBean
sb
=
null
;
if
(
HumitureControllerType
.
Equals
(
1
))
if
(
HumitureControllerType
.
Equals
(
1
))
{
{
bautRate
=
9600
;
//波特率
bautRate
=
9600
;
//波特率
}
}
sb
=
new
AcSerialBean
(
port
,
bautRate
,
parity
,
dataBits
,
stopBits
);
sb
=
new
AcSerialBean
(
port
,
bautRate
,
parity
,
dataBits
,
stopBits
);
try
try
{
{
if
(
sb
.
openPort
())
if
(
sb
.
openPort
())
{
{
serialBeanMap
.
Add
(
port
,
sb
);
serialBeanMap
.
Add
(
port
,
sb
);
var
ht
=
HumitureController
.
QueryData
(
port
);
var
ht
=
HumitureController
.
QueryData
(
port
);
LogUtil
.
info
(
LogName
+
"串口"
+
port
+
"打开成功!温度:"
+
ht
.
Temperate
+
",湿度:"
+
ht
.
Humidity
);
LogUtil
.
info
(
LogName
+
"串口"
+
port
+
"打开成功!温度:"
+
ht
.
Temperate
+
",湿度:"
+
ht
.
Humidity
);
return
true
;
return
true
;
}
}
else
else
{
{
LogUtil
.
error
(
LogName
+
"串口"
+
port
+
"打开失败!"
);
LogUtil
.
error
(
LogName
+
"串口"
+
port
+
"打开失败!"
);
return
false
;
return
false
;
}
}
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
LogUtil
.
error
(
"串口"
+
port
+
"打开失败:"
+
ex
.
ToString
());
LogUtil
.
error
(
"串口"
+
port
+
"打开失败:"
+
ex
.
ToString
());
}
}
return
true
;
return
true
;
}
}
...
@@ -98,12 +98,12 @@ namespace OnlineStore.DeviceLibrary
...
@@ -98,12 +98,12 @@ namespace OnlineStore.DeviceLibrary
}
}
return
null
;
return
null
;
}
}
// public static ASTemperateParam LastData = new ASTemperateParam(0, 0);
// public static ASTemperateParam LastData = new ASTemperateParam(0, 0);
public
static
HumitureParam
QueryData
(
string
port
)
public
static
HumitureParam
QueryData
(
string
port
)
{
{
HumitureParam
param
=
new
HumitureParam
(
0
,
0
,
100
);
HumitureParam
param
=
new
HumitureParam
(
0
,
0
,
100
);
param
.
DeviceAddress
=
port
;
param
.
DeviceAddress
=
port
;
List
<
double
>
data
=
queryData
(
port
);
List
<
double
>
data
=
queryData
(
port
);
if
(
data
.
Count
.
Equals
(
3
))
if
(
data
.
Count
.
Equals
(
3
))
{
{
//double humidityadjust = (double)ConfigAppSettings.GetNumValue(Setting_Init.Device_HumidityAdjust);
//double humidityadjust = (double)ConfigAppSettings.GetNumValue(Setting_Init.Device_HumidityAdjust);
...
@@ -129,9 +129,12 @@ namespace OnlineStore.DeviceLibrary
...
@@ -129,9 +129,12 @@ namespace OnlineStore.DeviceLibrary
// else
// else
// data[1] += tempadjust;
// data[1] += tempadjust;
//}
//}
data
[
1
]
=
ProcessTemp
(
data
[
1
]);
data
[
1
]
=
ProcessTemp
(
port
,
data
[
1
]);
param
=
new
HumitureParam
(
data
[
1
],
data
[
0
],
data
[
2
]);
param
=
new
HumitureParam
(
data
[
1
],
data
[
0
],
data
[
2
]);
}
}
//校准温湿度
return
param
;
return
param
;
}
}
/// <summary>
/// <summary>
...
@@ -139,7 +142,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -139,7 +142,7 @@ namespace OnlineStore.DeviceLibrary
/// </summary>
/// </summary>
/// <param name="nowTemp"></param>
/// <param name="nowTemp"></param>
/// <returns></returns>
/// <returns></returns>
private
static
double
ProcessTemp
(
double
nowTemp
)
private
static
double
ProcessTemp
(
string
port
,
double
nowTemp
)
{
{
double
temp
=
nowTemp
;
double
temp
=
nowTemp
;
double
minVal
=
5
;
//ConfigHelper.Config.Get("TempThreshold_Min", 5);
double
minVal
=
5
;
//ConfigHelper.Config.Get("TempThreshold_Min", 5);
...
@@ -158,7 +161,12 @@ namespace OnlineStore.DeviceLibrary
...
@@ -158,7 +161,12 @@ namespace OnlineStore.DeviceLibrary
{
{
temp
=
(
nowTemp
-
11
)
*
(
nowTemp
-
10
)
/
10
+
11
;
temp
=
(
nowTemp
-
11
)
*
(
nowTemp
-
10
)
/
10
+
11
;
}
}
else
{
var
calib
=
ConfigHelper
.
Config
.
Get
(
$
"TemptureCalib_{port}"
,
0
);
nowTemp
+=
calib
;
return
nowTemp
;
}
return
Math
.
Round
(
temp
,
1
);
return
Math
.
Round
(
temp
,
1
);
}
}
/// <summary>
/// <summary>
...
@@ -204,7 +212,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -204,7 +212,7 @@ namespace OnlineStore.DeviceLibrary
sendData
[
0
]
=
0x01
;
sendData
[
0
]
=
0x01
;
if
(
HumitureControllerType
.
Equals
(
1
))
if
(
HumitureControllerType
.
Equals
(
1
))
{
{
sendData
[
1
]
=
0x04
;
sendData
[
1
]
=
0x04
;
}
}
else
else
{
{
...
@@ -225,14 +233,14 @@ namespace OnlineStore.DeviceLibrary
...
@@ -225,14 +233,14 @@ namespace OnlineStore.DeviceLibrary
return
getReviceData
(
reviceData
);
return
getReviceData
(
reviceData
);
}
}
public
static
int
QueryHistoryCount
(
string
port
)
public
static
int
QueryHistoryCount
(
string
port
)
{
{
AcSerialBean
sb
=
GetSerialBean
(
port
);
AcSerialBean
sb
=
GetSerialBean
(
port
);
if
(
sb
==
null
||
HumitureControllerType
.
Equals
(
2
).
Equals
(
false
))
if
(
sb
==
null
||
HumitureControllerType
.
Equals
(
2
).
Equals
(
false
))
{
{
return
-
1
;
return
-
1
;
}
}
byte
[]
sendData
=
new
byte
[
8
];
byte
[]
sendData
=
new
byte
[
8
];
sendData
[
0
]
=
0x01
;
sendData
[
0
]
=
0x01
;
sendData
[
1
]
=
0x04
;
sendData
[
1
]
=
0x04
;
...
@@ -255,7 +263,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -255,7 +263,7 @@ namespace OnlineStore.DeviceLibrary
sendData
[
7
]
=
0x00
;
sendData
[
7
]
=
0x00
;
sendData
=
buildCheckData
(
sendData
,
sendData
.
Length
-
2
);
sendData
=
buildCheckData
(
sendData
,
sendData
.
Length
-
2
);
string
str
=
AcSerialBean
.
byteToHexStr
(
sendData
);
string
str
=
AcSerialBean
.
byteToHexStr
(
sendData
);
// LogUtil.debug("温湿度控制器发送数据:" + str);
// LogUtil.debug("温湿度控制器发送数据:" + str);
byte
[]
reviceData
=
new
byte
[
9
];
byte
[]
reviceData
=
new
byte
[
9
];
bool
isOk
=
false
;
bool
isOk
=
false
;
sb
.
SendCommand
(
sendData
,
ref
reviceData
,
100
,
out
isOk
);
sb
.
SendCommand
(
sendData
,
ref
reviceData
,
100
,
out
isOk
);
...
@@ -339,7 +347,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -339,7 +347,7 @@ namespace OnlineStore.DeviceLibrary
return
list
;
return
list
;
}
}
private
static
byte
[]
buildCheckData
(
byte
[]
sendData
,
int
length
)
private
static
byte
[]
buildCheckData
(
byte
[]
sendData
,
int
length
)
{
{
ushort
pChecksum
=
0
;
ushort
pChecksum
=
0
;
...
@@ -356,7 +364,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -356,7 +364,7 @@ namespace OnlineStore.DeviceLibrary
{
{
sendData
[
length
+
1
]
=
checkByte
[
0
];
sendData
[
length
+
1
]
=
checkByte
[
0
];
sendData
[
length
]
=
checkByte
[
1
];
sendData
[
length
]
=
checkByte
[
1
];
}
}
return
sendData
;
return
sendData
;
}
}
...
@@ -371,7 +379,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -371,7 +379,7 @@ namespace OnlineStore.DeviceLibrary
}
}
if
(
dataArray
.
Length
>=
9
)
if
(
dataArray
.
Length
>=
9
)
{
{
string
data
=
String
.
Format
(
"{0:X2}"
,
dataArray
[
5
])
+
String
.
Format
(
"{0:X2}"
,
dataArray
[
6
]
+
String
.
Format
(
"{0:X2}"
,
dataArray
[
3
])
+
String
.
Format
(
"{0:X2}"
,
dataArray
[
4
])
);
string
data
=
String
.
Format
(
"{0:X2}"
,
dataArray
[
5
])
+
String
.
Format
(
"{0:X2}"
,
dataArray
[
6
]
+
String
.
Format
(
"{0:X2}"
,
dataArray
[
3
])
+
String
.
Format
(
"{0:X2}"
,
dataArray
[
4
])
);
int
tempV
=
Convert
.
ToInt32
(
data
,
16
);
int
tempV
=
Convert
.
ToInt32
(
data
,
16
);
return
tempV
;
return
tempV
;
}
}
...
@@ -385,7 +393,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -385,7 +393,7 @@ namespace OnlineStore.DeviceLibrary
private
static
List
<
double
>
getReviceData
(
byte
[]
dataArray
)
private
static
List
<
double
>
getReviceData
(
byte
[]
dataArray
)
{
{
List
<
double
>
list
=
new
List
<
double
>();
List
<
double
>
list
=
new
List
<
double
>();
try
try
{
{
if
(
dataArray
==
null
)
if
(
dataArray
==
null
)
...
@@ -411,6 +419,6 @@ namespace OnlineStore.DeviceLibrary
...
@@ -411,6 +419,6 @@ namespace OnlineStore.DeviceLibrary
}
}
return
list
;
return
list
;
}
}
}
}
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论