更新 S7 部分

This commit is contained in:
caixiang 2022-02-10 09:35:10 +08:00
parent 0d326d95a7
commit 83ac4db80f
3 changed files with 8 additions and 9 deletions

View File

@ -22,7 +22,6 @@ public enum S7Client {
; ;
private String host; private String host;
//默认 0 机架号 //默认 0 机架号
@ -104,7 +103,7 @@ public enum S7Client {
if(connect!=null){ if(connect!=null){
connections.add(connect); connections.add(connect);
}else { }else {
logger.info("check_ping 断线重连出现异常。。"); logger.info("check_ping 断线重连出现异常。。");
} }
} }
@ -112,7 +111,7 @@ public enum S7Client {
try { try {
Thread.sleep(10000); Thread.sleep(10000);
}catch (Exception e){ }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"); System.out.println(connector.hashCode()+" : ping");
Thread.sleep(100); Thread.sleep(100);
}catch (Exception e){ }catch (Exception e){
System.out.println(connector.hashCode()+" : connection error"); logger.info(connector.hashCode()+" : connection error"+"errMessage is : "+e.getMessage());
logger.info(e.getMessage());
//先把 socket close掉 //先把 socket close掉
try { try {
connector.close(); connector.close();
@ -147,7 +145,7 @@ public enum S7Client {
//如果是网络波动照成的socket断开 等个1S 再重连试试 //如果是网络波动照成的socket断开 等个1S 再重连试试
Thread.sleep(100); Thread.sleep(100);
}catch (Exception ee){ }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){ if(connect!=null){
connections.add(connect); connections.add(connect);
}else { }else {
logger.info("断线重连出现异常。。"); logger.info("ping时候出现异常尝试重连 重连时候还是 出现异常。。");
} }
} }

View File

@ -56,7 +56,7 @@ public final class PLCinterface {
e.printStackTrace(); e.printStackTrace();
} }
} }
res = 0; res = -1;
while ((this.in.available() > 0) && (len > 0)) { while ((this.in.available() > 0) && (len > 0)) {
res = this.in.read(b, start, len); res = this.in.read(b, start, len);
start += res; start += res;

View File

@ -123,6 +123,7 @@ public final class TCPConnection extends S7Connection {
* *
* @return the int * @return the int
* 0 ==> 不成功 * 0 ==> 不成功
* -1 ==> 读到一个空的字节流 这种情况很少
* 其他 ==> 成功 * 其他 ==> 成功
*/ */
protected int readISOPacket() { protected int readISOPacket() {
@ -165,7 +166,7 @@ public final class TCPConnection extends S7Connection {
* the size * the size
* @return the int * @return the int
* 1 ==> 成功 * 1 ==> 成功
* 0 ==> 不成功 * 0 ==> 不成功出现异常了
*/ */
protected int sendISOPacket(int size) { protected int sendISOPacket(int size) {
size += 4; size += 4;