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 b474e464..325232e4 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java +++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java @@ -56,7 +56,7 @@ public class ExecuteTheRecipe { * 等待超时时间 */ //public static int whileTime = 40; - public static int whileTime = 5; + public static int whileTime = 100; /** * 监听变量值 @@ -1015,7 +1015,7 @@ public class ExecuteTheRecipe { Log.d("倒菜", "倒菜完成了"); if (IsMoveYiHaoWei()) { - WriteMainPLC("机器人放主料完成", true, null); + WriteMainPLC("炒锅投主料完成", true, null); } //判断是否有烹饪时间 @@ -1063,7 +1063,7 @@ public class ExecuteTheRecipe { final boolean[] IsComplete = {false}; long a = System.currentTimeMillis(); while (!IsComplete[0]) { - if ((System.currentTimeMillis() - a) > 1000 * (whileTime * 3)) { + if ((System.currentTimeMillis() - a) > 1000 * (whileTime * 10)) { break; } else { Object sb = ReadMainPLC("机器人放辅料完成");//ListeningValue.get(name); @@ -1113,7 +1113,7 @@ public class ExecuteTheRecipe { final boolean[] IsComplete = {false}; long a = System.currentTimeMillis(); while (!IsComplete[0]) { - if ((System.currentTimeMillis() - a) > 1000 * (whileTime * 3)) { + if ((System.currentTimeMillis() - a) > 1000 * (whileTime * 10)) { break; } else { Object sb = ReadMainPLC("机器人到达炒锅出餐位");//ListeningValue.get(name); @@ -1124,7 +1124,7 @@ public class ExecuteTheRecipe { Thread.sleep(100);//10 *6 } WriteMainPLC("机器人到达炒锅出餐位", false, null); - WriteMainPLC("炒锅倒菜减速位", false, null); + WriteMainPLC("炒锅出餐减速到位", false, null); BottomClick1("出菜"); @@ -1357,6 +1357,8 @@ public class ExecuteTheRecipe { WriteMainPLC("心跳", false, null); WriteMainPLC("炒锅空闲状态", ConfigName.getInstance().WokStatus, null); WriteMainPLC("投料机构状态", ConfigName.getInstance().TouLiaoStatus, null); + Log.e("炒锅状态", "炒锅状态: "+ ConfigName.getInstance().WokStatus); + Log.e("投料机构状态", "投料机构状态: "+ ConfigName.getInstance().TouLiaoStatus); //读取主控下发的商品 ReadMasterDeliveryGoods(); @@ -1579,13 +1581,13 @@ public class ExecuteTheRecipe { public static void ReadPLCMainStatus() { try { if (ConfigName.getInstance().PlcIsConnect) { - Object obj1 = getListingValue("翻转轴1允许机器人放盒取盒"); - Object obj2 = getListingValue("翻转轴2允许机器人放盒取盒"); + Object obj1 = ReadPLC("翻转轴1允许机器人放盒取盒"); + Object obj2 = ReadPLC("翻转轴2允许机器人放盒取盒"); boolean ob1 = obj1 == null ? false : (boolean) obj1; boolean ob2 = obj2 == null ? false : (boolean) obj2; ConfigName.getInstance().TouLiaoStatus = ob1 && ob2; - Object obj3 = getListingValue("初始化"); + Object obj3 = ReadPLC("初始化完成"); boolean ob3 = obj3 == null ? false : (boolean) obj3; ConfigName.getInstance().WokStatus = ob3 && !ExecuteTheRecipe.IsStart; } @@ -1655,30 +1657,40 @@ public class ExecuteTheRecipe { ToastUtils.warning("请耐心等待商品制作结束!!!"); WriteMainPLC("商品数据验证", false, null); } else { + WriteMainPLC("商品数据验证", true, null); + if (ConfigName.getInstance().user.name.equals("admin") || ConfigName.getInstance().user.account.equals("admin") || ConfigName.getInstance().user.userID.equals("超级管理员")) { DataBus.getInstance().mListener.clickListener(null, goods); + boolean issucess=false; try { + WriteMainPLC("机器人放主料完成", false, null); final boolean[] IsComplete = {false}; long a = System.currentTimeMillis(); while (!IsComplete[0]) { - if ((System.currentTimeMillis() - a) > 1000 * (whileTime * 3)) { + if ((System.currentTimeMillis() - a) > 1000 * (whileTime * 5)) { break; } else { + WriteMainPLC("投料机构状态", ConfigName.getInstance().TouLiaoStatus, null); Object sb = ReadMainPLC("机器人放主料完成"); if (sb != null) { IsComplete[0] = (boolean) (sb); + issucess=(boolean) (sb); } } Thread.sleep(100);//10 *6 } - WriteMainPLC("机器人放主料完成", false, null); } catch (Exception e) { } - MessageManager.getInstance().sendMessage(MessageName.IsStratMakeGood1, goods.id); + if(issucess) + { + MessageManager.getInstance().sendMessage(MessageName.IsStratMakeGood1, goods.id); + } } else { MessageManager.getInstance().sendMessage(MessageName.OpenMakeGoodFrom, goods.id); + boolean issucess=false; + try { final boolean[] IsComplete = {false}; long a = System.currentTimeMillis(); @@ -1689,20 +1701,35 @@ public class ExecuteTheRecipe { Object sb = ReadMainPLC("机器人放主料完成"); if (sb != null) { IsComplete[0] = (boolean) (sb); + issucess= (boolean) (sb); } } Thread.sleep(100);//10 *6 } + WriteMainPLC("机器人放主料完成", false, null); + } catch (Exception e) { } - MessageManager.getInstance().sendMessage(MessageName.IsStratMakeGood, goods.id); + if(issucess) + { + MessageManager.getInstance().sendMessage(MessageName.IsStratMakeGood, goods.id); + } } } } } } + + Object IsJT = ReadMainPLC("机器人急停"); + if (IsJT!=null) + { + if((boolean) IsJT)//异常情况 + { + WritePLC("停止",true,null); + } + } } //endregion 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 c524be0a..12b87232 100644 --- a/app/src/main/java/com/bonait/bnframework/business/MainInit.java +++ b/app/src/main/java/com/bonait/bnframework/business/MainInit.java @@ -26,6 +26,8 @@ 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.modbus.ModbusTcpMainHelper; +import com.bonait.bnframework.common.modbus.ModbusTcpMainServer; import com.bonait.bnframework.common.notification.MainNotification; import com.bonait.bnframework.common.utils.AppUtils; import com.bonait.bnframework.common.utils.NetworkUtils; @@ -255,14 +257,30 @@ public class MainInit { public void ErrorMsg(String 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); + if(msg.contains("主设备")) + { + ModbusTcpMainHelper.get().release();//释放modbus + ConfigName.getInstance().PlcMainIsConnect=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("主控PLC", "主控PLC: 连接断开"); + + }else if(msg.contains("PLC设备")) + { + 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程序断开PLC,准备重连机制..."; + QueryDB.AddAlertlog(log); + Log.e("设备PLC", "设备PLC: 连接断开"); + + } + } } @Override 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 eafd4f86..d1ed7c36 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 @@ -221,11 +221,11 @@ public class ConfigName { /** * 炒锅状态:空闲 或者 不正常 */ - public boolean WokStatus = true; + public boolean WokStatus = false; /** * 炒锅投料机构:空闲 或者 不正常 */ - public boolean TouLiaoStatus = true; + public boolean TouLiaoStatus = false; /** * 出餐减速位:空闲 或者 不正常 */ @@ -1135,6 +1135,8 @@ public class ConfigName { put("机器人放辅料完成",52); put("机器人到达炒锅出餐位",53); put("商品下发",54); + put("机器人急停",55);//true 异常 false 正常 + put("商品信息",0); }}; diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpMainServer.java b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpMainServer.java index 56146faa..18b42ffa 100644 --- a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpMainServer.java +++ b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpMainServer.java @@ -1,5 +1,7 @@ package com.bonait.bnframework.common.modbus; +import android.util.Log; + import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.helper.DataFormat; @@ -174,30 +176,7 @@ public class ModbusTcpMainServer { } - /** - * 连接 - */ - public void Connect() throws InterruptedException { - boolean status = false; - while (!status) { - try { - //status为0则代表通,为1则代表不通。 - status =ping2(ConfigName.getInstance().Address,1,1); - Thread.sleep(1000); - } catch (InterruptedException e) { - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " 网络验证失败"); - } catch (Exception e) { - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " 网络验证失败"); - } - } - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " PLC通讯正常,准备连接!"); - while (ConfigName.getInstance().PlcIsConnect==false) - { - ConnectPLC(); - Thread.sleep(5000); - } - } /** * 连接PLC @@ -219,13 +198,17 @@ public class ModbusTcpMainServer { MessageLog.ShowInfo("设备 " + ConfigName.getInstance().MainAddress + " 连接成功"); ConfigName.getInstance().PlcMainIsConnect = true; ConfigData.getInstance().MainPLC_Init(); + Log.e("主控PLC", "主控PLC: 连接成功"); + } @Override public void onFailure(Throwable tr) { ConfigName.getInstance().PlcMainIsConnect = false; ToastUtils.info("设备 " + ConfigName.getInstance().MainAddress + " 连接失败:" + tr.getMessage()); - MessageLog.ShowError("设备 " + ConfigName.getInstance().MainAddress + " 连接失败:" + tr.getMessage()); + MessageLog.ShowError("主设备 " + ConfigName.getInstance().MainAddress + " 连接失败:" + tr.getMessage()); + Log.e("主控PLC", "主控PLC: 连接断开"); + } @Override public void onFinally() { diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpServer.java b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpServer.java index 6a08c960..4470bce6 100644 --- a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpServer.java +++ b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpServer.java @@ -2,6 +2,7 @@ package com.bonait.bnframework.common.modbus; import android.os.Looper; +import android.util.Log; import com.bonait.bnframework.MainApplication; import com.bonait.bnframework.business.ConfigData; @@ -171,32 +172,6 @@ public class ModbusTcpServer { } - - /** - * 连接 - */ - public void Connect() throws InterruptedException { - boolean status = false; - while (!status) { - try { - //status为0则代表通,为1则代表不通。 - status =ping2(ConfigName.getInstance().Address,1,1); - Thread.sleep(1000); - } catch (InterruptedException e) { - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " 网络验证失败"); - } catch (Exception e) { - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " 网络验证失败"); - } - } - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " PLC通讯正常,准备连接!"); - - while (ConfigName.getInstance().PlcIsConnect==false) - { - ConnectPLC(); - Thread.sleep(5000); - } - } - /** * 连接PLC */ @@ -213,18 +188,20 @@ public class ModbusTcpServer { @Override public void onSuccess(ModbusMaster modbusMaster) { ToastUtils.info("设备 " + ConfigName.getInstance().Address + " 连接成功"); - MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " 连接成功"); ConfigName.getInstance().PlcIsConnect = true; ConfigData.getInstance().PLC_Init(); + Log.e("设备PLC", "设备PLC: 连接成功"); } @Override public void onFailure(Throwable tr) { ConfigName.getInstance().PlcIsConnect = false; ToastUtils.info("设备 " + ConfigName.getInstance().Address + " 连接失败:" + tr.getMessage()); - MessageLog.ShowError("设备 " + ConfigName.getInstance().Address + " 连接失败:" + tr.getMessage()); + MessageLog.ShowError("PLC设备 " + ConfigName.getInstance().Address + " 连接失败:" + tr.getMessage()); + Log.e("设备PLC", "设备PLC: 连接断开"); } + @Override public void onFinally() { 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 1cba7d30..2760c9a2 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 @@ -173,6 +173,7 @@ public class BottomNavigationNewActivity extends BaseActivity { runOnUiThread(new Runnable() { @Override public void run() { + cooking.SetStartStaus(true); ExecuteTheRecipe.IsPause = false; ExecuteTheRecipe.WritePLC("暂停开关", false, null); onRecordStart(); diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CookingActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CookingActivity.java index cc94cacb..2d4d3ab8 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CookingActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/CookingActivity.java @@ -244,6 +244,11 @@ public class CookingActivity extends LinearLayout { } huoli.SetLevel(0); } + + public void SetStartStaus(boolean i) + { + start_goodmake.SetStatus(i); + } //endregion //region 私有方法