Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
Z
zhmes-agecal
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
耿迪迪
zhmes-agecal
Commits
16a45a69
Commit
16a45a69
authored
Jun 05, 2025
by
wanghao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1 每次读取后 关闭 socket连接
parent
223e5917
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
50 deletions
+56
-50
ZhMesAgecalApplication.java
...dmin/src/main/java/com/zehong/ZhMesAgecalApplication.java
+2
-0
EquipmentDataCollection.java
...ong/web/controller/equipment/EquipmentDataCollection.java
+45
-47
ReceiverThread.java
...main/java/com/zehong/common/utils/TCP/ReceiverThread.java
+5
-1
TCPClient.java
.../src/main/java/com/zehong/common/utils/TCP/TCPClient.java
+4
-2
No files found.
zhmes-agecal-admin/src/main/java/com/zehong/ZhMesAgecalApplication.java
View file @
16a45a69
...
...
@@ -3,12 +3,14 @@ package com.zehong;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
/**
* 启动程序
*
* @author zehong
*/
@EnableScheduling
@SpringBootApplication
(
exclude
=
{
DataSourceAutoConfiguration
.
class
})
public
class
ZhMesAgecalApplication
{
...
...
zhmes-agecal-admin/src/main/java/com/zehong/web/controller/equipment/EquipmentDataCollection.java
View file @
16a45a69
...
...
@@ -53,59 +53,57 @@ public class EquipmentDataCollection {
log
.
error
(
"设备列表查询结果为空"
);
throw
new
Exception
(
"无设备信息!"
);
}
if
(
equipmentInfos
.
size
()
>
0
){
String
sendMsg
=
"00010000000601040000000A"
;
String
receiveMsg
;
String
sendMsg
=
"00010000000601040000000A"
;
String
receiveMsg
;
TEquipmentAlarmData
alarmData
=
new
TEquipmentAlarmData
();
for
(
TEquipmentInfo
info
:
equipmentInfos
){
/* 1.老化柜、标定柜通讯 */
receiveMsg
=
agingCabinetCommunication
(
info
,
sendMsg
);
if
(
receiveMsg
==
null
){
// 记录异常数据
alarmData
.
setfAlarmType
(
"01"
);
// 01.老化柜 02.标定柜 03.机械臂 04.老化层 05.点位
alarmData
.
setfEquipmentCode
(
info
.
getfEquipmentCode
());
alarmData
.
setfAlarmData
(
"老化柜通讯失败,无响应"
);
tEquipmentAlarmDataService
.
insertTEquipmentAlarmData
(
alarmData
);
TEquipmentAlarmData
alarmData
=
new
TEquipmentAlarmData
();
for
(
TEquipmentInfo
info
:
equipmentInfos
){
/* 1.老化柜、标定柜通讯 */
receiveMsg
=
agingCabinetCommunication
(
info
,
sendMsg
);
if
(
receiveMsg
==
null
){
// 记录异常数据
alarmData
.
setfAlarmType
(
"01"
);
// 01.老化柜 02.标定柜 03.机械臂 04.老化层 05.点位
alarmData
.
setfEquipmentCode
(
info
.
getfEquipmentCode
());
alarmData
.
setfAlarmData
(
"老化柜通讯失败,无响应"
);
tEquipmentAlarmDataService
.
insertTEquipmentAlarmData
(
alarmData
);
// 更新老化柜状态(“0”空闲,“1”运行,“2”故障)
info
.
setfStatus
(
"2"
);
tEquipmentInfoService
.
updateTEquipmentInfo
(
info
);
}
else
if
(
receiveMsg
.
length
()
!=
58
)
{
// 记录异常数据
alarmData
.
setfAlarmType
(
"01"
);
// 01.老化柜 02.标定柜 03.机械臂 04.老化层 05.点位
alarmData
.
setfEquipmentCode
(
info
.
getfEquipmentCode
());
alarmData
.
setfAlarmData
(
"老化柜IP或端口号为空"
);
tEquipmentAlarmDataService
.
insertTEquipmentAlarmData
(
alarmData
);
}
else
{
// 解析服务器返回信息
// 示例:00 01 00 00 00 17 01 04 14 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
String
flag
=
receiveMsg
.
substring
(
18
,
58
);
if
(
"0000000000000000000000000000000000000000"
.
equals
(
flag
)
&&
!
"0"
.
equals
(
info
.
getfStatus
())){
// 更新老化柜状态(“0”空闲,“1”运行,“2”故障)
info
.
setfStatus
(
"2"
);
info
.
setfStatus
(
"0"
);
info
.
setfUpdateTime
(
new
Date
());
tEquipmentInfoService
.
updateTEquipmentInfo
(
info
);
}
else
if
(!
"0000000000000000000000000000000000000000"
.
equals
(
flag
)
&&
"0"
.
equals
(
info
.
getfStatus
())){
info
.
setfStatus
(
"1"
);
info
.
setfUpdateTime
(
new
Date
());
tEquipmentInfoService
.
updateTEquipmentInfo
(
info
);
}
else
if
(
receiveMsg
.
length
()
!=
58
)
{
// 记录异常数据
alarmData
.
setfAlarmType
(
"01"
);
// 01.老化柜 02.标定柜 03.机械臂 04.老化层 05.点位
alarmData
.
setfEquipmentCode
(
info
.
getfEquipmentCode
());
alarmData
.
setfAlarmData
(
"老化柜IP或端口号为空"
);
tEquipmentAlarmDataService
.
insertTEquipmentAlarmData
(
alarmData
);
}
else
if
(
receiveMsg
.
length
()
==
58
){
// 解析服务器返回信息
// 示例:00 01 00 00 00 17 01 04 14 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
String
flag
=
receiveMsg
.
substring
(
18
,
58
);
if
(
"0000000000000000000000000000000000000000"
.
equals
(
flag
)
&&
!
"0"
.
equals
(
info
.
getfStatus
())){
// 更新老化柜状态(“0”空闲,“1”运行,“2”故障)
info
.
setfStatus
(
"0"
);
info
.
setfUpdateTime
(
new
Date
());
tEquipmentInfoService
.
updateTEquipmentInfo
(
info
);
}
else
if
(!
"0000000000000000000000000000000000000000"
.
equals
(
flag
)
&&
"0"
.
equals
(
info
.
getfStatus
())){
info
.
setfStatus
(
"1"
);
info
.
setfUpdateTime
(
new
Date
());
tEquipmentInfoService
.
updateTEquipmentInfo
(
info
);
// 解析层状态,根据层编号修改状态
int
startIndex
;
int
endIndex
;
int
code
;
//组成老化层编号
String
status
;
TStoreyInfo
storeyInfo
=
new
TStoreyInfo
();
for
(
startIndex
=
18
,
endIndex
=
22
,
code
=
1
;
endIndex
<=
receiveMsg
.
length
();
startIndex
+=
4
,
endIndex
+=
4
,
code
++){
status
=
receiveMsg
.
substring
(
startIndex
,
endIndex
);
storeyInfo
.
setfStoreyCode
(
info
.
getfEquipmentCode
()
+
"-"
+
code
);
if
(
"0000"
.
equals
(
status
)){
/* 2.老化层断电 */
// 解析层状态,根据层编号修改状态
int
startIndex
;
int
endIndex
;
int
code
;
//组成老化层编号
String
status
;
TStoreyInfo
storeyInfo
=
new
TStoreyInfo
();
for
(
startIndex
=
18
,
endIndex
=
22
,
code
=
1
;
endIndex
<=
receiveMsg
.
length
();
startIndex
+=
4
,
endIndex
+=
4
,
code
++){
status
=
receiveMsg
.
substring
(
startIndex
,
endIndex
);
storeyInfo
.
setfStoreyCode
(
info
.
getfEquipmentCode
()
+
"-"
+
code
);
if
(
"0000"
.
equals
(
status
)){
/* 2.老化层断电 */
storeyInfo
.
setfStatus
(
"4"
);
//断电
tStoreyInfoService
.
updateTStoreyInfoByCode
(
storeyInfo
);
}
storeyInfo
.
setfStatus
(
"4"
);
//断电
tStoreyInfoService
.
updateTStoreyInfoByCode
(
storeyInfo
);
}
}
}
...
...
zhmes-agecal-common/src/main/java/com/zehong/common/utils/TCP/ReceiverThread.java
View file @
16a45a69
...
...
@@ -12,7 +12,7 @@ import java.net.Socket;
*
* @author zehong
*/
public
class
ReceiverThread
extends
Thread
implements
Runnable
{
public
class
ReceiverThread
extends
Thread
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ReceiverThread
.
class
);
public
static
String
hexResponse
;
private
final
Socket
socket
;
...
...
@@ -34,7 +34,11 @@ public class ReceiverThread extends Thread implements Runnable {
// 将接收到的字节转换为十六进制字符串显示
hexResponse
=
HexUtils
.
bytesToHex
(
responseBytes
);
log
.
info
(
"收到服务器响应: "
+
hexResponse
);
if
(
hexResponse
.
length
()
==
58
)
{
socket
.
close
();
}
}
log
.
info
(
"解析完了啊啊啊啊啊: "
+
hexResponse
);
}
catch
(
IOException
e
)
{
log
.
error
(
"接收数据失败: "
+
e
.
getMessage
());
}
...
...
zhmes-agecal-common/src/main/java/com/zehong/common/utils/TCP/TCPClient.java
View file @
16a45a69
...
...
@@ -34,13 +34,15 @@ public class TCPClient {
log
.
info
(
"已发送数据: "
+
sendMsg
);
receiverThread
=
new
ReceiverThread
(
socket
);
hexResponse
=
receiverThread
.
hexResponse
;
receiverThread
.
start
();
//
receiverThread.join();
receiverThread
.
join
();
hexResponse
=
ReceiverThread
.
hexResponse
;
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"通信异常: "
+
e
.
getMessage
());
e
.
printStackTrace
();
}
catch
(
InterruptedException
e
)
{
throw
new
RuntimeException
(
e
);
}
return
hexResponse
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment