From 2b92477e48258311d7cc439fa755ece7f937298c Mon Sep 17 00:00:00 2001 From: fyf <11621@LAPTOP-04QQU0AO> Date: Mon, 12 Jun 2023 11:21:45 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=B0=E5=9C=BA=E6=94=B9=E5=8A=A81233?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/bpa/helper/ModbusTcpServer.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java b/app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java index 8aeb7b0..f857380 100644 --- a/app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java +++ b/app/src/main/java/com/example/bpa/helper/ModbusTcpServer.java @@ -201,7 +201,7 @@ public class ModbusTcpServer { .setRetries(0) .setEncapsulated(false) .setKeepAlive(true); - ConnectPLC(); + //ConnectPLC(); } /** @@ -257,11 +257,15 @@ public class ModbusTcpServer { @Override public void Run() throws InterruptedException { try { - ModbusMaster master= ModbusTcpHelper.get().getModbusMaster(); - if (master==null || master.isConnected() == false) { - ConnectPLC(); + boolean status =ping2(ConfigName.getInstance().Address,1,1); + if(status) + { + ModbusMaster master= ModbusTcpHelper.get().getModbusMaster(); + if (master==null || master.isConnected() == false) { + ConnectPLC(); + } + Thread.sleep(20000); } - Thread.sleep(20000); } catch (Exception e) { Log.i("PLC", "PLC重连接失败!"+e.getMessage()); }