diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java index ae383acb..23138e8d 100644 --- a/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java +++ b/app/src/main/java/com/bonait/bnframework/common/constant/ConfigName.java @@ -184,6 +184,10 @@ public class ConfigName { //endregion //region PlC连接参数 + /** + * Plc是否连接 + */ + public boolean IsShow = false; /** * Plc是否连接 */ diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigation2Activity.java b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigation2Activity.java index 8e6945ee..fec98cfc 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigation2Activity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigation2Activity.java @@ -66,6 +66,7 @@ public class BottomNavigation2Activity extends BaseActivity { @Override protected void onDestroy() { ConfigData.getInstance().ColsePLC(); + ConfigName.getInstance().IsShow=false; //AliyunIOTManager.getInstance().CloseDev(); super.onDestroy(); } @@ -182,51 +183,55 @@ public class BottomNavigation2Activity extends BaseActivity { */ public void ReconnectModbus() { try { - + ConfigName.getInstance().IsShow=true; ThreadManager.Get().StartLong("PLC断线重连线程", true, new IThread() { @Override public void Run() throws InterruptedException { try { - if (ConfigName.getInstance().PlcIsConnect) { - //ping 不通 - boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); - if (!status) //ping 不通 连接 - { - MessageLog.ShowInfo("PLC状态断开,尝试连接..."); - ConfigName.getInstance().PlcIsConnect = false; - } - } else { - boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); - if (status) { - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " PLC通讯正常,准备连接!"); - ModbusTcpServer.ConnectPLC(); - } else { - MessageLog.ShowInfo("PLC状态断开,尝试连接..."); - ConfigName.getInstance().PlcIsConnect = false; - } - } - - if(ConfigName.getInstance().versionSelectionEnum.contains("一拖")) + if(ConfigName.getInstance().IsShow) { - if (ConfigName.getInstance().PlcMainIsConnect) { + if (ConfigName.getInstance().PlcIsConnect) { //ping 不通 - boolean status = ModbusTcpMainServer.ping2(ConfigName.getInstance().MainAddress, 1, 1); + boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); if (!status) //ping 不通 连接 { - MessageLog.ShowInfo("主控PLC状态断开,尝试连接..."); - ConfigName.getInstance().PlcMainIsConnect = false; + MessageLog.ShowInfo("PLC状态断开,尝试连接..."); + ConfigName.getInstance().PlcIsConnect = false; } } else { - boolean status = ModbusTcpMainServer.ping2(ConfigName.getInstance().MainAddress, 1, 1); + boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); if (status) { - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().MainAddress + " 主控PLC通讯正常,准备连接!"); - ModbusTcpMainServer.ConnectPLC(); + MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " PLC通讯正常,准备连接!"); + ModbusTcpServer.ConnectPLC(); } else { - MessageLog.ShowInfo("主控PLC状态断开,尝试连接..."); - ConfigName.getInstance().PlcMainIsConnect = false; + MessageLog.ShowInfo("PLC状态断开,尝试连接..."); + ConfigName.getInstance().PlcIsConnect = false; + } + } + + if(ConfigName.getInstance().versionSelectionEnum.contains("一拖")) + { + if (ConfigName.getInstance().PlcMainIsConnect) { + //ping 不通 + boolean status = ModbusTcpMainServer.ping2(ConfigName.getInstance().MainAddress, 1, 1); + if (!status) //ping 不通 连接 + { + MessageLog.ShowInfo("主控PLC状态断开,尝试连接..."); + ConfigName.getInstance().PlcMainIsConnect = false; + } + } else { + boolean status = ModbusTcpMainServer.ping2(ConfigName.getInstance().MainAddress, 1, 1); + if (status) { + MessageLog.ShowInfo("设备 " + ConfigName.getInstance().MainAddress + " 主控PLC通讯正常,准备连接!"); + ModbusTcpMainServer.ConnectPLC(); + } else { + MessageLog.ShowInfo("主控PLC状态断开,尝试连接..."); + ConfigName.getInstance().PlcMainIsConnect = false; + } } } } + Thread.sleep(3000); } catch (Exception e) { Log.i("PLC", "PLC重连接失败!" + e.getMessage()); diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java index 1d10edde..00914e9b 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java @@ -282,46 +282,49 @@ public class BottomNavigationNewActivity extends BaseActivity { */ public void ReconnectModbus() { try { - ThreadManager.Get().StartLong("PLC断线重连线程", true, new IThread() { + ThreadManager.Get().StartLong("PLC断线重连线程-2", true, new IThread() { @Override public void Run() throws InterruptedException { try { - if (ConfigName.getInstance().PlcIsConnect) { - //ping 不通 - boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); - if (!status) //ping 不通 连接 - { - MessageLog.ShowInfo("PLC状态断开,尝试连接..."); - ConfigName.getInstance().PlcIsConnect = false; - } - } else { - boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); - if (status) { - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " PLC通讯正常,准备连接!"); - ModbusTcpServer.ConnectPLC(); - } else { - MessageLog.ShowInfo("PLC状态断开,尝试连接..."); - ConfigName.getInstance().PlcIsConnect = false; - } - } - - if (ConfigName.getInstance().versionSelectionEnum.contains("一拖")) { - if (ConfigName.getInstance().PlcMainIsConnect) { + if(IsRunThread) + { + if (ConfigName.getInstance().PlcIsConnect) { //ping 不通 - boolean status = ModbusTcpMainServer.ping2(ConfigName.getInstance().MainAddress, 1, 1); + boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); if (!status) //ping 不通 连接 { - MessageLog.ShowInfo("主控PLC状态断开,尝试连接..."); - ConfigName.getInstance().PlcMainIsConnect = false; + MessageLog.ShowInfo("PLC状态断开,尝试连接..."); + ConfigName.getInstance().PlcIsConnect = false; } } else { - boolean status = ModbusTcpMainServer.ping2(ConfigName.getInstance().MainAddress, 1, 1); + boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1); if (status) { - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().MainAddress + " 主控PLC通讯正常,准备连接!"); - ModbusTcpMainServer.ConnectPLC(); + MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " PLC通讯正常,准备连接!"); + ModbusTcpServer.ConnectPLC(); } else { - MessageLog.ShowInfo("主控PLC状态断开,尝试连接..."); - ConfigName.getInstance().PlcMainIsConnect = false; + MessageLog.ShowInfo("PLC状态断开,尝试连接..."); + ConfigName.getInstance().PlcIsConnect = false; + } + } + + if (ConfigName.getInstance().versionSelectionEnum.contains("一拖")) { + if (ConfigName.getInstance().PlcMainIsConnect) { + //ping 不通 + boolean status = ModbusTcpMainServer.ping2(ConfigName.getInstance().MainAddress, 1, 1); + if (!status) //ping 不通 连接 + { + MessageLog.ShowInfo("主控PLC状态断开,尝试连接..."); + ConfigName.getInstance().PlcMainIsConnect = false; + } + } else { + boolean status = ModbusTcpMainServer.ping2(ConfigName.getInstance().MainAddress, 1, 1); + if (status) { + MessageLog.ShowInfo("设备 " + ConfigName.getInstance().MainAddress + " 主控PLC通讯正常,准备连接!"); + ModbusTcpMainServer.ConnectPLC(); + } else { + MessageLog.ShowInfo("主控PLC状态断开,尝试连接..."); + ConfigName.getInstance().PlcMainIsConnect = false; + } } } } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java index 025660dc..86654685 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyActivity.java @@ -550,7 +550,7 @@ public class DiyActivity extends BaseActivity { */ public boolean IsHotJ() { - int index=0; + int index=1; int k=0;int j=0; for(BPA_GOODSRECIPE item:bpa_goodsrecipes) { @@ -566,7 +566,7 @@ public class DiyActivity extends BaseActivity { index++; } - if(j<=k) + if(j