From 5beaeec0ac46c39a8fbb56f1153550296a7bf947 Mon Sep 17 00:00:00 2001 From: fyf <11621@LAPTOP-04QQU0AO> Date: Thu, 31 Aug 2023 10:24:45 +0800 Subject: [PATCH] plc --- app/src/main/java/com/example/bpa/MainActivity.java | 1 + app/src/main/java/com/example/bpa/app/BootInit.java | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/src/main/java/com/example/bpa/MainActivity.java b/app/src/main/java/com/example/bpa/MainActivity.java index cb3e271..e592d71 100644 --- a/app/src/main/java/com/example/bpa/MainActivity.java +++ b/app/src/main/java/com/example/bpa/MainActivity.java @@ -125,6 +125,7 @@ public class MainActivity extends FragmentActivity implements View.OnClickListen protected void onDestroy() { MQTT.get().ConnMqttBroken(false);//释放mqtt ModbusTcpHelper.get().release();//释放modbus + DataBus.getInstance().PlcIsConnect=false; super.onDestroy(); } //endregion diff --git a/app/src/main/java/com/example/bpa/app/BootInit.java b/app/src/main/java/com/example/bpa/app/BootInit.java index b0ad84f..1ff133a 100644 --- a/app/src/main/java/com/example/bpa/app/BootInit.java +++ b/app/src/main/java/com/example/bpa/app/BootInit.java @@ -19,6 +19,7 @@ import com.example.bpa.db.mode.BPA_SUBORDER; import com.example.bpa.db.mode.BPA_USER; import com.example.bpa.helper.CrashHandler; import com.example.bpa.helper.MessageLog; +import com.example.bpa.helper.ModbusTcpHelper; import com.example.bpa.helper.SdCart; import com.example.bpa.helper.ToastUtil; import com.example.bpa.service.BusinessServer; @@ -83,6 +84,17 @@ public class BootInit { MessageLog.MsgNotify = new IMessageLogNotify() { @Override public void ErrorMsg(String msg) { + if(msg.contains("msg:com.serotonin.modbus4j.exception")) + { + ModbusTcpHelper.get().release();//释放modbus + DataBus.getInstance().PlcIsConnect=false; + + BPA_ALERTLOG log = new BPA_ALERTLOG(); + log.userID = ConfigName.getInstance().user.userID; + log.type=4; + log.text = msg+"程序断开PLC,准备重连机制..."; + QueryDB.AddAlertlog(log); + } Log.e("Error", msg); } @Override