diff --git a/app/src/main/java/com/bonait/bnframework/business/ConfigData.java b/app/src/main/java/com/bonait/bnframework/business/ConfigData.java index b3256780..d0c899d1 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ConfigData.java +++ b/app/src/main/java/com/bonait/bnframework/business/ConfigData.java @@ -10,6 +10,7 @@ import androidx.annotation.NonNull; import com.bonait.bnframework.R; import com.bonait.bnframework.common.constant.ConfigName; +import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_CLOUDDATA; @@ -947,6 +948,7 @@ public class ConfigData { */ public void ColsePLC() { ModbusTcpHelper.get().release();//释放modbus + ConfigName.getInstance().PlcIsConnect=false; } /** * PLC初始化完成时,需要注册的服务 diff --git a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java index a8f196b9..899151e3 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java +++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java @@ -280,13 +280,14 @@ public class ExecuteTheRecipe { */ private static void Write_PLC_Stir(HashMap data) { try { + int val=0; for (HashMap.Entry entry : data.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); ToastUtils.info("工序:" + key + "," + value); if (key.contains("(秒)")) { - int val = Integer.parseInt(value); + val = Integer.parseInt(value); Thread.sleep(val * 1000); } else { int writeValue = GetMXValue(key, value); @@ -306,6 +307,11 @@ public class ExecuteTheRecipe { }); } } + + if(val>0) + { + Thread.sleep(val * 1000); + } } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); } @@ -318,12 +324,14 @@ public class ExecuteTheRecipe { */ private static void Write_PLC_Location(HashMap data) { try { + int val=0; + for (HashMap.Entry entry : data.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); ToastUtils.info("工序:" + key + "," + value); if (key.contains("(秒)")) { - int val = Integer.parseInt(value); + val = Integer.parseInt(value); Thread.sleep(val * 1000); } else if (key.contains("速度")) { int writeValue = GetMXValue(key, value); @@ -350,6 +358,11 @@ public class ExecuteTheRecipe { ToastUtils.info("炒锅到达"+value+",继续制作!!!"); } } + + if(val>0) + { + Thread.sleep(val * 1000); + } } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); } @@ -545,13 +558,13 @@ public class ExecuteTheRecipe { */ private static void Write_PLC_Heating(HashMap data) { try { + int val=0; for (HashMap.Entry entry : data.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); ToastUtils.info("工序:" + key + "," + value); if (key.contains("(秒)")) { - int val = Integer.parseInt(value); - Thread.sleep(val * 1000); + val = Integer.parseInt(value); } else { int writeValue = GetMXValue(key, value); WritePLC(key, writeValue, new IWriteCallBack() { @@ -570,6 +583,12 @@ public class ExecuteTheRecipe { }); } } + + if(val>0) + { + Thread.sleep(val * 1000); + } + } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); } diff --git a/app/src/main/java/com/bonait/bnframework/business/MainInit.java b/app/src/main/java/com/bonait/bnframework/business/MainInit.java index d8a94737..78350243 100644 --- a/app/src/main/java/com/bonait/bnframework/business/MainInit.java +++ b/app/src/main/java/com/bonait/bnframework/business/MainInit.java @@ -23,6 +23,7 @@ import com.bonait.bnframework.common.helper.CrashHandler; import com.bonait.bnframework.common.helper.I.IMessageLogNotify; import com.bonait.bnframework.common.helper.MessageLog; import com.bonait.bnframework.common.helper.SdCart; +import com.bonait.bnframework.common.modbus.ModbusTcpHelper; import com.bonait.bnframework.common.notification.MainNotification; import com.bonait.bnframework.common.utils.AppUtils; import com.bonait.bnframework.common.utils.NetworkUtils; @@ -154,7 +155,17 @@ public class MainInit { MessageLog.MsgNotify = new IMessageLogNotify() { @Override public void ErrorMsg(String msg) { - Log.e("Error", msg); + if(msg.contains("msg:com.serotonin.modbus4j.exception")) + { + ModbusTcpHelper.get().release();//释放modbus + ConfigName.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); + } } @Override public void InfoMsg(String msg) {