Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
李娜
/
SO664-HCSingleStore
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 66c7584e
由
LN
编写于
2021-03-19 15:50:01 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
服务器连接卡死修改
1 个父辈
034757b4
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
82 行增加
和
72 行删除
source/Common/util/HttpHelper.cs
source/Common/util/JsonHelper.cs
source/DeviceLibrary/acSingleStore/BoxBean.cs
source/DeviceLibrary/acSingleStore/HumitureBean.cs
source/Common/util/HttpHelper.cs
查看文件 @
66c7584
...
@@ -13,48 +13,44 @@ using System.Security.Cryptography.X509Certificates;
...
@@ -13,48 +13,44 @@ using System.Security.Cryptography.X509Certificates;
using
System.Reflection
;
using
System.Reflection
;
using
log4net
;
using
log4net
;
using
System.Net.NetworkInformation
;
using
System.Net.NetworkInformation
;
using
System.Threading
;
namespace
OnlineStore.Common
namespace
OnlineStore.Common
{
{
public
class
HttpHelper
public
class
HttpHelper
{
{
public
static
Operation
PostOP
(
string
url
,
Operation
operation
,
out
bool
isTimeOut
)
private
static
int
isLog
=
ConfigAppSettings
.
GetIntValue
(
Setting_Init
.
Server_Log_Open
);
private
static
object
lockObj
=
""
;
public
static
Operation
PostOP
(
string
url
,
Operation
operation
,
int
lockTime
,
out
bool
isTimeOut
)
{
{
isTimeOut
=
false
;
isTimeOut
=
false
;
try
if
(
Monitor
.
TryEnter
(
lockObj
,
lockTime
))
{
{
string
json
=
""
;
try
try
{
{
json
=
JsonHelper
.
SerializeObject
(
operation
);
string
json
=
JsonHelper
.
SerializeObject
(
operation
);
string
result
=
PostJson
(
url
,
json
,
Encoding
.
UTF8
,
out
isTimeOut
);
if
(!
string
.
IsNullOrEmpty
(
result
))
{
return
JsonHelper
.
DeserializeJsonToObject
<
Operation
>(
result
);
}
}
}
catch
(
Exception
ex
)
catch
(
Exception
ex
)
{
{
LogUtil
.
error
(
"
JsonHelper.SerializeObject(operation) 出错【operation.op="
+
operation
.
op
+
"】
"
+
ex
);
LogUtil
.
error
(
"
Post 出错【operation.op="
+
operation
.
op
+
"】:
"
+
ex
);
}
}
finally
string
result
=
PostJson
(
url
,
json
,
Encoding
.
UTF8
,
out
isTimeOut
);
if
(!
string
.
IsNullOrEmpty
(
result
))
{
{
try
Monitor
.
Exit
(
lockObj
);
{
}
return
JsonHelper
.
DeserializeJsonToObject
<
Operation
>(
result
);
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"JsonHelper.DeserializeJsonToObject 出错【result="
+
result
+
"】"
+
ex
);
}
}
}
}
catch
(
Exception
ex
)
else
if
(
lockTime
>
10
)
{
{
LogUtil
.
error
(
"Post 出错【operation.op="
+
operation
.
op
+
"】:"
+
ex
);
string
json
=
JsonHelper
.
SerializeObject
(
operation
);
LogUtil
.
error
(
" PostOP "
+
lockTime
+
" send "
+
json
+
" TryEnter fail "
);
}
}
return
null
;
return
null
;
}
}
private
static
int
isLog
=
ConfigAppSettings
.
GetIntValue
(
Setting_Init
.
Server_Log_Open
);
private
static
string
PostJson
(
string
url
,
string
paramData
,
Encoding
encoding
,
out
bool
IsTimeOut
)
private
static
string
PostJson
(
string
url
,
string
paramData
,
Encoding
encoding
,
out
bool
IsTimeOut
)
{
{
IsTimeOut
=
false
;
IsTimeOut
=
false
;
...
@@ -62,7 +58,7 @@ namespace OnlineStore.Common
...
@@ -62,7 +58,7 @@ namespace OnlineStore.Common
{
{
LogUtil
.
info
(
"给服务器发送数据【"
+
paramData
+
"】 "
);
LogUtil
.
info
(
"给服务器发送数据【"
+
paramData
+
"】 "
);
}
}
DateTime
startime
=
DateTime
.
Now
;
string
result
=
""
;
string
result
=
""
;
if
(
url
.
ToLower
().
IndexOf
(
"https"
,
System
.
StringComparison
.
Ordinal
)
>
-
1
)
if
(
url
.
ToLower
().
IndexOf
(
"https"
,
System
.
StringComparison
.
Ordinal
)
>
-
1
)
...
@@ -88,10 +84,11 @@ namespace OnlineStore.Common
...
@@ -88,10 +84,11 @@ namespace OnlineStore.Common
catch
(
Exception
e
)
catch
(
Exception
e
)
{
{
LogUtil
.
error
(
"POST ERROR:"
+
e
.
ToString
(),
1
);
LogUtil
.
error
(
"POST ERROR:"
+
e
.
ToString
(),
1
);
}
}
TimeSpan
span
=
DateTime
.
Now
-
startime
;
if
(
isLog
==
1
)
if
(
isLog
==
1
)
{
{
LogUtil
.
info
(
"收到服务器数据【"
+
result
+
"】"
);
LogUtil
.
info
(
"收到服务器数据
["
+
span
.
ToString
()+
"]
【"
+
result
+
"】"
);
}
}
return
result
;
return
result
;
}
}
...
...
source/Common/util/JsonHelper.cs
查看文件 @
66c7584
using
System.Collections.Generic
;
using
System
;
using
System.Collections.Generic
;
using
System.IO
;
using
System.IO
;
using
Newtonsoft.Json
;
using
Newtonsoft.Json
;
...
@@ -9,24 +10,34 @@ namespace OnlineStore.Common
...
@@ -9,24 +10,34 @@ namespace OnlineStore.Common
/// </summary>
/// </summary>
public
class
JsonHelper
public
class
JsonHelper
{
{
/// <summary>
/// <summary>
/// 将对象序列化为JSON格式
/// 将对象序列化为JSON格式
/// </summary>
/// </summary>
/// <param name="o">对象</param>
/// <param name="o">对象</param>
/// <returns>json字符串</returns>
/// <returns>json字符串</returns>
public
static
string
SerializeObject
(
object
o
)
public
static
string
SerializeObject
(
object
o
)
{
try
{
{
string
json
=
JsonConvert
.
SerializeObject
(
o
);
string
json
=
JsonConvert
.
SerializeObject
(
o
);
return
json
;
return
json
;
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
"JsonHelper.SerializeObject error【"
+
o
.
ToString
()
+
"】"
+
ex
);
}
return
""
;
}
/// <summary>
/// <summary>
/// 解析JSON字符串生成对象实体
/// 解析JSON字符串生成对象实体
/// </summary>
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="json">json字符串(eg.{"ID":"112","Name":"石子儿"})</param>
/// <param name="json">json字符串(eg.{"ID":"112","Name":"石子儿"})</param>
/// <returns>对象实体</returns>
/// <returns>对象实体</returns>
public
static
T
DeserializeJsonToObject
<
T
>(
string
json
)
where
T
:
class
public
static
T
DeserializeJsonToObject
<
T
>(
string
json
)
where
T
:
class
{
try
{
{
JsonSerializer
serializer
=
new
JsonSerializer
();
JsonSerializer
serializer
=
new
JsonSerializer
();
StringReader
sr
=
new
StringReader
(
json
);
StringReader
sr
=
new
StringReader
(
json
);
...
@@ -34,14 +45,20 @@ namespace OnlineStore.Common
...
@@ -34,14 +45,20 @@ namespace OnlineStore.Common
T
t
=
o
as
T
;
T
t
=
o
as
T
;
return
t
;
return
t
;
}
}
catch
(
Exception
ex
)
{
LogUtil
.
error
(
" JsonHelper.DeserializeJsonToObject error【"
+
json
+
"】"
+
ex
);
}
return
null
;
}
/// <summary>
/// <summary>
/// 解析JSON数组生成对象实体集合
/// 解析JSON数组生成对象实体集合
/// </summary>
/// </summary>
/// <typeparam name="T">对象类型</typeparam>
/// <typeparam name="T">对象类型</typeparam>
/// <param name="json">json数组字符串(eg.[{"ID":"112","Name":"石子儿"}])</param>
/// <param name="json">json数组字符串(eg.[{"ID":"112","Name":"石子儿"}])</param>
/// <returns>对象实体集合</returns>
/// <returns>对象实体集合</returns>
public
static
List
<
T
>
DeserializeJsonToList
<
T
>(
string
json
)
where
T
:
class
public
static
List
<
T
>
DeserializeJsonToList
<
T
>(
string
json
)
where
T
:
class
{
{
JsonSerializer
serializer
=
new
JsonSerializer
();
JsonSerializer
serializer
=
new
JsonSerializer
();
StringReader
sr
=
new
StringReader
(
json
);
StringReader
sr
=
new
StringReader
(
json
);
...
...
source/DeviceLibrary/acSingleStore/BoxBean.cs
查看文件 @
66c7584
...
@@ -983,7 +983,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -983,7 +983,7 @@ namespace OnlineStore.DeviceLibrary
for
(
int
i
=
1
;
i
<=
3
;
i
++)
for
(
int
i
=
1
;
i
<=
3
;
i
++)
{
{
bool
timeOut
=
false
;
bool
timeOut
=
false
;
Operation
resultOperation
=
HttpHelper
.
PostOP
(
StoreManager
.
GetPostApi
(
server
),
operation
,
out
timeOut
);
Operation
resultOperation
=
HttpHelper
.
PostOP
(
StoreManager
.
GetPostApi
(
server
),
operation
,
2000
,
out
timeOut
);
if
(
timeOut
)
if
(
timeOut
)
{
{
LogUtil
.
info
(
logName
+
" 第"
+
i
+
"次发送超时 "
);
LogUtil
.
info
(
logName
+
" 第"
+
i
+
"次发送超时 "
);
...
@@ -1070,7 +1070,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -1070,7 +1070,7 @@ namespace OnlineStore.DeviceLibrary
if
(
isInProcess
)
if
(
isInProcess
)
{
{
TimeSpan
span
=
DateTime
.
Now
-
lastConTime
;
TimeSpan
span
=
DateTime
.
Now
-
lastConTime
;
if
(
span
.
TotalSeconds
<
3
)
if
(
span
.
TotalSeconds
<
10
)
{
{
return
;
return
;
}
}
...
@@ -1226,7 +1226,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -1226,7 +1226,7 @@ namespace OnlineStore.DeviceLibrary
}
}
string
server
=
ConfigAppSettings
.
GetValue
(
Setting_Init
.
http_server
);
string
server
=
ConfigAppSettings
.
GetValue
(
Setting_Init
.
http_server
);
bool
isTimeout
=
false
;
bool
isTimeout
=
false
;
Operation
resultOperation
=
HttpHelper
.
PostOP
(
StoreManager
.
GetPostApi
(
server
),
lineOperation
,
out
isTimeout
);
Operation
resultOperation
=
HttpHelper
.
PostOP
(
StoreManager
.
GetPostApi
(
server
),
lineOperation
,
10
,
out
isTimeout
);
//发送状态信息到服务器
//发送状态信息到服务器
if
(
resultOperation
==
null
||
(
resultOperation
.
op
<=
0
))
if
(
resultOperation
==
null
||
(
resultOperation
.
op
<=
0
))
...
@@ -1251,9 +1251,9 @@ namespace OnlineStore.DeviceLibrary
...
@@ -1251,9 +1251,9 @@ namespace OnlineStore.DeviceLibrary
LogUtil
.
error
(
Name
+
"收到服务器命令:op="
+
resultOperation
.
op
+
",未找到对应处理"
);
LogUtil
.
error
(
Name
+
"收到服务器命令:op="
+
resultOperation
.
op
+
",未找到对应处理"
);
}
}
TimeSpan
span
=
DateTime
.
Now
-
time
;
TimeSpan
span
=
DateTime
.
Now
-
time
;
if
(
span
.
TotalMilliseconds
>
10
)
if
(
span
.
TotalMilliseconds
>
10
0
)
{
{
LogInfo
(
"执行TimerProcess 共处理了
【"
+
span
.
TotalMilliseconds
+
"】毫秒"
);
LogInfo
(
"执行 SendLineStatus 共
【"
+
span
.
TotalMilliseconds
+
"】毫秒"
);
}
}
}
}
...
@@ -1350,9 +1350,9 @@ namespace OnlineStore.DeviceLibrary
...
@@ -1350,9 +1350,9 @@ namespace OnlineStore.DeviceLibrary
}
}
TimeSpan
span
=
DateTime
.
Now
-
time
;
TimeSpan
span
=
DateTime
.
Now
-
time
;
if
(
span
.
TotalMilliseconds
>
10
)
if
(
span
.
TotalMilliseconds
>
10
0
)
{
{
LogInfo
(
"执行TimerProcess 共处理了
【"
+
span
.
TotalMilliseconds
+
"】毫秒"
);
LogInfo
(
"执行 ReviceOutStoreProcess 共
【"
+
span
.
TotalMilliseconds
+
"】毫秒"
);
}
}
}
}
}
}
...
...
source/DeviceLibrary/acSingleStore/HumitureBean.cs
查看文件 @
66c7584
...
@@ -18,14 +18,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -18,14 +18,7 @@ namespace OnlineStore.DeviceLibrary
this
.
Name
=
deviceName
;
this
.
Name
=
deviceName
;
this
.
PortName
=
port
;
this
.
PortName
=
port
;
}
}
public
HumitureParam
QueryData
()
{
HumitureParam
param
=
HumitureController
.
QueryData
(
PortName
);
LastData
=
param
;
return
LastData
;
}
internal
void
ProcessHumidityCMD
(
Operation
resultOperation
)
internal
void
ProcessHumidityCMD
(
Operation
resultOperation
)
{
{
Dictionary
<
string
,
string
>
data
=
resultOperation
.
data
;
Dictionary
<
string
,
string
>
data
=
resultOperation
.
data
;
...
@@ -72,19 +65,22 @@ namespace OnlineStore.DeviceLibrary
...
@@ -72,19 +65,22 @@ namespace OnlineStore.DeviceLibrary
{
{
try
try
{
{
if
((
DateTime
.
Now
-
preLogTime
).
TotalSeconds
>
(
5
+
box
.
DeviceID
))
if
((
DateTime
.
Now
-
preLogTime
).
TotalSeconds
>
(
3
+
box
.
DeviceID
))
{
{
preLogTime
=
DateTime
.
Now
;
preLogTime
=
DateTime
.
Now
;
HumitureParam
param
=
QueryData
();
HumitureParam
param
=
HumitureController
.
QueryData
(
PortName
);
LastData
=
param
;
double
humidity
=
0
;
double
humidity
=
0
;
double
temp
=
0
;
double
temp
=
0
;
if
(
param
!
=
null
)
if
(
param
=
=
null
)
{
{
humidity
=
param
.
Humidity
;
return
;
temp
=
param
.
Temperate
;
currTempStr
=
Name
+
(
"湿度:"
+
humidity
.
ToString
()
+
",温度:"
+
temp
);
}
}
humidity
=
param
.
Humidity
;
temp
=
param
.
Temperate
;
currTempStr
=
Name
+
(
"湿度:"
+
humidity
.
ToString
()
+
",温度:"
+
temp
);
double
currMaxHumidity
=
param
.
Humidity
;
double
currMaxHumidity
=
param
.
Humidity
;
float
startBlowHumidity
=
Max_Humidity
-
StartBlowValue
;
float
startBlowHumidity
=
Max_Humidity
-
StartBlowValue
;
float
stopBlowHumidity
=
Max_Humidity
-
StopBlowValue
;
float
stopBlowHumidity
=
Max_Humidity
-
StopBlowValue
;
...
@@ -98,7 +94,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -98,7 +94,7 @@ namespace OnlineStore.DeviceLibrary
else
if
(
temp
>
Max_Temperature
&&
Max_Temperature
>
0
)
else
if
(
temp
>
Max_Temperature
&&
Max_Temperature
>
0
)
{
{
LogUtil
.
info
(
Name
+
"当前温度【"
+
param
.
Temperate
+
"】超过最高温度【"
+
Max_Temperature
+
"】,开始报警!"
);
LogUtil
.
info
(
Name
+
"当前温度【"
+
param
.
Temperate
+
"】超过最高温度【"
+
Max_Temperature
+
"】,开始报警!"
);
needAlarm
=
true
;
needAlarm
=
true
;
//box.IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
//box.IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
}
}
else
if
(
temp
<
Max_Temperature
)
else
if
(
temp
<
Max_Temperature
)
...
@@ -106,7 +102,7 @@ namespace OnlineStore.DeviceLibrary
...
@@ -106,7 +102,7 @@ namespace OnlineStore.DeviceLibrary
if
(
IsInBlowing
.
Equals
(
false
)
&&
TempOrHumidityIsAlarm
)
if
(
IsInBlowing
.
Equals
(
false
)
&&
TempOrHumidityIsAlarm
)
{
{
LogUtil
.
info
(
Name
+
"不在吹气中,且当前温度【"
+
param
.
Temperate
+
"】低于【"
+
Max_Temperature
+
"】,关闭报警!"
);
LogUtil
.
info
(
Name
+
"不在吹气中,且当前温度【"
+
param
.
Temperate
+
"】低于【"
+
Max_Temperature
+
"】,关闭报警!"
);
TempOrHumidityIsAlarm
=
false
;
TempOrHumidityIsAlarm
=
false
;
//box.IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
//box.IOMove(IO_Type.StartOrStopBlow, IO_VALUE.LOW);
}
}
}
}
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论