From 6c9369ab9b7da99687857004470e8d7824eb69ae Mon Sep 17 00:00:00 2001
From: huang <1532065656@qq.com>
Date: 星期三, 03 九月 2025 08:02:00 +0800
Subject: [PATCH] 修改plc连接读取失败导致无法重新链接
---
JiuMuMesParent/common/servicebase/src/main/java/com/mes/service/ModbusTcp.java | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/JiuMuMesParent/common/servicebase/src/main/java/com/mes/service/ModbusTcp.java b/JiuMuMesParent/common/servicebase/src/main/java/com/mes/service/ModbusTcp.java
index 6248f29..9ce74b3 100644
--- a/JiuMuMesParent/common/servicebase/src/main/java/com/mes/service/ModbusTcp.java
+++ b/JiuMuMesParent/common/servicebase/src/main/java/com/mes/service/ModbusTcp.java
@@ -38,12 +38,19 @@
}
}
//杩炴帴
- public void connect(){
+ public boolean connect() {
try {
- this.socket=new Socket(Ip,Port);
+ if (this.socket != null && !this.socket.isClosed()) {
+ this.socket.close();
+ }
+ this.socket = new Socket(Ip, Port);
this.socket.setSoTimeout(300);
- }catch (Exception e) {
- log.info("The IP address of the host cannot be determined:{}",e.getMessage());
+ log.info("PLC杩炴帴鎴愬姛");
+ return true;
+ } catch (Exception e) {
+ log.error("PLC杩炴帴澶辫触", e);
+ this.socket = null;
+ return false;
}
}
//鍏抽棴杩炴帴
--
Gitblit v1.8.0