From 83ac4db80f4f017d25ce3d7021e640163b4474f5 Mon Sep 17 00:00:00 2001 From: caixiang <939387484@qq.com> Date: Thu, 10 Feb 2022 09:35:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20S7=20=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/qgs/dc/s7/my/s7connector/enmuc/S7Client.java | 12 +++++------- .../s7/my/s7connector/impl/nodave/PLCinterface.java | 2 +- .../s7/my/s7connector/impl/nodave/TCPConnection.java | 3 ++- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/qgs/dc/s7/my/s7connector/enmuc/S7Client.java b/src/main/java/com/qgs/dc/s7/my/s7connector/enmuc/S7Client.java index 227c2ea..f33eb97 100644 --- a/src/main/java/com/qgs/dc/s7/my/s7connector/enmuc/S7Client.java +++ b/src/main/java/com/qgs/dc/s7/my/s7connector/enmuc/S7Client.java @@ -22,7 +22,6 @@ public enum S7Client { - ; private String host; //默认 0 机架号 @@ -104,7 +103,7 @@ public enum S7Client { if(connect!=null){ connections.add(connect); }else { - logger.info("check_ping 断线重连出现异常。。"); + logger.info("(check_ping) 断线重连出现异常。。"); } } @@ -112,7 +111,7 @@ public enum S7Client { try { Thread.sleep(10000); }catch (Exception e){ - logger.info(e.getMessage()); + logger.info("(check_ping)"+e.getMessage()); } } } @@ -138,8 +137,7 @@ public enum S7Client { System.out.println(connector.hashCode()+" : ping"); Thread.sleep(100); }catch (Exception e){ - System.out.println(connector.hashCode()+" : connection error"); - logger.info(e.getMessage()); + logger.info(connector.hashCode()+" : connection error"+"errMessage is : "+e.getMessage()); //先把 socket close掉 try { connector.close(); @@ -147,7 +145,7 @@ public enum S7Client { //如果是网络波动照成的socket断开。 等个1S 再重连试试 Thread.sleep(100); }catch (Exception ee){ - logger.info(ee.getMessage()); + logger.info("connector.close() 出现异常,errMessage is : "+ee.getMessage()); } @@ -160,7 +158,7 @@ public enum S7Client { if(connect!=null){ connections.add(connect); }else { - logger.info("断线重连出现异常。。"); + logger.info("ping时候出现异常,尝试重连, 重连时候还是 出现异常。。"); } } diff --git a/src/main/java/com/qgs/dc/s7/my/s7connector/impl/nodave/PLCinterface.java b/src/main/java/com/qgs/dc/s7/my/s7connector/impl/nodave/PLCinterface.java index 3ce3c8b..7470566 100644 --- a/src/main/java/com/qgs/dc/s7/my/s7connector/impl/nodave/PLCinterface.java +++ b/src/main/java/com/qgs/dc/s7/my/s7connector/impl/nodave/PLCinterface.java @@ -56,7 +56,7 @@ public final class PLCinterface { e.printStackTrace(); } } - res = 0; + res = -1; while ((this.in.available() > 0) && (len > 0)) { res = this.in.read(b, start, len); start += res; diff --git a/src/main/java/com/qgs/dc/s7/my/s7connector/impl/nodave/TCPConnection.java b/src/main/java/com/qgs/dc/s7/my/s7connector/impl/nodave/TCPConnection.java index f47ae82..132daec 100644 --- a/src/main/java/com/qgs/dc/s7/my/s7connector/impl/nodave/TCPConnection.java +++ b/src/main/java/com/qgs/dc/s7/my/s7connector/impl/nodave/TCPConnection.java @@ -123,6 +123,7 @@ public final class TCPConnection extends S7Connection { * * @return the int * 0 ==> 不成功 + * -1 ==> 读到一个空的字节流 (这种情况很少) * 其他 ==> 成功 */ protected int readISOPacket() { @@ -165,7 +166,7 @@ public final class TCPConnection extends S7Connection { * the size * @return the int * 1 ==> 成功 - * 0 ==> 不成功 + * 0 ==> 不成功(出现异常了) */ protected int sendISOPacket(int size) { size += 4;