From 2c96a0282b938a42be1012c5a49601910987dd3b Mon Sep 17 00:00:00 2001 From: fyf <11621@LAPTOP-04QQU0AO> Date: Sat, 20 Jan 2024 13:05:26 +0800 Subject: [PATCH] =?UTF-8?q?1.=E8=AE=B0=E5=BD=95=E6=97=B6=E9=95=BF=E5=87=8F?= =?UTF-8?q?=E5=8E=BB=E6=89=8B=E5=8A=A8=E7=AD=89=E5=BE=85=E6=97=B6=E9=97=B4?= =?UTF-8?q?=202.=E6=89=8B=E5=8A=A8=E7=AD=89=E5=BE=85=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=9A=82=E5=81=9C=E5=80=92=E8=AE=A1=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/ExecuteTheRecipe.java | 55 +++++++++++++++++-- .../activity/BottomNavigationNewActivity.java | 22 +++++++- .../modules/home/fragment/Home1Fragment.java | 47 ++++++++++++++-- .../home/fragment/mode/imagebuttom.java | 13 +++++ 4 files changed, 126 insertions(+), 11 deletions(-) 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 3e24b99c..3ac2e09a 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java +++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java @@ -60,6 +60,9 @@ public class ExecuteTheRecipe { //public static int whileTime = 40; public static int whileTime = 100; + //手动操作耗时时长 + public static int HandTime=0; + /** * 监听变量值 */ @@ -110,6 +113,11 @@ public class ExecuteTheRecipe { * 通知版本号更新显示 */ public static IRun NotifyVersionNumUpdates = null; + + /** + * 通知手动暂停 + */ + public static IRunT NoticeHandSuspension = null; //endregion //region 强制结束 @@ -541,6 +549,8 @@ public class ExecuteTheRecipe { ExecuteTheRecipe.WritePLC("暂停开关", true, null); } ModbusTcpServer.get().WriteBool("M52.1", (boolean) true, null); + long startTime = System.currentTimeMillis(); //起始时间 + if(NoticeHandSuspension!=null){NoticeHandSuspension.Run(true);} final boolean[] IsComplete = {false}; Activity activity = findActivity(context); @@ -573,6 +583,11 @@ public class ExecuteTheRecipe { ExecuteTheRecipe.WritePLC("暂停开关", false, null); } ModbusTcpServer.get().WriteBool("M52.1", (boolean) false, null); + long endTime = System.currentTimeMillis(); //结束时间 + int time = (int) ((endTime - startTime) / 1000); + HandTime=HandTime+time; + if(NoticeHandSuspension!=null){NoticeHandSuspension.Run(false);} + ExecuteTheRecipe.showlog("手动已确认投入主料:" + name + "-继续流程"); } else { @@ -948,7 +963,14 @@ public class ExecuteTheRecipe { ExecuteTheRecipe.showlog("工序:手动投料," + name + "," + zl); String title = "手动投料-温馨提示!"; String message = "客官请投入主料,[" + name + "]重量" + zl + "g,投入后点击[确定]继续流程!"; - ExecuteTheRecipe.WritePLC("暂停开关", true, null); + + if (ConfigName.getInstance().WhetherManualFeedingSuspended.contains("是")) { + ExecuteTheRecipe.WritePLC("暂停开关", true, null); + } + ModbusTcpServer.get().WriteBool("M52.1", (boolean) true, null); + long startTime = System.currentTimeMillis(); //起始时间 + if(NoticeHandSuspension!=null){NoticeHandSuspension.Run(true);} + final boolean[] IsComplete = {false}; Activity activity = findActivity(context); @@ -974,7 +996,17 @@ public class ExecuteTheRecipe { while (!IsComplete[0]) { Thread.sleep(100);//10 *6 } - ExecuteTheRecipe.WritePLC("暂停开关", false, null); + + if (ConfigName.getInstance().WhetherManualFeedingSuspended.contains("是")) { + ExecuteTheRecipe.WritePLC("暂停开关", false, null); + } + ModbusTcpServer.get().WriteBool("M52.1", (boolean) false, null); + long endTime = System.currentTimeMillis(); //结束时间 + int time = (int) ((endTime - startTime) / 1000); + HandTime=HandTime+time; + if(NoticeHandSuspension!=null){NoticeHandSuspension.Run(false);} + + ExecuteTheRecipe.showlog("确定完成,继续制作!"); } else { //自动投料 @@ -1075,7 +1107,12 @@ public class ExecuteTheRecipe { ExecuteTheRecipe.showlog("工序:手动投料," + name + "," + zl); String title = "手动投料-温馨提示!"; String message = "客官请投入主料,[" + name + "]重量" + zl + "g,投入后点击[确定]继续流程!"; - ExecuteTheRecipe.WritePLC("暂停开关", true, null); + if (ConfigName.getInstance().WhetherManualFeedingSuspended.contains("是")) { + ExecuteTheRecipe.WritePLC("暂停开关", true, null); + } + ModbusTcpServer.get().WriteBool("M52.1", (boolean) true, null); + long startTime = System.currentTimeMillis(); //起始时间 + if(NoticeHandSuspension!=null){NoticeHandSuspension.Run(true);} final boolean[] IsComplete = {false}; Activity activity = findActivity(context); @@ -1103,7 +1140,16 @@ public class ExecuteTheRecipe { while (!IsComplete[0]) { Thread.sleep(100);//10 *6 } - ExecuteTheRecipe.WritePLC("暂停开关", false, null); + + if (ConfigName.getInstance().WhetherManualFeedingSuspended.contains("是")) { + ExecuteTheRecipe.WritePLC("暂停开关", false, null); + } + ModbusTcpServer.get().WriteBool("M52.1", (boolean) false, null); + long endTime = System.currentTimeMillis(); //结束时间 + int time = (int) ((endTime - startTime) / 1000); + HandTime=HandTime+time; + if(NoticeHandSuspension!=null){NoticeHandSuspension.Run(false);} + ExecuteTheRecipe.showlog("确定完成,继续制作!"); } else { //自动投料 @@ -1429,6 +1475,7 @@ public class ExecuteTheRecipe { ExecuteTheRecipe.WritePLC("料仓2校准开关", false, null);//默认校准时间5秒 ExecuteTheRecipe.WritePLC("料仓3校准开关", false, null);//默认校准时间5秒 + ModbusTcpServer.get().WriteBool("M52.1", (boolean) false, null); //读取版本号 ModbusTcpServer.get().ReadInt("VD1100", 1, val -> { PlcVersion= String.valueOf(val[0]); diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java index c779c5eb..2e102ee1 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationNewActivity.java @@ -22,6 +22,7 @@ import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.helper.CountDownTimerExt; +import com.bonait.bnframework.common.helper.I.IRunT; import com.bonait.bnframework.common.helper.I.IThread; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.helper.MessageLog; @@ -368,6 +369,7 @@ public class BottomNavigationNewActivity extends BaseActivity { ExecuteTheRecipe.showlog("开始烹饪菜谱【"+goods.name+"】"); ModbusTcpServer.get().WriteBool("M52.0", (boolean) true, null); + ExecuteTheRecipe.HandTime=0;//默认将手动操作时间复位 try { //获取工艺 @@ -411,8 +413,10 @@ public class BottomNavigationNewActivity extends BaseActivity { ExecuteTheRecipe.showlog("结束烹饪菜谱【"+goods.name+"】,关闭搅拌、关闭加热,"+String.format("方法使用时间 %d s", time)); if (!ExecuteTheRecipe.IsForcedEnd) { - QueryDB.UpdateGoodsMakeTime(goods.id, time); + int ztime=time-ExecuteTheRecipe.HandTime; + QueryDB.UpdateGoodsMakeTime(goods.id, ztime>0?ztime:time); } + ExecuteTheRecipe.HandTime=0;//默认将手动操作时间复位 ExecuteTheRecipe.all_list = new ArrayList<>(); runOnUiThread(new Runnable() { @@ -549,6 +553,22 @@ public class BottomNavigationNewActivity extends BaseActivity { } }); makeThreadDC.start(); + + ExecuteTheRecipe.NoticeHandSuspension=new IRunT() { + @Override + public void Run(Object o) { + if(IsRunThread) + { + if((boolean) o) + { + onRecordPause(); + }else + { + onRecordPauseStart(); + } + } + } + }; } /** diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home1Fragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home1Fragment.java index b64b7eda..8cfeaa13 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home1Fragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/Home1Fragment.java @@ -41,6 +41,8 @@ import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.db.res.StatusMode; import com.bonait.bnframework.common.helper.ByteHelper; +import com.bonait.bnframework.common.helper.CountDownTimerExt; +import com.bonait.bnframework.common.helper.I.IRunT; import com.bonait.bnframework.common.helper.I.IThread; import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.I.MyClickListener; @@ -575,6 +577,7 @@ public class Home1Fragment extends BaseFragment { ExecuteTheRecipe.showlog("--------------------------------------"); ExecuteTheRecipe.showlog("开始烹饪菜谱【"+good.name+"】"); ModbusTcpServer.get().WriteBool("M52.0", (boolean) true, null); + ExecuteTheRecipe.HandTime=0;//默认将手动操作时间复位 try { //获取工艺 @@ -608,8 +611,10 @@ public class Home1Fragment extends BaseFragment { ExecuteTheRecipe.showlog("结束烹饪菜谱【"+good.name+"】,关闭搅拌、关闭加热,"+String.format("方法使用时间 %d s", time)); if (!ExecuteTheRecipe.IsForcedEnd) { - QueryDB.UpdateGoodsMakeTime(good.id, time); + int ztime=time-ExecuteTheRecipe.HandTime; + QueryDB.UpdateGoodsMakeTime(good.id, ztime>0?ztime:time); } + ExecuteTheRecipe.HandTime=0;//默认将手动操作时间复位 ExecuteTheRecipe.all_list = new ArrayList<>(); @@ -764,6 +769,22 @@ public class Home1Fragment extends BaseFragment { } }); makeThreadUI.start(); + + ExecuteTheRecipe.NoticeHandSuspension=new IRunT() { + @Override + public void Run(Object o) { + if(IsRunThread) + { + if((boolean) o) + { + onRecordPause(); + }else + { + onRecordPauseStart(); + } + } + } + }; } /** @@ -887,7 +908,7 @@ public class Home1Fragment extends BaseFragment { } } - private CountDownTimer countDownTimer = null;//计时器 + private CountDownTimerExt countDownTimer = null;//计时器 /** * 计时器 @@ -899,15 +920,15 @@ public class Home1Fragment extends BaseFragment { public void TimerCount(int alltime, boolean status) { if (status) { if (countDownTimer == null) { - countDownTimer = new CountDownTimer(alltime * 1000, 1000) { + countDownTimer = new CountDownTimerExt(alltime * 1000, 1000) { @Override - public void onTick(long millisUntilFinished) { + public void onTimerTick(long millisUntilFinished) { int overtime = (int) ((millisUntilFinished) / 1000);//剩余时间 SetProcesssUI(alltime, alltime - overtime); } @Override - public void onFinish() { + public void onTimerFinish() { SetProcesssUI(alltime, alltime);//进度条100% } }; @@ -915,12 +936,26 @@ public class Home1Fragment extends BaseFragment { countDownTimer.start(); } else { if (countDownTimer != null) { - countDownTimer.cancel(); + countDownTimer.stop(); countDownTimer = null; } } } + /** + * 暂停 + */ + public void onRecordPause() { + countDownTimer.pause(); + } + + /** + * 继续 + */ + public void onRecordPauseStart() { + countDownTimer.resume(); + } + /** * 点击事件 * diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/imagebuttom.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/imagebuttom.java index 8e67886a..396d8b05 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/imagebuttom.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/imagebuttom.java @@ -14,8 +14,10 @@ import androidx.annotation.Nullable; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; +import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.utils.AlertDialogUtils; +import com.bonait.bnframework.common.utils.ToastUtils; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; @@ -96,6 +98,17 @@ public class imagebuttom extends LinearLayout { }else { + if (!ConfigName.getInstance().PlcIsConnect) { + ToastUtils.warning("PLC未准备就绪!!!"); + return; + } + + Object chushiover = ExecuteTheRecipe.getListingValue("初始化完成"); + if (chushiover == null || !(boolean) chushiover) { + ToastUtils.warning("设备未初始化,请先手动初始化设备!!!"); + return; + } + String title = "开始操作提示!"; String message = "请问客官确定要开始制作吗,小菠萝好开心呀,马上就有好吃的耶?"; AlertDialogUtils.showDialog(getContext(), title, message, new QMUIDialogAction.ActionListener() {