From e379b776387396dadea6eb5e4753587f2dae8d09 Mon Sep 17 00:00:00 2001 From: fyf Date: Wed, 10 Jan 2024 15:04:22 +0800 Subject: [PATCH] 4444 --- app/build.gradle | 4 + .../bnframework/business/ConfigData.java | 15 - .../business/ExecuteTheRecipe.java | 1241 ++++------------- .../bonait/bnframework/business/MainInit.java | 18 +- .../common/constant/ConfigName.java | 41 +- .../common/modbus/ModbusTcpMainHelper.java | 43 - .../common/modbus/ModbusTcpMainServer.java | 723 ---------- .../common/modbus/S7/IS7ConnHelper.java | 15 + .../common/modbus/S7/S7ConnHelper.java | 136 ++ .../common/modbus/S7/S7Listenner.java | 107 ++ .../common/modbus/S7/mode/MyGunData.java | 29 + .../common/modbus/S7/mode/MyS7Entity.java | 123 ++ .../modbus/S7/mode/MyS7WriteEntity.java | 11 + .../activity/BottomNavigation2Activity.java | 23 - .../activity/BottomNavigationNewActivity.java | 26 - .../modules/home/fragment/Home1Fragment.java | 17 - .../home/fragment/HomeFragmentSBKZ.java | 117 +- .../home/fragment/from/DishTestActivity.java | 446 +----- .../home/fragment/from/DiyMemoryActivity.java | 174 +-- .../fragment/SystemSystemsetFragment.java | 2 +- app/src/main/res/layout/activity_dishtest.xml | 156 +-- app/src/main/res/layout/fragment_home1.xml | 85 -- .../main/res/layout/fragment_home_sbkz.xml | 96 -- 23 files changed, 742 insertions(+), 2906 deletions(-) delete mode 100644 app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpMainHelper.java delete mode 100644 app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpMainServer.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/modbus/S7/IS7ConnHelper.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/modbus/S7/S7ConnHelper.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/modbus/S7/S7Listenner.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/modbus/S7/mode/MyGunData.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/modbus/S7/mode/MyS7Entity.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/modbus/S7/mode/MyS7WriteEntity.java diff --git a/app/build.gradle b/app/build.gradle index a888b814..158675c9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -160,4 +160,8 @@ dependencies { // implementation files('libs\\org.eclipse.paho.client.mqttv3-1.2.5.jar') + + + //S7系列 PLC读取 + implementation 'com.github.s7connector:s7connector:2.0' } 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 d231c647..a1f1ced2 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ConfigData.java +++ b/app/src/main/java/com/bonait/bnframework/business/ConfigData.java @@ -30,7 +30,6 @@ import com.bonait.bnframework.common.http.callback.json.JsonDialogCallback; import com.bonait.bnframework.common.image.utils.LocalCacheUtils; import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.modbus.ModbusTcpHelper; -import com.bonait.bnframework.common.modbus.ModbusTcpMainHelper; import com.bonait.bnframework.common.modbus.ModbusTcpServer; import com.bonait.bnframework.common.model.ResAPI; import com.bonait.bnframework.common.model.mode.ActionJsonMode; @@ -1155,12 +1154,6 @@ public class ConfigData { public void ColsePLC() { ModbusTcpHelper.get().release();//释放modbus ConfigName.getInstance().PlcIsConnect = false; - - if(ConfigName.getInstance().versionSelectionEnum.contains("一拖")) - { - ModbusTcpMainHelper.get().release();//释放modbus - ConfigName.getInstance().PlcMainIsConnect = false; - } } /** @@ -1170,14 +1163,6 @@ public class ConfigData { //PLC连接成功,启动数据监听 ExecuteTheRecipe.Listening(); } - - /** - * PLC主控初始化完成时,需要注册的服务 - */ - public void MainPLC_Init() { - //PLC连接成功,启动数据监听 - ExecuteTheRecipe.MainListening(); - } //endregion } 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 57369225..523592f7 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java +++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java @@ -26,7 +26,6 @@ import com.bonait.bnframework.common.helper.I.IThread; import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.ThreadManager; import com.bonait.bnframework.common.message.MessageManager; -import com.bonait.bnframework.common.modbus.ModbusTcpMainServer; import com.bonait.bnframework.common.modbus.ModbusTcpServer; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; @@ -99,7 +98,6 @@ public class ExecuteTheRecipe { //endregion //region 强制结束 - /** * 设置强制结束 */ @@ -117,7 +115,6 @@ public class ExecuteTheRecipe { //endregion //region 执行配方 - /** * 执行配方 * @@ -138,34 +135,10 @@ public class ExecuteTheRecipe { ToastUtils.info("开始执行:" + recipe.sort + "、" + recipe.processms); if (recipe.materialType == 0)//正常物料 { - //先到达抽料位 - BPA_GOODSRECIPE data1 = Get位置("高速", "抽料位"); - ExecuteOperationSteps(data1.processname, data1.processvalue); - ExecuteMaterialIssuance(recipe.processvalue); } else if (recipe.materialType == 1)//工序模型 { - if (recipe.processname.equals("加水")) { - BPA_GOODSRECIPE data2 = Get位置("高速", "抽料位"); - ExecuteOperationSteps(data2.processname, data2.processvalue); - } else if (recipe.processname.equals("主料")) { - if (ConfigName.getInstance().versionSelectionEnum.contains("一拖")) { - BPA_GOODSRECIPE data3 = Get位置("高速", "原点位"); - ExecuteOperationSteps(data3.processname, data3.processvalue); - } else { - BPA_GOODSRECIPE data3 = Get位置("高速", "炒菜位1"); - ExecuteOperationSteps(data3.processname, data3.processvalue); - } - } else if (recipe.processname.equals("辅料")) { - BPA_GOODSRECIPE data3 = Get位置("高速", "原点位"); - ExecuteOperationSteps(data3.processname, data3.processvalue); - } ExecuteOperationSteps(recipe.processname, recipe.processvalue); - - if (recipe.processname.equals("出菜")) { - BPA_GOODSRECIPE data4 = Get位置("高速", "炒菜位1"); - ExecuteOperationSteps(data4.processname, data4.processvalue); - } } } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); @@ -288,35 +261,20 @@ public class ExecuteTheRecipe { case "位置": Write_PLC_Location(formulation); break; - case "加热": + case "打火": Write_PLC_Heating(formulation); break; - case "主料": - if (ConfigName.getInstance().versionSelectionEnum.contains("一拖四")) { - Write_PLC_MainIngredients4(formulation); - } else if (ConfigName.getInstance().versionSelectionEnum.contains("一拖二")) { - Write_PLC_MainIngredients2(formulation); - } else { - Write_PLC_Ingredients(formulation); - } - break; - case "辅料": - if (ConfigName.getInstance().versionSelectionEnum.contains("一拖")) { - Write_PLC_MainAccessory(formulation); - } + case "约束条件": + Write_PLC_ConstraintCondition(formulation); break; - case "加水": - Write_PLC_Water(formulation); + case "主料": + Write_PLC_Ingredients(formulation); break; case "延迟": Write_PLC_Delay(formulation); break; case "出菜": - if (ConfigName.getInstance().versionSelectionEnum.contains("一拖")) { - Write_PLC_MainOutdishes(formulation); - } else { - Write_PLC_Outdishes(formulation); - } + Write_PLC_Outdishes(formulation); break; case "清洗": Write_PLC_CleanPan(formulation); @@ -440,10 +398,6 @@ public class ExecuteTheRecipe { String value = entry.getValue(); if (key.contains("(秒)")) { val = Integer.parseInt(value); - } else if (key.contains("速度")) { - int writeValue = GetMXValue(key, value); - //修改最高速度40 - WritePLC(key, writeValue >= 30 ? 30 : writeValue, null); } } @@ -496,148 +450,50 @@ public class ExecuteTheRecipe { */ private static void Write_PLC_Ingredients(HashMap data) { try { - //是否手动 - boolean ishand = true; ToastUtils.info("准备倒入主料!"); - //region 判断是否手动 - if (ConfigName.getInstance().versionSelectionEnum.equals("大炒版本")) { - ishand = true; - } else { - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("投料动作")) { - if (value.contains("手动投料")) { - ishand = true; - } else { - ishand = false; - } - } + String name = ""; + String zl = ""; + for (HashMap.Entry entry : data.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue(); + if (key.contains("名称")) { + name = value; + } else if (key.contains("重量")) { + zl = value; } } - //endregion - - - if (ishand) { - if (ConfigName.getInstance().versionSelectionEnum.equals("大炒自动投料版本") || ConfigName.getInstance().versionSelectionEnum.equals("小炒版本")) { - ExecuteTheRecipe.BottomClick1("平移-去1号位"); - } - String name = ""; - String zl = ""; - int val = 0; - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("名称")) { - name = value; - } else if (key.contains("重量")) { - zl = value; - } - } - ToastUtils.info("工序:手动投料," + name + "," + zl); - String title = "手动投料-温馨提示!"; - String message = "客官请投入主料,[" + name + "]重量" + zl + "g,投入后点击[确定]继续流程!"; - ExecuteTheRecipe.WritePLC("暂停开关", true, null); - - final boolean[] IsComplete = {false}; - Activity activity = findActivity(context); - if (activity != null) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - try { - - new QMUIDialog.MessageDialogBuilder(context).setCancelable(false).setTitle(title).setMessage(message).addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - IsComplete[0] = true; - dialog.dismiss(); - } - }).create(com.qmuiteam.qmui.R.style.QMUI_Dialog).show(); - - } catch (Exception e) { - - } - } - }); - } - - while (!IsComplete[0]) { - Thread.sleep(100);//10 *6 - } - ExecuteTheRecipe.WritePLC("暂停开关", false, null); - ToastUtils.info("确定完成,继续制作!"); - } else { - //自动投料 - if (ConfigName.getInstance().versionSelectionEnum.equals("大炒自动投料版本") || ConfigName.getInstance().versionSelectionEnum.equals("小炒版本")) { - String writeValue = "1号位"; - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("主料位置")) { - writeValue = value; - } - } - if (ExecuteCurrentOperation != null) { - ExecuteCurrentOperation.Run("主料" + "|" + writeValue); - } - - - //1.去某一个位置 - BottomClick1("平移-去" + writeValue); + ToastUtils.info("工序:手动投料," + name + "," + zl); + String title = "手动投料-温馨提示!"; + String message = "客官请投入主料,[" + name + "]重量" + zl + "g,投入后点击[确定]继续流程!"; + final boolean[] IsComplete = {false}; + Activity activity = findActivity(context); + if (activity != null) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + try { + new QMUIDialog.MessageDialogBuilder(context).setCancelable(false).setTitle(title).setMessage(message).addAction("确定", new QMUIDialogAction.ActionListener() { + @Override + public void onClick(QMUIDialog dialog, int index) { + IsComplete[0] = true; + dialog.dismiss(); + } + }).create(com.qmuiteam.qmui.R.style.QMUI_Dialog).show(); + } catch (Exception e) { - Log.d("平移", "平移-去" + writeValue); - //一直等待机器移动到该位置,否则就一直等待 6s超时 - String name = "平移轴在" + writeValue; - final boolean[] IsComplete = {false}; - long a = System.currentTimeMillis(); - while (!IsComplete[0] && !IsForcedEnd) { - if ((System.currentTimeMillis() - a) > 1000 * whileTime) { - break; - } else { - Object sb = ReadPLC(name);// ListeningValue.get(name); - if (sb != null) { - IsComplete[0] = (boolean) (sb); - } - } - Thread.sleep(100);//10 *6 - } - Log.d("平移", name + "已经就位"); - - //2.给倒菜启动 - BottomClick1("主料"); - name = "倒菜完成"; - IsComplete[0] = false; - a = System.currentTimeMillis(); - while (!IsComplete[0] && !IsForcedEnd) { - if ((System.currentTimeMillis() - a) > 1000 * whileTime) { - break; - } else { - Object sb = ReadPLC(name);// ListeningValue.get(name); - if (sb != null) { - IsComplete[0] = (boolean) (sb); - } } - Thread.sleep(100);//10 *6 } - ToastUtils.info("主料倒入完成,继续制作!"); - - } + }); } - Log.d("倒菜", "倒菜完成了"); - if (IsMoveYiHaoWei()) { - if (ConfigName.getInstance().versionSelectionEnum.equals("大炒自动投料版本") || ConfigName.getInstance().versionSelectionEnum.equals("小炒版本")) { - ExecuteTheRecipe.BottomClick1("平移-去1号位"); - Log.d("移动去", "1号位"); - } + while (!IsComplete[0]) { + Thread.sleep(100);//10 *6 } - //默认去炒制位置1去等待 - BPA_GOODSRECIPE data3 = Get位置("高速", "炒菜位1"); - ExecuteOperationSteps(data3.processname, data3.processvalue); + ToastUtils.info("确定完成,继续制作!"); + Log.d("倒菜", "倒菜完成了"); //判断是否有烹饪时间 int val = 0; @@ -725,18 +581,12 @@ public class ExecuteTheRecipe { val = Integer.parseInt(value); } else { ToastUtils.info("工序:" + key + "," + value); - int writeValue = GetMXValue(key, value); - if (ExecuteCurrentOperation != null) { - ExecuteCurrentOperation.Run("加热" + "|" + writeValue); - } - //写加热挡位 - WritePLC(key, writeValue, null); - if (writeValue == 0) { - ConfigName.getInstance().IsOpenHuoLi = false; - WritePLC("加热", false, null); - } else { - ConfigName.getInstance().IsOpenHuoLi = true; - WritePLC("加热", true, null); + if(value.contains("自动打火")) + { + //WritePLC(value,true,null); + }else //手动打火 + { + } } } @@ -752,11 +602,11 @@ public class ExecuteTheRecipe { } /** - * 写PLC加水 + * 写PLC 约束条件 * * @param data */ - private static void Write_PLC_Water(HashMap data) { + private static void Write_PLC_ConstraintCondition(HashMap data) { try { int val = 0; for (HashMap.Entry entry : data.entrySet()) { @@ -764,36 +614,24 @@ public class ExecuteTheRecipe { String value = entry.getValue(); if (key.contains("(秒)")) { val = Integer.parseInt(value); + } else { + + } } - if (ExecuteCurrentOperation != null) { - ExecuteCurrentOperation.Run("加水" + "|" + val); - } if (val > 0 && !IsForcedEnd) { - WritePLC("炒锅抽水", true, null); - final boolean[] IsComplete = {false}; - new Handler(Looper.getMainLooper()).postDelayed(new Runnable() { - @Override - public void run() { - IsComplete[0] = true; - } - }, val * 1000); - - long a = System.currentTimeMillis(); - while (!IsComplete[0]) { - if ((System.currentTimeMillis() - a) > 1000 * whileTime) { - break; - } - Thread.sleep(100); - } - ExecuteTheRecipe.WritePLC("炒锅抽水", false, null); + ThreadDelay(val); + //Thread.sleep(val * 1000); } + } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); } } + + /** * 写PLC 延迟 * @@ -910,579 +748,104 @@ public class ExecuteTheRecipe { } //endregion - //region 一拖四写PLC工序 - + //region 主页按钮 /** - * 写PLC主料 一拖4 + * 火力点击 * * @param data */ - private static void Write_PLC_MainIngredients4(HashMap data) { + public static void Write_PLC_HuoLI(int data) { try { - //是否手动 - boolean ishand = true; - ToastUtils.info("准备倒入主料!"); - - //region 判断是否手动 - if (ConfigName.getInstance().versionSelectionEnum.equals("大炒版本")) { - ishand = true; - } else { - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("投料动作")) { - if (value.contains("手动投料")) { - ishand = true; - } else { - ishand = false; - } - } - } - } - //endregion - - - if (ishand) { - String name = ""; - String zl = ""; - int val = 0; - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("名称")) { - name = value; - } else if (key.contains("重量")) { - zl = value; - } - } - ToastUtils.info("工序:手动投料," + name + "," + zl); - String title = "手动投料-温馨提示!"; - String message = "客官请投入主料,[" + name + "]重量" + zl + "g,投入后点击[确定]继续流程!"; - ExecuteTheRecipe.WritePLC("暂停开关", true, null); - - final boolean[] IsComplete = {false}; - Activity activity = findActivity(context); - if (activity != null) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - try { - - new QMUIDialog.MessageDialogBuilder(context).setCancelable(false).setTitle(title).setMessage(message).addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - IsComplete[0] = true; - dialog.dismiss(); - } - }).create(com.qmuiteam.qmui.R.style.QMUI_Dialog).show(); - - } catch (Exception e) { - - } - } - }); - } - - while (!IsComplete[0]) { - Thread.sleep(100);//10 *6 - } - ExecuteTheRecipe.WritePLC("暂停开关", false, null); - ToastUtils.info("确定完成,继续制作!"); - } else { - //自动投料 - String writeValue = "1号位"; - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("主料位置")) { - if (!value.contains("3") && !value.contains("4")) { - writeValue = value; - } - } - } - if (ExecuteCurrentOperation != null) { - ExecuteCurrentOperation.Run("主料" + "|" + writeValue); - } - - //2.给倒菜启动 - BottomClick1("主料" + writeValue); - String name = writeValue + "倒菜完成"; - final boolean[] IsComplete = {false}; - long a = System.currentTimeMillis(); - while (!IsComplete[0] && !IsForcedEnd) { - if ((System.currentTimeMillis() - a) > 1000 * whileTime) { - break; + WritePLC("加热功率", data, new IWriteCallBack() { + @Override + public void onSuccess() { + if (data == 0) { + ConfigName.getInstance().IsOpenHuoLi = false; + WritePLC("加热", false, null); } else { - Object sb = ReadPLC(name);// ListeningValue.get(name); - if (sb != null) { - IsComplete[0] = (boolean) (sb); - } + ConfigName.getInstance().IsOpenHuoLi = true; + WritePLC("加热", true, null); } - Thread.sleep(100);//10 *6 } - ToastUtils.info("主料倒入完成,继续制作!"); - } - Log.d("倒菜", "倒菜完成了"); - - if (IsMoveYiHaoWei()) { - WriteMainPLC("炒锅投主料完成", true, null); - } - //默认去炒制位置1去等待 - BPA_GOODSRECIPE data3 = Get位置("高速", "炒菜位1"); - ExecuteOperationSteps(data3.processname, data3.processvalue); - - //判断是否有烹饪时间 - int val = 0; - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("(秒)")) { - val = Integer.parseInt(value); + @Override + public void onFailure(String ErrorMsg) { } - } - if (val > 0 && !IsForcedEnd) { - ThreadDelay(val); - //Thread.sleep(val * 1000); - } - - Log.d("烹饪时间", "烹饪时间完成了"); - + }); + ToastUtils.info("火力按钮点击,当前级别:" + data); } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); } } + //endregion + + //region PLC监听线程 /** - * 写PLC主料 一拖2 - * - * @param data + * 自提设备监听 */ - private static void Write_PLC_MainIngredients2(HashMap data) { - try { - //是否手动 - boolean ishand = true; - ToastUtils.info("准备倒入主料!"); + public static void Listening() { - //region 判断是否手动 - if (ConfigName.getInstance().versionSelectionEnum.equals("大炒版本")) { - ishand = true; - } else { - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("投料动作")) { - if (value.contains("手动投料")) { - ishand = true; - } else { - ishand = false; - } - } - } + ConfigName.getInstance().PLC_Address.clear(); + ArrayList address = QueryDB.GetPlcaddressALL(); + for (BPA_PLCADDRESS item : address) { + if (!item.address.isEmpty() && !item.address.equals("-------------")) { + ConfigName.getInstance().PLC_Address.put(item.name, item); } - //endregion - - - if (ishand) { - String name = ""; - String zl = ""; - int val = 0; - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("名称")) { - name = value; - } else if (key.contains("重量")) { - zl = value; - } - } - ToastUtils.info("工序:手动投料," + name + "," + zl); - String title = "手动投料-温馨提示!"; - String message = "客官请投入主料,[" + name + "]重量" + zl + "g,投入后点击[确定]继续流程!"; - ExecuteTheRecipe.WritePLC("暂停开关", true, null); - - final boolean[] IsComplete = {false}; - Activity activity = findActivity(context); - if (activity != null) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - try { - - new QMUIDialog.MessageDialogBuilder(context).setCancelable(false).setTitle(title).setMessage(message).addAction("确定", new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { - IsComplete[0] = true; - dialog.dismiss(); - } - }).create(com.qmuiteam.qmui.R.style.QMUI_Dialog).show(); + } - } catch (Exception e) { + new Thread(new Runnable() { + @Override + public void run() { + try { + WritePLC("初始化", true, null); + Thread.sleep(500); + WritePLC("初始化", false, null); - } - } - }); - } + ExecuteTheRecipe.WritePLC("温控开关", false, null);//开关闭合 + ExecuteTheRecipe.WritePLC("暂停开关", false, null);//开关闭合 - while (!IsComplete[0]) { - Thread.sleep(100);//10 *6 - } - ExecuteTheRecipe.WritePLC("暂停开关", false, null); - ToastUtils.info("确定完成,继续制作!"); - } else { - //自动投料 - String writeValue = "1号位"; - if (ExecuteCurrentOperation != null) { - ExecuteCurrentOperation.Run("主料" + "|" + writeValue); + ExecuteTheRecipe.WritePLC("校准时间", 50, null);//默认校准时间5秒 + ExecuteTheRecipe.WritePLC("料仓1校准开关", false, null);//默认校准时间5秒 + ExecuteTheRecipe.WritePLC("料仓2校准开关", false, null);//默认校准时间5秒 + ExecuteTheRecipe.WritePLC("料仓3校准开关", false, null);//默认校准时间5秒 + } catch (InterruptedException e) { + ToastUtils.info("异常信息:" + e.getMessage()); } + } + }).start(); - WriteMainPLC("机器人投放主料完成", false, null); - WriteMainPLC("炒锅请求投主料", true, null); - boolean isJre = false; - Object K = ReadPLC("加热"); - isJre = K == null ? false : (boolean) K; - if (isJre) { - ExecuteTheRecipe.WritePLC("加热", false, null); - }//提前关闭加热 - - final boolean[] IsComplete = {false}; - long a = System.currentTimeMillis(); - while (!IsComplete[0] && !IsForcedEnd) { - if ((System.currentTimeMillis() - a) > 1000 * (whileTime * 10)) { - break; - } else { - Object sb = ReadMainPLC("机器人投放主料完成");//ListeningValue.get(name); - if (sb != null) { - IsComplete[0] = (boolean) (sb); + ThreadManager.Get().StartLong("PLC设备数据监听", true, new IThread() { + @Override + public void Run() throws InterruptedException { + try { + for (String item : ConfigName.getInstance().PLC_Address.keySet()) { + String key = item; + BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(item); + if (plcaddress.isread == 1) { + Object val = ReadPLC(key); + ListeningValue.put(key, val); } } - Thread.sleep(100);//10 *6 - } - WriteMainPLC("机器人投放主料完成", false, null); - if (isJre) { - ExecuteTheRecipe.WritePLC("加热", true, null); - }//再次释放加热 - } - Log.d("倒菜", "倒菜完成了"); - if (IsMoveYiHaoWei()) { - WriteMainPLC("炒锅投主料完成", true, null); - } + if (ConfigName.getInstance().PlcIsConnect) { + TempControl(); + ReadPLCStatus(); - //默认去炒制位置1去等待 - BPA_GOODSRECIPE data3 = Get位置("高速", "炒菜位1"); - ExecuteOperationSteps(data3.processname, data3.processvalue); + } - //判断是否有烹饪时间 - int val = 0; - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("(秒)")) { - val = Integer.parseInt(value); + } catch (Exception ex) { + ToastUtils.error("异常信息:" + ex.getMessage()); } + Thread.sleep(100); } - if (val > 0 && !IsForcedEnd) { - ThreadDelay(val); - //Thread.sleep(val * 1000); - } - - Log.d("烹饪时间", "烹饪时间完成了"); + @Override + public void RunComplete() throws InterruptedException { - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } - - /** - * 写PLC投辅料 - * - * @param data - */ - private static void Write_PLC_MainAccessory(HashMap data) { - try { - int val = 0; - for (HashMap.Entry entry : data.entrySet()) { - String key = entry.getKey(); - String value = entry.getValue(); - if (key.contains("(秒)")) { - val = Integer.parseInt(value); - } - } - - if (ExecuteCurrentOperation != null) { - ExecuteCurrentOperation.Run("辅料" + "|" + val); - } - WriteMainPLC("机器人放辅料完成", false, null); - WriteMainPLC("炒锅请求投辅料", true, null); - - - boolean isJre = false; - Object K = ReadPLC("加热"); - isJre = K == null ? false : (boolean) K; - if (isJre) { - ExecuteTheRecipe.WritePLC("加热", false, null); - }//提前关闭加热 - - final boolean[] IsComplete = {false}; - long a = System.currentTimeMillis(); - while (!IsComplete[0] && !IsForcedEnd) { - if ((System.currentTimeMillis() - a) > 1000 * (whileTime * 10)) { - break; - } else { - Object sb = ReadMainPLC("机器人放辅料完成");//ListeningValue.get(name); - if (sb != null) { - IsComplete[0] = (boolean) (sb); - } - } - Thread.sleep(100);//10 *6 - } - WriteMainPLC("机器人放辅料完成", false, null); - if (isJre) { - ExecuteTheRecipe.WritePLC("加热", true, null); - }//再次释放加热 - - //默认去炒制位置1去等待 - BPA_GOODSRECIPE data3 = Get位置("高速", "炒菜位1"); - ExecuteOperationSteps(data3.processname, data3.processvalue); - - if (val > 0 && !IsForcedEnd) { - ThreadDelay(val); - //Thread.sleep(val * 1000); - } - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } - - /** - * 写PLC 出菜 - * - * @param data - */ - private static void Write_PLC_MainOutdishes(HashMap data) { - try { - ToastUtils.info("准备出菜!"); - //先延迟 - 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); - if (all_list.size() > 0) { - ThreadDelay(val); - //Thread.sleep(val * 1000); - } - } - } - //ExecuteTheRecipe.WritePLC("搅拌", false, null); - ExecuteTheRecipe.WritePLC("加热", false, null); - - WriteMainPLC("炒锅出餐完成", false, null); - WriteMainPLC("机器人到达炒锅出餐位", false, null); - WriteMainPLC("炒菜完成请求出餐", true, null); - //等待机器人就位 - final boolean[] IsComplete = {false}; - long a = System.currentTimeMillis(); - while (!IsComplete[0] && !IsForcedEnd) { - if ((System.currentTimeMillis() - a) > 1000 * (whileTime * 10)) { - break; - } else { - Object sb = ReadMainPLC("机器人到达炒锅出餐位");//ListeningValue.get(name); - if (sb != null) { - IsComplete[0] = (boolean) (sb); - } - } - Thread.sleep(100);//10 *6 - } - WriteMainPLC("机器人到达炒锅出餐位", false, null); - WriteMainPLC("炒锅出餐减速到位", false, null); - - BottomClick1("出菜"); - - //一直等待机器移动到该位置,否则就一直等待 6s超时 - String name = "出餐启动反馈"; - IsComplete[0] = false; - a = System.currentTimeMillis(); - while (!IsComplete[0] && !IsForcedEnd) { - if ((System.currentTimeMillis() - a) > 1000 * (whileTime * 3)) { - break; - } else { - Object sb = ReadPLC(name);//ListeningValue.get(name); - if (sb != null) { - IsComplete[0] = (boolean) (sb); - } - Object jsw = ReadPLC("炒锅倒菜减速位");//ListeningValue.get(name); - if (jsw != null) { - WriteMainPLC("炒锅出餐减速到位", (Boolean) jsw, null); - } - } - Thread.sleep(100);//10 *6 - } - WriteMainPLC("炒锅出餐完成", true, null); - ToastUtils.info("出菜完成,锅体准备回到原位!"); - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } - //endregion - - //region 判断当前工序后是否还有 主料 不包含 手动配料 - - /** - * 是否还有 主料 不包含 手动配料 如果没有主料的话 那么就是对的 - * - * @return - */ - public static boolean IsMoveYiHaoWei() { - boolean IsMove = false; - try { - int k = 0; - ArrayList kkkkkk = new ArrayList<>(); - for (BPA_GOODSRECIPE item : all_list) { - if (k > Index_select) //查找当前工序 后的步骤 所有主料 - { - if (item.processname.contains("主料") && !item.processvalue.contains("手动投料"))// && - { - kkkkkk.add(item); - } - } - k++; - } - - - if (kkkkkk.size() <= 0 && all_list.size() > 0) { - IsMove = true; - } - - } catch (Exception ex) { - - } finally { - return IsMove; - } - } - //endregion - - //region 主页按钮 - - /** - * 点击摇欠按钮 - * - * @param data - */ - public static void Write_PLC_YaoQian(MyStatus data) { - try { - if (data == MyStatus.Start) { - ToastUtils.info("点击摇浅按钮"); - - } else if (data == MyStatus.Stop) { - ToastUtils.info("点击停摇按钮"); - } - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } - - /** - * 火力点击 - * - * @param data - */ - public static void Write_PLC_HuoLI(int data) { - try { - WritePLC("加热功率", data, new IWriteCallBack() { - @Override - public void onSuccess() { - if (data == 0) { - ConfigName.getInstance().IsOpenHuoLi = false; - WritePLC("加热", false, null); - } else { - ConfigName.getInstance().IsOpenHuoLi = true; - WritePLC("加热", true, null); - } - } - - @Override - public void onFailure(String ErrorMsg) { - } - }); - ToastUtils.info("火力按钮点击,当前级别:" + data); - - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - } - //endregion - - //region PLC监听线程 - - /** - * 自提设备监听 - */ - public static void Listening() { - - ConfigName.getInstance().PLC_Address.clear(); - ArrayList address = QueryDB.GetPlcaddressALL(); - for (BPA_PLCADDRESS item : address) { - if (!item.address.isEmpty() && !item.address.equals("-------------")) { - ConfigName.getInstance().PLC_Address.put(item.name, item); - } - } - - new Thread(new Runnable() { - @Override - public void run() { - try { - WritePLC("初始化", true, null); - Thread.sleep(500); - WritePLC("初始化", false, null); - - ExecuteTheRecipe.WritePLC("温控开关", false, null);//开关闭合 - ExecuteTheRecipe.WritePLC("暂停开关", false, null);//开关闭合 - - ExecuteTheRecipe.WritePLC("校准时间", 50, null);//默认校准时间5秒 - ExecuteTheRecipe.WritePLC("料仓1校准开关", false, null);//默认校准时间5秒 - ExecuteTheRecipe.WritePLC("料仓2校准开关", false, null);//默认校准时间5秒 - ExecuteTheRecipe.WritePLC("料仓3校准开关", false, null);//默认校准时间5秒 - } catch (InterruptedException e) { - ToastUtils.info("异常信息:" + e.getMessage()); - } - } - }).start(); - - ThreadManager.Get().StartLong("PLC设备数据监听", true, new IThread() { - @Override - public void Run() throws InterruptedException { - try { - for (String item : ConfigName.getInstance().PLC_Address.keySet()) { - String key = item; - BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(item); - if (plcaddress.isread == 1) { - Object val = ReadPLC(key); - ListeningValue.put(key, val); - } - } - - if (ConfigName.getInstance().PlcIsConnect) { - TempControl(); - ReadPLCStatus(); - - } - - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - Thread.sleep(100); - } - - @Override - public void RunComplete() throws InterruptedException { - - } - }); + } + }); ThreadManager.Get().StartLong("PLC设备-心跳", true, new IThread() { @Override @@ -1508,49 +871,6 @@ public class ExecuteTheRecipe { } }); } - - /** - * 主控设备监听 - */ - public static void MainListening() { - new Thread(new Runnable() { - @Override - public void run() { - for (String item : ConfigName.getInstance().MainPlcAddress.keySet()) { - if (!item.equals("商品信息")) { - WriteMainPLC(item, false, null); - } - } - } - }).start(); - - ThreadManager.Get().StartLong("主控PLC设备-心跳", true, new IThread() { - @Override - public void Run() throws InterruptedException { - try { - if (ConfigName.getInstance().PlcMainIsConnect) { - //心跳 - ReadPLCMainStatus(); - WriteMainPLC("心跳", false, null); - WriteMainPLC("炒锅空闲状态", ConfigName.getInstance().WokStatus, null); - WriteMainPLC("投料机构状态", ConfigName.getInstance().TouLiaoStatus, null); - Log.e("炒锅状态", "炒锅状态: " + ConfigName.getInstance().WokStatus); - Log.e("投料机构状态", "投料机构状态: " + ConfigName.getInstance().TouLiaoStatus); - //读取主控下发的商品 - ReadMasterDeliveryGoods(); - } - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } - Thread.sleep(2000); - } - - @Override - public void RunComplete() throws InterruptedException { - - } - }); - } //endregion //region PLC基础控制类 @@ -1622,59 +942,6 @@ public class ExecuteTheRecipe { } } - /** - * 写主控PLC数据 - * - * @param name - * @param value - */ - public static void WriteMainPLC(String name, boolean value, IWriteCallBack callback) { - try { - if (ConfigName.getInstance().MainPlcAddress.containsKey(name)) { - Integer plcaddress = ConfigName.getInstance().MainPlcAddress.get(name) + (ConfigName.getInstance().DeviceHao - 1) * 100; - if (ConfigName.getInstance().PlcMainIsConnect) { - ModbusTcpMainServer.get().WriteBool(String.valueOf(plcaddress), value, callback); - } - } - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } finally { - } - } - - /** - * 读主控PLC数据 - * - * @param name - * @return - */ - public static Object ReadMainPLC(String name) { - final Object[] ReturnsVariable = {null}; - try { - if (ConfigName.getInstance().MainPlcAddress.containsKey(name)) { - if (!name.equals("商品信息")) { - Integer plcaddress = ConfigName.getInstance().MainPlcAddress.get(name) + (ConfigName.getInstance().DeviceHao - 1) * 100; - if (ConfigName.getInstance().PlcMainIsConnect) { - ModbusTcpMainServer.get().ReadBool(String.valueOf(plcaddress), 1, val -> { - ReturnsVariable[0] = val[0]; - }); - } - } else { - Integer plcaddress = ConfigName.getInstance().MainPlcAddress.get(name) + (ConfigName.getInstance().DeviceHao - 1) * 20; - if (ConfigName.getInstance().PlcMainIsConnect) { - ModbusTcpMainServer.get().ReadString(String.valueOf(plcaddress), 36, val1 -> { - ReturnsVariable[0] = val1; - }); - } - } - } - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } finally { - return ReturnsVariable[0]; - } - } - /** * 实时状态 */ @@ -1750,28 +1017,6 @@ public class ExecuteTheRecipe { } } - /** - * 反馈主控制台状态 - */ - public static void ReadPLCMainStatus() { - try { - if (ConfigName.getInstance().PlcIsConnect) { - 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 = ReadPLC("初始化完成"); - boolean ob3 = obj3 == null ? false : (boolean) obj3; - ConfigName.getInstance().WokStatus = ob3 && !ExecuteTheRecipe.IsStart; - } - } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); - } finally { - } - } - /** * 温控 */ @@ -1803,116 +1048,9 @@ public class ExecuteTheRecipe { } } } - - /** - * 读取主控下发的商品 - */ - public static void ReadMasterDeliveryGoods() { - Object Ismake = ReadMainPLC("商品下发"); - if (Ismake != null) { - if ((boolean) Ismake) //信息来了,是否需要制作 - { - WriteMainPLC("商品下发", false, null); - Object obj = ReadMainPLC("商品信息"); - String id = obj == null ? "--------" : (String) obj; - - BPA_GOODS goods = QueryDB.GetGoodsId(id); - if (goods == null) { - WriteMainPLC("商品数据验证", false, null); - } else { - Object chushiover = ExecuteTheRecipe.getListingValue("初始化完成"); - if (!ConfigName.getInstance().PlcIsConnect) { - ToastUtils.warning("PLC未准备就绪!!!"); - WriteMainPLC("商品数据验证", false, null); - } else if (chushiover == null || !(boolean) chushiover) { - ToastUtils.warning("设备未初始化,请先手动初始化设备!!!"); - WriteMainPLC("商品数据验证", false, null); - } else if (ExecuteTheRecipe.IsStart) { - ToastUtils.warning("请耐心等待商品制作结束!!!"); - WriteMainPLC("商品数据验证", false, null); - } else { - WriteMainPLC("机器人准备就绪", false, null); - WriteMainPLC("商品数据验证", true, null); - boolean IsLaoVis = ConfigName.getInstance().user.name.equals("admin") || ConfigName.getInstance().user.account.equals("admin") || ConfigName.getInstance().user.userID.equals("超级管理员"); - if (IsLaoVis) { - DataBus.getInstance().mListener.clickListener(null, goods); - } else { - MessageManager.getInstance().sendMessage(MessageName.OpenMakeGoodFrom, goods.id); - } - boolean issucess = false; - try { - final boolean[] IsComplete = {false}; - long a = System.currentTimeMillis(); - while (!IsComplete[0]) { - 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) { - } - - if (issucess) { - if (IsLaoVis) { - MessageManager.getInstance().sendMessage(MessageName.IsStratMakeGood1, goods.id); - } else { - MessageManager.getInstance().sendMessage(MessageName.IsStratMakeGood, goods.id); - } - } - } - } - } - } - - //机器人急停,制作订单 应该暂停 - - //强制结束任务 - Object IsStop = ReadMainPLC("强制结束任务"); - if (IsStop != null) { - if ((boolean) IsStop) { - WriteMainPLC("强制结束任务", false, null);//复位 - - ExecuteTheRecipe.IsPause = false; - ExecuteTheRecipe.WritePLC("暂停开关", false, null); - ExecuteTheRecipe.SetForcedEnd();//设置强制结束 - } - } - -// Object IsJT = ReadMainPLC("机器人急停"); -// if (IsJT != null) { -// if ((boolean) IsJT)//异常情况 -// { -// //WritePLC("停止",true,null); -// } -// } - } //endregion //region 获取基础挡位变量 - - /** - * 获取位置 - * - * @param sd - * @return - */ - public static BPA_GOODSRECIPE Get位置(String sd, String name) { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType = 1; - pf.processname = "位置"; - pf.processms = "位置(" + sd + "," + name + ",0)"; - pf.processvalue = "转动速度," + sd + "|位置动作," + name + "|延迟(秒),0"; - return pf; - } - /** * 获取挡位变量 * @@ -1941,7 +1079,6 @@ public class ExecuteTheRecipe { //endregion //region 延迟函数 - /** * 线程延迟函数(避免线程阻塞等待) * @@ -1958,4 +1095,146 @@ public class ExecuteTheRecipe { } } //endregion + + //region 获取默认工艺 + /** + * 获取搅拌 + * @param sd 0-50 + * @return + */ + public static BPA_GOODSRECIPE Get搅拌(int sd) + { + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + pf.materialType=1; + pf.processname="搅拌"; + pf.processms="搅拌("+sd+",0)"; + pf.processvalue="搅拌速度,"+sd+"|等待(秒),0"; + return pf; + } + + /** + * 获取搅拌 + * @param data 自动打火、手动打火 + * @return + */ + public static BPA_GOODSRECIPE Get打火(String data) + { + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + pf.materialType=1; + pf.processname="打火"; + pf.processms="打火("+data+",0)"; + pf.processvalue="打火动作,"+data+"|等待(秒),0"; + return pf; + } + /** + * 获取位置 + * @param + * @return + */ + public static BPA_GOODSRECIPE Get位置(String name) + { + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + pf.materialType=1; + pf.processname="位置"; + pf.processms="位置("+name+",0)"; + pf.processvalue="位置动作,"+name+"|等待(秒),0"; + return pf; + } + /** + * 获取手动主料 + * + * @param + * @return + */ + public static BPA_GOODSRECIPE Get主料(int k1,int k2,int k3,int k4,int temp,int zl) { + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + pf.materialType = 1; + pf.processname = "主料"; + pf.processms = String.format("主料(未知,%d,%d,%d,%d,%d,%d,%d",k1,k2,k3,k4,temp,zl,0); + pf.processvalue = String.format("主料名称,未知|一环功率,%d|二环功率,%d|三环功率,%d|四环功率,%d|温度设定,%d|锅内重量,%d|烹饪(秒),%d",k1,k2,k3,k4,temp,zl,0); + return pf; + } + + /** + * 获取约束条件 + * + * @param + * @return + */ + public static BPA_GOODSRECIPE Get约束条件(int k1,int k2,int k3,int k4,int temp,int zl) { + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + pf.materialType = 1; + pf.processname = "约束条件"; + pf.processms = String.format("约束条件(%d,%d,%d,%d,%d,%d,%d",k1,k2,k3,k4,temp,zl,0); + pf.processvalue = String.format("一环功率,%d|二环功率,%d|三环功率,%d|四环功率,%d|温度设定,%d|锅内重量,%d|烹饪(秒),%d",k1,k2,k3,k4,temp,zl,0); + return pf; + } + + /** + * 获取选中行的变量 + * + * @return + */ + public static BPA_GOODSRECIPE Get物料(String name, String yl) { + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + try { + // 延迟,100|延迟,100|延迟,100|延迟,100| + String data = ""; + String desc = ""; + + pf.materialType = 0; + data += name + "," + yl + "|"; + desc += yl + ","; + + pf.processname = "物料"; + pf.processms = "物料" + "(" + desc.substring(0, desc.length() - 1) + ")"; + pf.processvalue = data.substring(0, data.length() - 1); + return pf; + } catch (Exception ex) { + return null; + } + } + /** + * 获取延迟 + * @param time + * @return + */ + public static BPA_GOODSRECIPE Get延迟(int time) + { + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + pf.materialType=1; + pf.processname="延迟"; + pf.processms="延迟("+time+")"; + pf.processvalue="等待(秒),"+time; + return pf; + } + + /** + * 获取出菜 + * @return + */ + public static BPA_GOODSRECIPE Get出菜(int k) + { + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + pf.materialType=1; + pf.processname="出菜"; + pf.processms="出菜("+k+")"; + pf.processvalue="等待(秒),"+k; + return pf; + } + + /** + * 获取清洗 + * + * @return + */ + public static BPA_GOODSRECIPE Get清洗(int k) { + BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); + pf.materialType = 1; + pf.processname = "清洗"; + pf.processms = "清洗(" + k + ")"; + pf.processvalue = "等待(秒)," + k; + return pf; + } + //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 12b87232..0e7896bc 100644 --- a/app/src/main/java/com/bonait/bnframework/business/MainInit.java +++ b/app/src/main/java/com/bonait/bnframework/business/MainInit.java @@ -26,8 +26,6 @@ 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; @@ -259,14 +257,14 @@ public class MainInit { { 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: 连接断开"); +// 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设备")) { 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 799ae106..c007ca6b 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 @@ -48,7 +48,7 @@ public class ConfigName { public Context dishesCon; public Context Home; public Application app; - public boolean IsPortraitScreen=true;//是否竖屏 + public boolean IsPortraitScreen = true;//是否竖屏 //endregion //region SD卡路径设置 @@ -413,6 +413,7 @@ public class ConfigName { public List Process_燃气大炒 = new ArrayList() {{ add(new ProcessT("搅拌", Arrays.asList("搅拌速度", "等待(秒)"))); add(new ProcessT("打火", Arrays.asList("打火动作", "等待(秒)"))); + add(new ProcessT("位置", Arrays.asList("位置动作", "等待(秒)"))); add(new ProcessT("约束条件", Arrays.asList("一环功率", "二环功率", "三环功率", "四环功率", "温度设定", "锅内重量", "等待(秒)"))); add(new ProcessT("主料", Arrays.asList("主料名称", "一环功率", "二环功率", "三环功率", "四环功率", "温度设定", "锅内重量", "烹饪(秒)"))); add(new ProcessT("物料", Arrays.asList())); @@ -420,32 +421,6 @@ public class ConfigName { add(new ProcessT("出菜", Arrays.asList("等待(秒)"))); add(new ProcessT("清洗", Arrays.asList("等待(秒)"))); }}; - /** - * 主控地址列表 - */ - public ConcurrentHashMap MainPlcAddress = new ConcurrentHashMap() {{ - put("炒锅空闲状态",1); //实时 - put("炒锅出餐完成",2); - put("炒锅投主料完成",3);//准备就绪,开始烹饪 - put("炒锅请求投辅料",4); - put("商品数据验证",5); - put("投料机构状态",6); //实时 - put("心跳",7); //实时 - put("炒菜完成请求出餐",8); - put("炒锅出餐减速到位",9); //实时 - put("炒锅请求投主料",10); - put("强制结束任务完成",11);//炒锅反馈强制结束任务完成 - - put("机器人准备就绪",51);//修改就绪信号 - put("机器人放辅料完成",52); - put("机器人到达炒锅出餐位",53); - put("商品下发",54); - put("机器人急停",55);//true 异常 false 正常 - put("机器人投放主料完成",56); - put("强制结束任务",57); - - put("商品信息",0); - }}; /** * 根据名称获取变量 @@ -457,8 +432,8 @@ public class ConfigName { String data = ""; if (item.equals("打火动作")) { data = "自动打火、手动打火"; - } else if (item.equals("投料动作")) { - data = "投出等待三秒、直接投出、手动投料"; + } else if (item.equals("位置动作")) { + data = "炒菜位、倒菜位、清洗位"; } return data; } @@ -503,15 +478,15 @@ public class ConfigName { /** * 最大火力级别 */ - public String HuoLi="八档"; + public String HuoLi = "八档"; /** * 最大温度:默认温度 */ - public int MaxTemp=200; + public int MaxTemp = 200; /** * 是否打开火力 */ - public boolean IsOpenHuoLi=false; + public boolean IsOpenHuoLi = false; //endregion /** * 炒锅状态上报信息 @@ -651,7 +626,7 @@ public class ConfigName { /** * 料仓显示物料 */ - public ConcurrentHashMap SilosDisplayMaterial = new ConcurrentHashMap() {{ + public ConcurrentHashMap SilosDisplayMaterial = new ConcurrentHashMap() {{ put(1, "未设置"); put(2, "未设置"); put(3, "未设置"); diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpMainHelper.java b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpMainHelper.java deleted file mode 100644 index 7cb6fae1..00000000 --- a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpMainHelper.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.bonait.bnframework.common.modbus; - -import com.licheedev.modbus4android.ModbusWorker; -import com.serotonin.modbus4j.ModbusMaster; - -public class ModbusTcpMainHelper extends ModbusWorker { - private static volatile ModbusTcpMainHelper instance = null; - - public static ModbusTcpMainHelper get() { - ModbusTcpMainHelper manager = instance; - if (manager == null) { - synchronized (ModbusTcpMainHelper.class) { - manager = instance; - if (manager == null) { - manager = new ModbusTcpMainHelper(); - instance = manager; - } - } - } - return manager; - } - - private ModbusTcpMainHelper() { - } - - /** - * 释放整个ModbusManager,单例会被置null - */ - public synchronized void release() { - super.release(); - instance = null; - } - - /** - * 获取 - * @return - */ - public synchronized ModbusMaster getModbusMaster() - { - return super.getModbusMaster(); - } - -} 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 deleted file mode 100644 index 18b42ffa..00000000 --- a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusTcpMainServer.java +++ /dev/null @@ -1,723 +0,0 @@ -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; -import com.bonait.bnframework.common.helper.I.IReadCallBack; -import com.bonait.bnframework.common.helper.I.IWriteCallBack; -import com.bonait.bnframework.common.helper.MessageLog; -import com.bonait.bnframework.common.utils.ToastUtils; -import com.licheedev.modbus4android.ModbusCallback; -import com.licheedev.modbus4android.ModbusParam; -import com.licheedev.modbus4android.ModbusRespException; -import com.licheedev.modbus4android.param.TcpParam; -import com.serotonin.modbus4j.ModbusMaster; -import com.serotonin.modbus4j.exception.ModbusInitException; -import com.serotonin.modbus4j.exception.ModbusTransportException; -import com.serotonin.modbus4j.msg.ReadCoilsResponse; -import com.serotonin.modbus4j.msg.ReadHoldingRegistersResponse; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.LineNumberReader; -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -/** - * 主控Tcp服务 - */ -public class ModbusTcpMainServer { - private static volatile ModbusTcpMainServer instance = null; - - public static ModbusTcpMainServer get() { - ModbusTcpMainServer manager = instance; - if (manager == null) { - synchronized (ModbusTcpMainServer.class) { - manager = instance; - if (manager == null) { - manager = new ModbusTcpMainServer(); - instance = manager; - } - } - } - return manager; - } - - private ModbusTcpMainServer() { - } - - static ModbusParam param; - - private int GetAddress(String address) { - if (address == null) return -1; - if (address.length() > 0) { - address = address.trim(); -// if (address.toUpperCase().contains("M") && address.length() >= 4) { -// String[] res = address.substring(1).split("[.]"); -// if (res != null && res.length == 2) { -// try { -// int firstAdd = Integer.parseInt(res[0]); -// int endAdd = Integer.parseInt(res[1]); -// if (endAdd >= 0 && endAdd <= 7) { -// return (firstAdd * 8) + 320 + endAdd; -// } -// } catch (NumberFormatException e) { -// return -1; -// } -// } -// } else if (address.toUpperCase().contains("I") && address.length() >= 4) { -// String[] res = address.substring(1).split("[.]"); -// if (res != null && res.length == 2) { -// try { -// int firstAdd = Integer.parseInt(res[0]); -// int endAdd = Integer.parseInt(res[1]); -// if (endAdd >= 0 && endAdd <= 7) { -// return (firstAdd * 8) + endAdd; -// } -// } catch (NumberFormatException e) { -// return -1; -// } -// } -// } else if ((address.toUpperCase().contains("VW") || address.toUpperCase().contains("VD")) && address.length() >= 3) { -// String res = address.substring(2); -// if (res != null) { -// try { -// int tempAdd = Integer.parseInt(res); -// return (tempAdd / 2) + 100; -// } catch (NumberFormatException e) { -// return -1; -// } -// } -// } else { -// try { -// return Integer.parseInt(address); -// } catch (NumberFormatException e) { -// return -1; -// } -// } - try { - return Integer.parseInt(address); - } catch (NumberFormatException e) { - return -1; - } - } - return -1; - } - - /** - * 获取布尔位地址信息 - * 列:M2.5 = getBitSingleAdd("M",2,5); - * - * @param Prefix 地址标头 - * @param startAdd 起始地址编号 - * @param num 要获取的第几位数量 - * @return - */ - public String getBitSingleAdd(String Prefix, int startAdd, int num) { - if (num > 0) { - int FirstAdd = num / 8; - int EndAdd = num % 8; - if (EndAdd == 0) { - FirstAdd--; - EndAdd = 7; - } else { - EndAdd--; - } - return Prefix + FirstAdd + startAdd + "." + EndAdd; - } - return ""; - } - - /** - * Ping PLC地址是否通畅 - * @param address - * @param pingTimes ping的次数 - * @param timeOut 超时时间 10 - * @return - */ - public static boolean ping2(String address, int pingTimes, int timeOut) { - Process process = null; - try { - process = Runtime.getRuntime().exec( "ping " + "-c " + pingTimes + " -w " + timeOut+ " "+address); - InputStreamReader r = new InputStreamReader(process.getInputStream()); - - LineNumberReader returnData = new LineNumberReader(r); - - String returnMsg=""; - - String line = ""; - - while ((line = returnData.readLine()) != null) { - - System.out.println(line); - - returnMsg += line; - - } - - if(returnMsg.indexOf("100% packet loss")!=-1){ - System.out.println("与 " +address +" 连接不畅通."); - //ToastUtils.info("与 " +address +" 连接不畅通."); - return false; - } else{ - System.out.println("与 " +address +" 连接畅通."); - //ToastUtils.info("与 " +address +" 连接不畅通."); - return true; - } - } catch (IOException e) { - // e.printStackTrace(); - } - return false; - - } - - - - - /** - * 连接PLC - */ - public static void ConnectPLC() - { - String host=ConfigName.getInstance().MainAddress; - int port=ConfigName.getInstance().MainPost; - param = TcpParam.create(host, port) - .setTimeout(1000) - .setRetries(0) - .setEncapsulated(false) - .setKeepAlive(true); - ModbusTcpMainHelper.get().init(param, new ModbusCallback() { - @Override - public void onSuccess(ModbusMaster modbusMaster) { - ToastUtils.info("设备 " + ConfigName.getInstance().MainAddress + " 连接成功"); - - 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()); - Log.e("主控PLC", "主控PLC: 连接断开"); - - } - @Override - public void onFinally() { - - } - }); - } - - - private Float BytesToFloat(byte[] buffers, DataFormat df) { - if (buffers.length == 4) { - byte[] bytes = new byte[4]; - if (df == DataFormat.ABCD) { - bytes[0] = buffers[3]; - bytes[1] = buffers[2]; - bytes[2] = buffers[1]; - bytes[3] = buffers[0]; - } else if (df == DataFormat.CDAB) { - bytes[0] = buffers[1]; - bytes[1] = buffers[0]; - bytes[2] = buffers[3]; - bytes[3] = buffers[2]; - } else if (df == DataFormat.BADC) { - bytes[0] = buffers[2]; - bytes[1] = buffers[3]; - bytes[2] = buffers[0]; - bytes[3] = buffers[1]; - } else if (df == DataFormat.DCBA) { - bytes[0] = buffers[0]; - bytes[1] = buffers[1]; - bytes[2] = buffers[2]; - bytes[3] = buffers[3]; - } - return ByteBuffer.wrap(bytes).getFloat(); - } - return 0.0f; - } - - private Integer BytesToInt(byte[] buffers, DataFormat df) { - if (buffers.length == 4) { - byte[] bytes = new byte[4]; - if (df == DataFormat.ABCD) { - bytes[0] = buffers[3]; - bytes[1] = buffers[2]; - bytes[2] = buffers[1]; - bytes[3] = buffers[0]; - } else if (df == DataFormat.CDAB) { - bytes[0] = buffers[1]; - bytes[1] = buffers[0]; - bytes[2] = buffers[3]; - bytes[3] = buffers[2]; - } else if (df == DataFormat.BADC) { - bytes[0] = buffers[2]; - bytes[1] = buffers[3]; - bytes[2] = buffers[0]; - bytes[3] = buffers[1]; - } else if (df == DataFormat.DCBA) { - bytes[0] = buffers[0]; - bytes[1] = buffers[1]; - bytes[2] = buffers[2]; - bytes[3] = buffers[3]; - } - return ByteBuffer.wrap(bytes).getInt(); - } - return 0; - } - - private byte[] IntToByte(int number) { - int temp = number; - byte[] b = new byte[4]; - for (int i = 0; i < b.length; i++) { - b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位 - temp = temp >> 8; // 向右移8位 - } - return b; - } - - private short[] IntToShorts(int value) { - short[] res = new short[2]; - int temp = value; - byte[] b = new byte[4]; - for (int i = 0; i < b.length; i++) { - b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位 - temp = temp >> 8; // 向右移8位 - } - for (int i = 0; i < res.length; i++) { - short s0 = (short) (b[i * 2] & 0xff);// 最低位 - short s1 = (short) (b[i * 2 + 1] & 0xff); - s1 <<= 8; - res[i] = (short) (s0 | s1); - } - return res; - } - - public static String GetString(short[] src, int start, int len) throws UnsupportedEncodingException { - short[] temp = new short[len]; - for (int i = 0; i < len; i++) { - temp[i] = src[i + start]; - } - byte[] bytesTemp = shorts2Bytes(temp); - for (int i = 0; i < bytesTemp.length; i++) { - byte b = bytesTemp[i]; - } - String str = new String(bytesTemp, "UTF-8"); - return str; - } - - public static byte[] shorts2Bytes(short[] data) { - byte[] byteValue = new byte[data.length * 2]; - for (int i = 0; i < data.length; i++) { - byteValue[i * 2] = (byte) (data[i] & 0xff); - byteValue[i * 2 + 1] = (byte) ((data[i] & 0xff00) >> 8); - } - return byteValue; - } - - /*** - *读取实时状态 - * @param Address the address - * @param length 读取的长度 3 - * @param callback 读取成功的回调 - */ - public void ReadStatus(String Address, int length, IReadCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ReadHoldingRegistersResponse res = ModbusTcpMainHelper.get().syncReadHoldingRegisters(1, add, length); - byte[] data = res.getData(); - byte[] tempData = new byte[6]; - tempData[0] = data[1]; - tempData[1] = data[0]; - if (callback != null) callback.onSuccess(tempData); - } catch (InterruptedException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - /*** - *读取扫码数据 - * @param Address the address - * @param length 读取的长度 - * @param callback 读取成功的回调 - */ - public void ReadString(String Address, int length, IReadCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ReadHoldingRegistersResponse res = ModbusTcpMainHelper.get().syncReadHoldingRegisters(1, add, length); - byte[] data = res.getData(); - byte[] data1 = Arrays.copyOfRange(data, 0, length); - //36 GUID 18 Number - String id = ""; - try { - byte[] tempdata = new byte[length]; - for (int i = 0; i < data1.length; i++) { - if (i % 2 == 0) { - - tempdata[i + 1] = data1[i]; - } else { - tempdata[i - 1] = data1[i]; - } - } - id = new String(tempdata, "UTF-8").trim(); - } catch (UnsupportedEncodingException ex) { - } - if (callback != null) callback.onSuccess(id); - } catch (InterruptedException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - public void WriteString(String Address, int length, IWriteCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - short[] send = new short[length]; - for (short item : send) { - item = 0; - } - try { - ModbusTcpMainHelper.get().syncWriteRegisters(1, add, send); - if (callback != null) - callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void ReadShort(String Address, int length, IReadCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ReadHoldingRegistersResponse res = ModbusTcpMainHelper.get().syncReadHoldingRegisters(1, add, length); - short[] data = res.getShortData(); - if (data.length == length) { - if (callback != null) callback.onSuccess(data); - } - } catch (InterruptedException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - public void ReadBool(String Address, int length, IReadCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ReadCoilsResponse res = ModbusTcpMainHelper.get().syncReadCoil(1, add, length); - boolean[] data = res.getBooleanData(); - boolean[] result = Arrays.copyOfRange(data, 0, length); - if (result.length == length) { - if (callback != null) callback.onSuccess(result); - } - } catch (InterruptedException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - public void ReadFloat(String Address, int length, IReadCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ReadHoldingRegistersResponse res = ModbusTcpMainHelper.get().syncReadHoldingRegisters(1, add, length); - byte[] data = res.getData(); - float[] tempValues = new float[length]; - for (int i = 0; i < length; i++) { - byte[] tempData = new byte[4]; - for (int m = 0; m < 4; m++) { - tempData[m] = data[i * 4 + m]; - } - tempValues[i] = BytesToFloat(tempData, DataFormat.ABCD); - } - if (tempValues.length == length) { - if (callback != null) callback.onSuccess(tempValues); - } - } catch (InterruptedException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - public void ReadInt(String Address, int length, IReadCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ReadHoldingRegistersResponse res = ModbusTcpMainHelper.get().syncReadHoldingRegisters(1, add, length * 2); - byte[] data = res.getData(); - int[] tempValues = new int[length]; - if(data.length>=4) - { - for (int i = 0; i < length; i++) { - byte[] tempData = new byte[4]; - for (int m = 0; m < 4; m++) { - tempData[m] = data[i * 4 + m]; - } -// Integer a1 = tempValues[i] = BytesToInt(tempData, DataFormat.ABCD); -// Integer a2 = tempValues[i] = BytesToInt(tempData, DataFormat.BADC); -// Integer a3 = tempValues[i] = BytesToInt(tempData, DataFormat.CDAB); -// Integer a4 = tempValues[i] = BytesToInt(tempData, DataFormat.DCBA); - tempValues[i] = BytesToInt(tempData, DataFormat.BADC); - } - }else - { - MessageLog.ShowError("ReadInt onFailure,Address=" ); - - } - if (callback != null) callback.onSuccess(tempValues); - } catch (InterruptedException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - public void WriteShort(String Address, short Value, IWriteCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - short[] send = new short[1]; - send[0] = Value; - try { - ModbusTcpMainHelper.get().syncWriteRegisters(1, add, send); - if (callback != null) - callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void WriteBool(String Address, boolean Value, IWriteCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ModbusTcpMainHelper.get().syncWriteCoil(1, add, Value); - if (callback != null) - callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void WriteFloat(String Address, float Value, IWriteCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - int intBits = Float.floatToRawIntBits(Value); - short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)}; - try { - ModbusTcpMainHelper.get().syncWriteRegisters(1, add, send); - - if (callback != null) callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void WriteInt(String Address, int Value, IWriteCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - short[] send = IntToShorts(Value); - try { - ModbusTcpMainHelper.get().syncWriteRegisters(1, add, send); - if (callback != null) callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void WriteShort(String Address, short Value) { - int add = GetAddress(Address); - if (add < 0) return; - short[] send = new short[1]; - send[0] = Value; - try { - ModbusTcpMainHelper.get().syncWriteRegisters(1, add, send); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } - } - - public void WriteBool(String Address, boolean Value) { - int add = GetAddress(Address); - if (add < 0) return; - - try { - ModbusTcpMainHelper.get().syncWriteCoil(1, add, Value); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } - } - - public void WriteFloat(String Address, float Value) { - int add = GetAddress(Address); - if (add < 0) return; - int intBits = Float.floatToRawIntBits(Value); - short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)}; - try { - ModbusTcpMainHelper.get().syncWriteRegisters(1, add, send); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } - } - - public void WriteInt(String Address, int Value) { - int add = GetAddress(Address); - if (add < 0) return; - short[] send = IntToShorts(Value); - try { - ModbusTcpMainHelper.get().syncWriteRegisters(1, add, send); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } - } -} diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/S7/IS7ConnHelper.java b/app/src/main/java/com/bonait/bnframework/common/modbus/S7/IS7ConnHelper.java new file mode 100644 index 00000000..d0a5e9a6 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/modbus/S7/IS7ConnHelper.java @@ -0,0 +1,15 @@ +package com.bonait.bnframework.common.modbus.S7; + +import com.bonait.bnframework.common.modbus.S7.mode.MyGunData; + +import java.io.IOException; + +public interface IS7ConnHelper { + void initConnect() throws IOException; + Object readPlcData(Integer dbNum, Class clazz, int offSet); + MyGunData readTheDbData(Integer dbNum, MyGunData clazz, int offSet); + void writePlcData(Integer dbNum, MyGunData clazz, int offSet); + + //DB,DB号,偏移量,Byte数组 + void writePlcByte(byte[] bytes); +} diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/S7/S7ConnHelper.java b/app/src/main/java/com/bonait/bnframework/common/modbus/S7/S7ConnHelper.java new file mode 100644 index 00000000..b7f13e42 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/modbus/S7/S7ConnHelper.java @@ -0,0 +1,136 @@ +package com.bonait.bnframework.common.modbus.S7; + +import android.util.Log; + +import com.bonait.bnframework.common.modbus.S7.mode.MyGunData; +import com.bonait.bnframework.common.modbus.S7.mode.MyS7Entity; +import com.github.s7connector.api.DaveArea; +import com.github.s7connector.api.S7Connector; +import com.github.s7connector.api.S7Serializer; +import com.github.s7connector.api.factory.S7ConnectorFactory; +import com.github.s7connector.api.factory.S7SerializerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * S7系列读取 + */ +public class S7ConnHelper implements IS7ConnHelper { + + /** + * ip + */ + public String Ip = "192.168.0.12"; + /** + * 端口 + */ + public Integer Port = 102; + public S7Connector s7Connector; + public S7Serializer s7Serializer; + public MyS7Entity myDbData; //S7数据返回 + private List myDbDatas = new ArrayList(); + public Boolean isConnected = false; + private Boolean heart = false; + public Map myMap = new HashMap<>(); + + @Override + public void initConnect() throws IOException { + if (this.s7Connector == null) { + this.s7Connector = S7ConnectorFactory.buildTCPConnector() + .withHost(Ip) + .withPort(Port) + .withRack(0)//机架号 + .withSlot(1)//插槽号 + .build(); + this.s7Serializer = S7SerializerFactory.buildSerializer(s7Connector); + this.isConnected = true; + } + } + + /** + * @param dbNum DB号 + * @param clazz 变量 + * @param offSet 偏移量 + */ + @Override + public Object readPlcData(Integer dbNum, Class clazz, int offSet) { + //第一个参数:DaveArea.DB 表示读取PLC的地址区域为DB + //第二个参数:DB块地址,若plc中是DB1000,则填1000 + //第三个参数:数据长度 + //第四个参数:偏移量 + if (this.isConnected = true) { + this.myDbData = (MyS7Entity) this.s7Serializer.dispense(clazz, dbNum, offSet); + + //心跳 + if (heart == false) { + this.myDbData.heartBeat = 10; + heart = true; + } else if (heart == true) { + this.myDbData.heartBeat = 20; + heart = false; + } + + try { + this.s7Serializer.store(this.myDbData, dbNum, offSet); + } + //断线重连 + catch (Exception ex) { + Show("断线重连" + ex.getMessage()); + this.isConnected = false; + try { + this.s7Connector.close(); + } catch (IOException e) { + e.printStackTrace(); + } + this.s7Connector = null; + this.s7Serializer = null; + try { + this.initConnect(); + } catch (IOException e) { + e.printStackTrace(); + } + } + this.myDbData = (MyS7Entity) this.s7Serializer.dispense(clazz, dbNum, offSet); + +// if (myDbDatas.size() < 30) { +// myDbDatas.add(myDbData); +// } else { +// myDbDatas.remove(0); +// } + + } + + return myDbData; + } + + @Override + public MyGunData readTheDbData(Integer dbNum, MyGunData clazz, int offSet) { + MyGunData myData = this.s7Serializer.dispense(clazz.getClass(), dbNum, offSet); + return myData; + } + + @Override + public void writePlcData(Integer dbNum, MyGunData clazz, int offSet) { + this.s7Serializer.store(clazz, dbNum, 0); + } + + /** + * DB,DB号,偏移量,Byte数组 + * @param bytes + */ + @Override + public void writePlcByte(byte[] bytes) { + this.s7Connector.write(DaveArea.DB, 31, 0, bytes); + } + + /** + * 显示日志 + */ + public void Show(String message) { + Log.e("S7帮助类", message); + } +} diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/S7/S7Listenner.java b/app/src/main/java/com/bonait/bnframework/common/modbus/S7/S7Listenner.java new file mode 100644 index 00000000..61b12c5a --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/modbus/S7/S7Listenner.java @@ -0,0 +1,107 @@ +package com.bonait.bnframework.common.modbus.S7; + +import android.util.Log; + +import com.bonait.bnframework.common.modbus.S7.mode.MyS7Entity; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.sql.Timestamp; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +public class S7Listenner { + public S7ConnHelper s7ConnHelper; + + Boolean last = false; + Boolean trigIn = false; + Boolean trigQ = false; + + + public void Conn() throws IOException { + s7ConnHelper.initConnect(); + Show("初始化成功!!"); + } + + //S7 + public void Listen(){ + + try { + s7ConnHelper.readPlcData(1, MyS7Entity.class, 0); + Map myMap = new HashMap<>(); + Field[] fields = s7ConnHelper.myDbData.getClass().getFields(); + for (Field f :fields + ) { + //log.info(f.getType().toString()); + + if (f.get(s7ConnHelper.myDbData) instanceof Double){ + String format = String.format("%.3f", f.get(s7ConnHelper.myDbData)); + myMap.put(f.getName(),format); + } + else { + myMap.put(f.getName(),f.get(s7ConnHelper.myDbData)); + } + + } + s7ConnHelper.myMap=myMap; + + + java.util.Date date = new Date();//获得当前时间 + Timestamp t = new Timestamp(date.getTime());//将时间转换成Timestamp类型,这样便可以存入到Mysql数据库中 + + for (String key: s7ConnHelper.myMap.keySet() + ) { + System.out.println(key); + } +// System.out.println("==============="); +// for (Object v: s7ConnHelper.getMyMap().values() +// ) { +// System.out.println(v); +// } + } + catch (Exception ex){ + Show(ex.getMessage()+"====="); + s7ConnHelper.s7Connector=null; + s7ConnHelper.s7Serializer=null; + try { + s7ConnHelper.initConnect(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + +// java.util.Date date = new Date();//获得当前时间 +// Timestamp t = new Timestamp(date.getTime());//将时间转换成Timestamp类型,这样便可以存入到Mysql数据库中 +// for (int i = 0 ; i 0)//如果大于0,那么加一个延迟 { - DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); + DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get延迟(time_c)); } - - String sdstr = Get速度(_speed); - BPA_GOODSRECIPE data = Get搅拌(sdstr); + BPA_GOODSRECIPE data = ExecuteTheRecipe.Get搅拌(_speed); DataBus.getInstance().bpa_goodsrecipes.add(data); ExecuteTheRecipe.ExecuteOperationSteps(data.processname, data.processvalue); @@ -870,57 +774,6 @@ public class DishTestActivity extends BaseActivity { } } - /** - * 投主菜品 - * - * @param num - */ - public void MainDish(int num) { -// Object sb = ExecuteTheRecipe.ReadPLC("平移轴在1号位"); -// if (sb != null) { -// if ((boolean) (sb)) { -// -// } else { -// ToastUtils.warning("平移轴未复位!!!"); -// } -// } else { -// ToastUtils.warning("PLC未连接!!!"); -// } - - SetZhiXingZhong(true); - - int time = (int) ((SystemClock.elapsedRealtime() - runtime.getBase()) / 1000);//当前点击多少秒 - int time_c = time - ClikTime; - new Thread(new Runnable() { - @Override - public void run() { - - BPA_GOODSRECIPE data1 = Get位置("高速", "炒菜位1"); - //DataBus.getInstance().bpa_goodsrecipes.add(data1); - ExecuteTheRecipe.ExecuteOperationSteps(data1.processname, data1.processvalue); - - BPA_GOODSRECIPE data = Get主料(num); - - ExecuteTheRecipe.ExecuteOperationSteps(data.processname, data.processvalue); - - runOnUiThread(new Runnable() { - @Override - public void run() { - if (time_c > 0)//如果大于0,那么加一个延迟 - { - DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); - } - DataBus.getInstance().bpa_goodsrecipes.add(data); - ToastUtils.warning("主料:" + num + "号仓投放"); - SetZhiXingZhong(false); - //刷新工序 - RefreshProcedure(); - } - }); - } - }).start(); - - } /** * 手动投主菜品 @@ -933,9 +786,9 @@ public class DishTestActivity extends BaseActivity { if (time_c > 0)//如果大于0,那么加一个延迟 { - DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); + DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get延迟(time_c)); } - DataBus.getInstance().bpa_goodsrecipes.add(Get手动主料()); + DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get主料(0,0,0,0,0,0)); ExecuteTheRecipe.WritePLC("暂停开关", true, null); //刷新工序 RefreshProcedure(); @@ -972,11 +825,11 @@ public class DishTestActivity extends BaseActivity { public void run() { - BPA_GOODSRECIPE data1 = Get位置("高速", "抽料位"); + BPA_GOODSRECIPE data1 = ExecuteTheRecipe.Get位置("抽料位"); //DataBus.getInstance().bpa_goodsrecipes.add(data1); ExecuteTheRecipe.ExecuteOperationSteps(data1.processname, data1.processvalue); - BPA_GOODSRECIPE cipe = GetSelectItemFromValue(name, yl); + BPA_GOODSRECIPE cipe = ExecuteTheRecipe.Get物料(name, yl); ExecuteTheRecipe.ExecuteMaterialIssuance(cipe.processvalue); @@ -985,7 +838,7 @@ public class DishTestActivity extends BaseActivity { public void run() { if (time_c > 0)//如果大于0,那么加一个延迟 { - DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); + DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get延迟(time_c)); } DataBus.getInstance().bpa_goodsrecipes.add(cipe); @@ -998,52 +851,6 @@ public class DishTestActivity extends BaseActivity { }).start(); } - boolean IsChouShui=false; - /** - * 抽水 - */ - public void PumpWater(boolean isselectd) { - if (isselectd) { - - int time = (int) ((SystemClock.elapsedRealtime() - runtime.getBase()) / 1000);//当前点击多少秒 - int time_c = time - ClikTime; - new Thread(new Runnable() { - @Override - public void run() { - runOnUiThread(new Runnable() { - @Override - public void run() { - guoneichoushui.setVisibility(View.VISIBLE); - } - }); - } - }).start(); - new Thread(new Runnable() { - @Override - public void run() { - BPA_GOODSRECIPE data1 = Get位置("高速", "抽料位"); - ExecuteTheRecipe.ExecuteOperationSteps(data1.processname, data1.processvalue); - runOnUiThread(new Runnable() { - @Override - public void run() { - if (time_c > 0)//如果大于0,那么加一个延迟 - { - DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); - } - onRecordStart_CS(); - } - }); - } - }).start(); - } else { - onRecordStop_CS(); - } - ExecuteTheRecipe.WritePLC("炒锅抽水", isselectd, null); - ToastUtils.warning("锅内加水:" + isselectd); - //刷新工序 - RefreshProcedure(); - } - /** * 设置火力 * @@ -1056,12 +863,12 @@ public class DishTestActivity extends BaseActivity { if (time_c > 0)//如果大于0,那么加一个延迟 { - DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); + DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get延迟(time_c)); } String sdstr = Get挡位((int) data); - BPA_GOODSRECIPE data1 = Get加热(sdstr); - DataBus.getInstance().bpa_goodsrecipes.add(data1); +// BPA_GOODSRECIPE data1 = ExecuteTheRecipe.Get加热(sdstr); +// DataBus.getInstance().bpa_goodsrecipes.add(data1); ClikTime = time; ExecuteTheRecipe.Write_PLC_HuoLI((int) data); @@ -1075,9 +882,9 @@ public class DishTestActivity extends BaseActivity { public void AutomaticServing() { int time = (int) ((SystemClock.elapsedRealtime() - runtime.getBase()) / 1000);//当前点击多少秒 int time_c = time - ClikTime; - BPA_GOODSRECIPE data = Get出菜(time_c); + BPA_GOODSRECIPE data = ExecuteTheRecipe.Get出菜(time_c); DataBus.getInstance().bpa_goodsrecipes.add(data); - BPA_GOODSRECIPE data2 = Get清洗(0); + BPA_GOODSRECIPE data2 = ExecuteTheRecipe.Get清洗(0); DataBus.getInstance().bpa_goodsrecipes.add(data2); new Thread(new Runnable() { @Override @@ -1087,209 +894,6 @@ public class DishTestActivity extends BaseActivity { } }).start(); } - - /** - * 获取延迟 - * - * @param time - * @return - */ - public BPA_GOODSRECIPE Get延迟(int time) { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType = 1; - pf.processname = "延迟"; - pf.processms = "延迟(" + time + ")"; - pf.processvalue = "延迟(秒)," + time; - return pf; - } - - /** - * 获取加水 - * - * @param time - * @return - */ - public BPA_GOODSRECIPE Get加水(int time) { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType = 1; - pf.processname = "加水"; - pf.processms = "加水(" + time + ")"; - pf.processvalue = "时长(秒)," + time; - return pf; - } - - /** - * 获取主料 - * - * @param wz - * @return - */ - public BPA_GOODSRECIPE Get主料(int wz) { - String ms = "未知"; - if (wz == 1) { - if (!liaohetext1.isEmpty()) { - ms = liaohetext1; - } - } else if (wz == 2) { - if (!liaohetext2.isEmpty()) { - ms = liaohetext2; - } - } else if (wz == 3) { - if (!liaohetext3.isEmpty()) { - ms = liaohetext3; - } - } else if (wz == 4) { - if (!liaohetext4.isEmpty()) { - ms = liaohetext4; - } - } - - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType = 1; - pf.processname = "主料"; - - pf.processms = "主料(" + ms + "," + wz + "号位,0,直接投出,0)"; - pf.processvalue = "主料名称," + ms + "|主料位置," + wz + "号位|主料重量,0|投料动作,直接投出|烹饪(秒),0"; - return pf; - } - - /** - * 获取手动主料 - * - * @param - * @return - */ - public BPA_GOODSRECIPE Get手动主料() { - String ms = "未知"; - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType = 1; - pf.processname = "主料"; - pf.processms = "主料(" + ms + ",1号位,0,手动投料,0)"; - pf.processvalue = "主料名称," + ms + "|主料位置,1号位|主料重量,0|投料动作,手动投料|烹饪(秒),0"; - return pf; - } - - /** - * 获取位置 - * - * @param sd - * @return - */ - public BPA_GOODSRECIPE Get位置(String sd, String name) { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType = 1; - pf.processname = "位置"; - pf.processms = "位置(" + sd + "," + name + ",0)"; - pf.processvalue = "转动速度," + sd + "|位置动作," + name + "|延迟(秒),0"; - return pf; - } - - /** - * 获取搅拌 - * - * @param sd - * @return - */ - public BPA_GOODSRECIPE Get搅拌(String sd) { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType = 1; - pf.processname = "搅拌"; - pf.processms = "搅拌(" + sd + ",0)"; - pf.processvalue = "搅拌速度," + sd + "|延迟(秒),0"; - return pf; - } - - /** - * 获取加热 - * - * @param sd - * @return - */ - public BPA_GOODSRECIPE Get加热(String sd) { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType = 1; - pf.processname = "加热"; - pf.processms = "加热(" + sd + ",0)"; - pf.processvalue = "加热功率," + sd + "|延迟(秒),0"; - return pf; - } - - /** - * 获取出菜 - * - * @return - */ - public BPA_GOODSRECIPE Get出菜(int k) { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType = 1; - pf.processname = "出菜"; - pf.processms = "出菜(" + k + ")"; - pf.processvalue = "等待(秒)," + k; - return pf; - } - - /** - * 获取清洗 - * - * @return - */ - public BPA_GOODSRECIPE Get清洗(int k) { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType = 1; - pf.processname = "清洗"; - pf.processms = "清洗(" + k + ")"; - pf.processvalue = "等待(秒)," + k; - return pf; - } - - /** - * 获取选中行的变量 - * - * @return - */ - public BPA_GOODSRECIPE GetSelectItemFromValue(String name, String yl) { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - try { - // 延迟,100|延迟,100|延迟,100|延迟,100| - String data = ""; - String desc = ""; - - pf.materialType = 0; - data += name + "," + yl + "|"; - desc += yl + ","; - - pf.processname = "液体料"; - pf.processms = "液体料" + "(" + desc.substring(0, desc.length() - 1) + ")"; - pf.processvalue = data.substring(0, data.length() - 1); - return pf; - } catch (Exception ex) { - return null; - } - } - - /** - * 获取速度 - * - * @return - */ - public String Get速度(int speed) { - if (speed >= 0 && speed < 5) { - return "停止"; - } else if (speed >= 5 && speed < 15) { - return "最低"; - } else if (speed >= 15 && speed < 25) { - return "低速"; - } else if (speed >= 25 && speed < 35) { - return "中速"; - } else if (speed >= 35 && speed < 45) { - return "高速"; - } else if (speed >= 45 && speed < 55) { - return "最高"; - } else { - return "极高"; - } - } - /** * 获取挡位 * diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyMemoryActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyMemoryActivity.java index 2d449600..bf3577bb 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyMemoryActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DiyMemoryActivity.java @@ -157,14 +157,14 @@ public class DiyMemoryActivity extends BaseActivity { if(time_c>0)//如果大于0,那么加一个延迟 { - DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); + DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get延迟(time_c)); } - String sdstr= Get挡位((int) data); - BPA_GOODSRECIPE data1=Get加热(sdstr); - DataBus.getInstance().bpa_goodsrecipes.add(data1); - ClikTime=time; - ExecuteTheRecipe.Write_PLC_HuoLI((int) data); +// String sdstr= Get挡位((int) data); +// BPA_GOODSRECIPE data1=ExecuteTheRecipe.Get加热(sdstr); +// DataBus.getInstance().bpa_goodsrecipes.add(data1); +// ClikTime=time; +// ExecuteTheRecipe.Write_PLC_HuoLI((int) data); } } @@ -222,12 +222,11 @@ public class DiyMemoryActivity extends BaseActivity { { if(time_c>0)//如果大于0,那么加一个延迟 { - DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); + DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get延迟(time_c)); } int sd = (int) nifty_slider2.getValue(); - String sdstr= Get速度(sd); - BPA_GOODSRECIPE data=Get搅拌(sdstr); + BPA_GOODSRECIPE data=ExecuteTheRecipe.Get搅拌(sd); DataBus.getInstance().bpa_goodsrecipes.add(data); ExecuteTheRecipe.WritePLC("搅拌速度", sd, new IWriteCallBack() { @Override @@ -262,18 +261,6 @@ public class DiyMemoryActivity extends BaseActivity { ExecuteTheRecipe.BottomClick("平移-去1号位"); } break; - case R.id.touliao1://主料1 - ClickZL(time,time_c,1); - break; - case R.id.touliao2://主料2 - ClickZL(time,time_c,2); - break; - case R.id.touliao3://主料3 - ClickZL(time,time_c,3); - break; - case R.id.touliao4://主料4 - ClickZL(time,time_c,4); - break; case R.id.ydw://原点位 ClickWZ(time,time_c,"原点位"); break; @@ -298,9 +285,9 @@ public class DiyMemoryActivity extends BaseActivity { case R.id.zidongchucan://自动出餐 if(isRunClick()) { - BPA_GOODSRECIPE data1=Get出菜(time_c); + BPA_GOODSRECIPE data1=ExecuteTheRecipe.Get出菜(time_c); DataBus.getInstance().bpa_goodsrecipes.add(data1); - BPA_GOODSRECIPE data2 = Get清洗(0); + BPA_GOODSRECIPE data2 = ExecuteTheRecipe.Get清洗(0); DataBus.getInstance().bpa_goodsrecipes.add(data2); MakeRecipe(data1); ClikTime=time; @@ -335,49 +322,18 @@ public class DiyMemoryActivity extends BaseActivity { return true; } - public void ClickZL(int time,int time_c,int num) - { -// Object sb = ExecuteTheRecipe.ReadPLC("平移轴在1号位"); -// if (sb != null) { -// if ((boolean) (sb)) { -// -// } else { -// ToastUtils.warning("平移轴未复位!!!"); -// } -// } else { -// ToastUtils.warning("PLC未连接!!!"); -// } - - if(isRunClick()) - { - if(time_c>0)//如果大于0,那么加一个延迟 - { - DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); - } - - //控制去炒菜位 - BPA_GOODSRECIPE data1=Get位置("高速","炒菜位1"); - DataBus.getInstance().bpa_goodsrecipes.add(data1); - - BPA_GOODSRECIPE data=Get主料(num); - DataBus.getInstance().bpa_goodsrecipes.add(data); - MakeRecipe(data);//执行主料 - ClikTime=time; - } - - } public void ClickWZ(int time,int time_c,String name) { if(isRunClick()) { if(time_c>0)//如果大于0,那么加一个延迟 { - DataBus.getInstance().bpa_goodsrecipes.add(Get延迟(time_c)); + DataBus.getInstance().bpa_goodsrecipes.add(ExecuteTheRecipe.Get延迟(time_c)); } // int sd = (int) nifty_slider3.getValue(); // String sdstr= Get速度(sd); - BPA_GOODSRECIPE data=Get位置("高速",name); + BPA_GOODSRECIPE data=ExecuteTheRecipe.Get位置(name); DataBus.getInstance().bpa_goodsrecipes.add(data); MakeRecipe(data); ClikTime=time; @@ -393,23 +349,18 @@ public class DiyMemoryActivity extends BaseActivity { public void run() { if (recipe.materialType == 0)//正常物料 { - BPA_GOODSRECIPE data1=Get位置("高速","抽料位"); - ExecuteTheRecipe.ExecuteOperationSteps(data1.processname,data1.processvalue); - ExecuteTheRecipe.ExecuteMaterialIssuance(recipe.processvalue); } else if (recipe.materialType == 1)//工序模型 { if(recipe.processname.equals("主料")) { - BPA_GOODSRECIPE data1=Get位置("高速","炒菜位1"); - ExecuteTheRecipe.ExecuteOperationSteps(data1.processname,data1.processvalue); ExecuteTheRecipe.ExecuteOperationSteps(recipe.processname,recipe.processvalue); }else { if(recipe.processname.equals("出菜")) { ExecuteTheRecipe.ExecuteOperationSteps(recipe.processname,recipe.processvalue); - BPA_GOODSRECIPE data2 = Get清洗(0); + BPA_GOODSRECIPE data2 = ExecuteTheRecipe.Get清洗(0); ExecuteTheRecipe.ExecuteOperationSteps(data2.processname,data2.processvalue); }else { @@ -466,106 +417,7 @@ public class DiyMemoryActivity extends BaseActivity { } } - /** - * 获取延迟 - * @param time - * @return - */ - public BPA_GOODSRECIPE Get延迟(int time) - { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType=1; - pf.processname="延迟"; - pf.processms="延迟("+time+")"; - pf.processvalue="延迟(秒),"+time; - return pf; - } - /** - * 获取清洗 - * - * @return - */ - public BPA_GOODSRECIPE Get清洗(int k) { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType = 1; - pf.processname = "清洗"; - pf.processms = "清洗(" + k + ")"; - pf.processvalue = "等待(秒)," + k; - return pf; - } - /** - * 获取主料 - * @param wz - * @return - */ - public BPA_GOODSRECIPE Get主料(int wz) - { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType=1; - pf.processname="主料"; - pf.processms="主料(未知,"+wz+"号位,0,直接投出,0)"; - pf.processvalue="主料名称,未知|主料位置,"+wz+"号位|主料重量,0|投料动作,直接投出|烹饪(秒),0"; - return pf; - } - - /** - * 获取位置 - * @param sd - * @return - */ - public BPA_GOODSRECIPE Get位置(String sd,String name) - { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType=1; - pf.processname="位置"; - pf.processms="位置("+sd+","+name+",0)"; - pf.processvalue="转动速度,"+sd+"|位置动作,"+name+"|延迟(秒),0"; - return pf; - } - - /** - * 获取搅拌 - * @param sd - * @return - */ - public BPA_GOODSRECIPE Get搅拌(String sd) - { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType=1; - pf.processname="搅拌"; - pf.processms="搅拌("+sd+",0)"; - pf.processvalue="搅拌速度,"+sd+"|延迟(秒),0"; - return pf; - } - - /** - * 获取加热 - * @param sd - * @return - */ - public BPA_GOODSRECIPE Get加热(String sd) - { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType=1; - pf.processname="加热"; - pf.processms="加热("+sd+",0)"; - pf.processvalue="加热功率,"+sd+"|延迟(秒),0"; - return pf; - } - /** - * 获取出菜 - * @return - */ - public BPA_GOODSRECIPE Get出菜(int k) - { - BPA_GOODSRECIPE pf = new BPA_GOODSRECIPE(); - pf.materialType=1; - pf.processname="出菜"; - pf.processms="出菜("+k+")"; - pf.processvalue="等待(秒),"+k; - return pf; - } /** * 获取速度 diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java index 5a70b500..d26a1b26 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemSystemsetFragment.java @@ -154,7 +154,7 @@ public class SystemSystemsetFragment extends BaseFragment { break; case -100: ConfigName.getInstance().versionSelectionEnum = item.value; - versionselection.setSelection(material_map_vis.get(item.value)); + versionselection.setSelection(material_map_vis.get(item.value)==null?0:material_map_vis.get(item.value)); break; case -99: ConfigName.getInstance().Environment = item.value; diff --git a/app/src/main/res/layout/activity_dishtest.xml b/app/src/main/res/layout/activity_dishtest.xml index 163da8aa..36056e00 100644 --- a/app/src/main/res/layout/activity_dishtest.xml +++ b/app/src/main/res/layout/activity_dishtest.xml @@ -226,103 +226,6 @@ android:layout_marginBottom="180dp" android:orientation="vertical" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/fragment_home_sbkz.xml b/app/src/main/res/layout/fragment_home_sbkz.xml index 21d0fe6a..cdd5f53b 100644 --- a/app/src/main/res/layout/fragment_home_sbkz.xml +++ b/app/src/main/res/layout/fragment_home_sbkz.xml @@ -226,102 +226,6 @@ - - - - - - - - - - - - - - - - - - - - - - - -