From 26be79d92583cbadbbeb03cf0da0f7395cfc345a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Mon, 29 Jan 2024 12:39:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E7=82=92=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bnframework/business/DeviceData.java | 264 ++++++ .../business/ExecuteTheRecipe.java | 514 ++++++++-- .../common/constant/ConfigName.java | 9 +- .../bnframework/common/helper/Convert.java | 50 + .../bnframework/common/helper/Executor.java | 42 + .../common/helper/I/IDialogAction.java | 8 + .../common/helper/NotifyPropVar.java | 29 + .../common/helper/Result/IResult.java | 45 + .../common/helper/Result/OperateResult.java | 77 ++ .../common/helper/Result/OperateResultT.java | 74 ++ .../common/helper/Result/ResultCode.java | 38 + .../bnframework/common/helper/Stopwatch.java | 37 + .../common/modbus/s7/CommHelper.java | 89 +- .../common/modbus/s7/SiemensHelper.java | 177 +++- .../common/utils/AlertDialogUtils.java | 35 + .../BottomNavigationMainActivity.java | 3 +- .../home/fragment/MakeGoodFragment.java | 877 +++++++++++++----- .../fragment/mode/fragment_plc_control.java | 17 +- app/src/main/res/drawable/input_bj.xml | 6 +- .../layout/activity_device_information.xml | 2 + app/src/main/res/layout/activity_diy.xml | 39 +- app/src/main/res/layout/activity_log.xml | 2 + .../main/res/layout/activity_order_list.xml | 2 + .../res/layout/activity_system_parameter.xml | 2 + .../main/res/layout/fragment_make_good.xml | 474 ++++++---- 25 files changed, 2361 insertions(+), 551 deletions(-) create mode 100644 app/src/main/java/com/bonait/bnframework/business/DeviceData.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/Convert.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/Executor.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/I/IDialogAction.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/NotifyPropVar.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/Result/IResult.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/Result/OperateResult.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/Result/OperateResultT.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/Result/ResultCode.java create mode 100644 app/src/main/java/com/bonait/bnframework/common/helper/Stopwatch.java diff --git a/app/src/main/java/com/bonait/bnframework/business/DeviceData.java b/app/src/main/java/com/bonait/bnframework/business/DeviceData.java new file mode 100644 index 00000000..0ff35816 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/business/DeviceData.java @@ -0,0 +1,264 @@ +package com.bonait.bnframework.business; + +import com.bonait.bnframework.common.helper.NotifyPropVar; + +public class DeviceData { + /** + * 搅拌上限 + */ + public boolean MixingUpperLimit; + + /** + * 搅拌下限 + */ + public boolean MixingLowerLimit; + + /** + * 锅后限位 + */ + public boolean PostPotLimit; + + /** + * 摆臂上限 + */ + public boolean SwingArmUpperLimit; + + /** + * 摆臂下限 + */ + public boolean SwingArmLowerLimit; + + /** + * 点火正常 + */ + public boolean IgnitionNormal; + + /** + * 点火异常 + */ + public boolean IgnitionError; + + /** + * 设备急停 + */ + public boolean EStop; + + /** + * 炒锅当前重量 + */ + public float CurrentWeight; + + /** + * 炒锅当前温度 + */ + public float CurrentTemperature; + + //region 状态属性 +// /** +// * 系统启停状态 +// */ +// public boolean SystemStartStopStatus; +// +// /** +// * 超温停气状态 +// */ +// public boolean OverTemperatureShutdown; +// +// /** +// * 点火模式:true:手动,false:自动 +// */ +// public boolean IgnideMode; +// +// /** +// * 小火比例值 +// */ +// public float SmallFireProportion; +// +// /** +// * 中火比例值 +// */ +// public float MediumFireProportion ; +// +// /** +// * 大火比例值 +// */ +// public float HighFireProportion ; +// +// /** +// * 强火比例值 +// */ +// public float StrongFireProportion ; +// +// /** +// * 小火控制状态 +// */ +// public boolean SmallFireStatus; +// +// /** +// * 中火控制状态 +// */ +// public boolean MediumFireStatus ; +// +// /** +// * 大火控制状态 +// */ +// public boolean HighFireStatus ; +// +// /** +// * 强火控制状态 +// */ +// public boolean StrongFireStatus ; +// +// /** +// * 点火控制状态 +// */ +// public boolean IgnitionStatus; +// +// /** +// * 温度修正值 +// */ +// public float TemperatureCorrectionValue; +// +// /** +// * 温度上限值 +// */ +// public float UpperTemperatureLimit; +// +// /** +// * 搅拌控制状态 +// */ +// public boolean StirControlStatus; + //endregion + + + + //region 通知属性 + /** + * 系统启停状态通知对象 + */ + public NotifyPropVar SystemStartStopStatusNotify=new NotifyPropVar<>(false); + + /** + * 超温停气状态通知对象 + */ + public NotifyPropVar OverTemperatureShutdownNotify=new NotifyPropVar<>(false); + + /** + * 点火模式状态通知对象 + */ + public NotifyPropVar IgnideModeNotify =new NotifyPropVar<>(false); + + /** + * 小火比例值状态通知对象 + */ + public NotifyPropVar SmallFireProportionNotify=new NotifyPropVar<>(0f); + + /** + * 中火比例值状态通知对象 + */ + public NotifyPropVar MediumFireProportionNotify =new NotifyPropVar<>(0f); + + /** + * 大火比例值状态通知对象 + */ + public NotifyPropVar HighFireProportionNotify =new NotifyPropVar<>(0f); + + /** + * 强火比例值状态通知对象 + */ + public NotifyPropVar StrongFireProportionNotify =new NotifyPropVar<>(0f); + + /** + * 小火控制状态通知对象 + */ + public NotifyPropVar SmallFireStatusNotify =new NotifyPropVar<>(false); + + /** + * 中火控制状态通知对象 + */ + public NotifyPropVar MediumFireStatusNotify =new NotifyPropVar<>(false); + + /** + * 大火控制状态通知对象 + */ + public NotifyPropVar HighFireStatusNotify =new NotifyPropVar<>(false) ; + + /** + * 强火控制状态通知对象 + */ + public NotifyPropVar StrongFireStatusNotify =new NotifyPropVar<>(false) ; + + /** + * 点火控制状态态通知对象 + */ + public NotifyPropVar IgnitionStatusNotify =new NotifyPropVar<>(false); + + /** + * 温度修正值态通知对象 + */ + public NotifyPropVar TemperatureCorrectionValueNotify =new NotifyPropVar<>(0f); + + /** + * 温度上限值态通知对象 + */ + public NotifyPropVar UpperTemperatureLimitNotify =new NotifyPropVar<>(0f); + + /** + * 搅拌控制状态通知 + */ + public NotifyPropVar StirControlStatusNotify =new NotifyPropVar<>(false); + + /** + * 抽油启停状态通知 + */ + public NotifyPropVar OilPumpingStatusNotify =new NotifyPropVar<>(false); + + /** + * 备用气缸启停状态通知 + */ + public NotifyPropVar StandbyCylinderStatusNotify =new NotifyPropVar<>(false); + + /** + * 当前设定重量值改变通知 + */ + public NotifyPropVar SetWeightNotify =new NotifyPropVar<>(0f); + + /** + * 提前量设定值改变通知 + */ + public NotifyPropVar LeadNotify =new NotifyPropVar<>(0f); + + /** + * 急停故障 + */ + public NotifyPropVar EstopFaultNotify=new NotifyPropVar<>(false); + + /** + * 油泵故障 + */ + public NotifyPropVar OilPumpFault=new NotifyPropVar<>(false); + + /** + * 搅拌故障 + */ + public NotifyPropVar MixingFailure=new NotifyPropVar<>(false); + + /** + * 点火故障 + */ + public NotifyPropVar IgnitionMalfunction=new NotifyPropVar<>(false); + + /** + * 高温报警 + */ + public NotifyPropVar HighTemperatureAlarm=new NotifyPropVar<>(false); + + /** + * 备用故障 + */ + public NotifyPropVar StandbyFailure=new NotifyPropVar<>(false); + //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 6b4d72a7..2fbdaf23 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java +++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java @@ -3,8 +3,6 @@ package com.bonait.bnframework.business; import android.app.Activity; import android.content.Context; import android.content.ContextWrapper; -import android.os.Handler; -import android.os.Looper; import android.util.Log; import androidx.annotation.NonNull; @@ -14,13 +12,17 @@ import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; import com.bonait.bnframework.common.db.mode.BPA_SILOS; -import com.bonait.bnframework.common.helper.I.IRun; +import com.bonait.bnframework.common.helper.Convert; +import com.bonait.bnframework.common.helper.Executor; +import com.bonait.bnframework.common.helper.I.IDialogAction; 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.MessageLog; +import com.bonait.bnframework.common.helper.NotifyPropVar; +import com.bonait.bnframework.common.helper.Result.OperateResultT; import com.bonait.bnframework.common.helper.ThreadManager; import com.bonait.bnframework.common.modbus.s7.CommHelper; -import com.bonait.bnframework.common.modbus.s7.SiemensHelper; +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; @@ -55,7 +57,8 @@ public class ExecuteTheRecipe { /** * 是否启动 */ - public static boolean IsStart = false; + public static NotifyPropVar IsStart = new NotifyPropVar<>(false); + /** * 通知手动暂停 */ @@ -64,6 +67,9 @@ public class ExecuteTheRecipe { * 手动操作耗时时长 */ public static int HandTime = 0; + + public static Context mainContext; + public static Activity mainActivity; //endregion //region 强制结束 @@ -73,6 +79,7 @@ public class ExecuteTheRecipe { */ public static void SetForcedEnd() { ToastUtils.info("客官,小菠萝正在强制结束当前炒制菜品,请耐心等候!!!"); + showlog("强制结束任务"); IsForcedEnd = true; } @@ -86,6 +93,119 @@ public class ExecuteTheRecipe { //region 执行配方 + /** + * 设备状态信号 + */ + public static DeviceData getDeviceData=new DeviceData(); + + public static void DeviceMonitor(){ + ThreadManager.Get().StartLong("设备数据监听", true, new IThread() { + @Override + public void Run() throws InterruptedException { + + Convert.TryToBoolean(ReadPLC("监控_搅拌上限")).OnSource(s->{ getDeviceData.MixingUpperLimit=s.Content;}); + Convert.TryToBoolean(ReadPLC("监控_搅拌下限")).OnSource(s->{ getDeviceData.MixingLowerLimit=s.Content;}); + Convert.TryToBoolean(ReadPLC("监控_锅后限位")).OnSource(s->{ getDeviceData.PostPotLimit=s.Content;}); + Convert.TryToBoolean(ReadPLC("监控_点火正常")).OnSource(s->{ getDeviceData.IgnitionNormal=s.Content;}); + Convert.TryToBoolean(ReadPLC("监控_点火异常")).OnSource(s->{ getDeviceData.IgnitionError=s.Content;}); + Convert.TryToBoolean(ReadPLC("监控_急停按钮")).OnSource(s->{ getDeviceData.EStop=s.Content;}); + Convert.TryToFloat(ReadPLC("炒锅当前重量")).OnSource(s->{ getDeviceData.CurrentWeight=s.Content;}); + Convert.TryToFloat(ReadPLC("炒锅当前温度")).OnSource(s->{ getDeviceData.CurrentTemperature=s.Content;}); + + Convert.TryToBoolean(ReadPLC("系统启停开关")).OnSource(s->{getDeviceData.SystemStartStopStatusNotify.setValue( s.Content);}); + Convert.TryToBoolean(ReadPLC("超温停气开关")).OnSource(s->{getDeviceData.OverTemperatureShutdownNotify.setValue( s.Content);}); + Convert.TryToBoolean(ReadPLC("点火手自动切换开关")).OnSource(s->{getDeviceData.IgnideModeNotify.setValue( s.Content);}); + Convert.TryToFloat(ReadPLC("小火比例阀开度")).OnSource(s->{getDeviceData.SmallFireProportionNotify.setValue( s.Content);}); + Convert.TryToFloat(ReadPLC("中火比例阀开度")).OnSource(s->{getDeviceData.MediumFireProportionNotify.setValue( s.Content);}); + Convert.TryToFloat(ReadPLC("大火比例阀开度")).OnSource(s->{getDeviceData.HighFireProportionNotify.setValue( s.Content);}); + Convert.TryToFloat(ReadPLC("强火比例阀开度")).OnSource(s->{getDeviceData.StrongFireProportionNotify.setValue( s.Content);}); + Convert.TryToBoolean(ReadPLC("小火开关(一圈)")).OnSource(s->{getDeviceData.SmallFireStatusNotify.setValue( s.Content);}); + Convert.TryToBoolean(ReadPLC("中火开关(二圈)")).OnSource(s->{getDeviceData.MediumFireStatusNotify.setValue( s.Content);}); + Convert.TryToBoolean(ReadPLC("大火开关(三圈)")).OnSource(s->{getDeviceData.HighFireStatusNotify.setValue( s.Content);}); + Convert.TryToBoolean(ReadPLC("强火开关(四圈)")).OnSource(s->{getDeviceData.StrongFireStatusNotify.setValue( s.Content);}); + Convert.TryToBoolean(ReadPLC("点火启动开关")).OnSource(s->{getDeviceData.IgnitionStatusNotify.setValue( s.Content);}); + Convert.TryToFloat(ReadPLC("炒锅温度修正")).OnSource(s->{getDeviceData.TemperatureCorrectionValueNotify.setValue( s.Content);}); + Convert.TryToFloat(ReadPLC("炒锅温度上限设置")).OnSource(s->{getDeviceData.UpperTemperatureLimitNotify.setValue( s.Content);}); + Convert.TryToBoolean(ReadPLC("搅拌启动开关")).OnSource(s->{getDeviceData.StirControlStatusNotify.setValue( s.Content);}); + Convert.TryToBoolean(ReadPLC("料仓1出料")).OnSource(s->{getDeviceData.OilPumpingStatusNotify.setValue( s.Content);}); + Convert.TryToBoolean(ReadPLC("料仓2出料")).OnSource(s->{getDeviceData.StandbyCylinderStatusNotify.setValue( s.Content);}); + Convert.TryToFloat(ReadPLC("设定重量")).OnSource(s->{getDeviceData.SetWeightNotify.setValue( s.Content);}); + Convert.TryToFloat(ReadPLC("设定提前量")).OnSource(s->{getDeviceData.LeadNotify.setValue( s.Content);}); + Convert.TryToBoolean(ReadPLC("急停按下")).OnSource(s->{getDeviceData.EstopFaultNotify.setValue(s.Content);}); + Convert.TryToBoolean(ReadPLC("油泵故障")).OnSource(s->{getDeviceData.OilPumpFault.setValue(s.Content);}); + Convert.TryToBoolean(ReadPLC("搅拌故障")).OnSource(s->{getDeviceData.MixingFailure.setValue(s.Content);}); + Convert.TryToBoolean(ReadPLC("点火异常")).OnSource(s->{getDeviceData.IgnitionMalfunction.setValue(s.Content);}); + Convert.TryToBoolean(ReadPLC("高温报警")).OnSource(s->{getDeviceData.HighTemperatureAlarm.setValue(s.Content);}); + Convert.TryToBoolean(ReadPLC("备用故障1")).OnSource(s->{getDeviceData.StandbyFailure.setValue(s.Content);}); + +// getDeviceData.MixingUpperLimit=Boolean.parseBoolean(ReadPLC("监控_搅拌上限").toString()); +// getDeviceData.MixingLowerLimit=Boolean.parseBoolean(ReadPLC("监控_搅拌下限").toString()); +// getDeviceData.PostPotLimit=Boolean.parseBoolean(ReadPLC("监控_锅后限位").toString()); +// getDeviceData.IgnitionNormal=Boolean.parseBoolean(ReadPLC("监控_点火正常").toString()); +// getDeviceData.IgnitionError=Boolean.parseBoolean(ReadPLC("监控_点火异常").toString()); +// getDeviceData.EStop= Boolean.parseBoolean(ReadPLC("监控_急停按钮").toString()); +// getDeviceData.CurrentWeight= Float.parseFloat(ReadPLC("炒锅当前重量").toString()); +// getDeviceData.CurrentTemperature= Float.parseFloat(ReadPLC("炒锅当前温度").toString()); + +// getDeviceData.SystemStartStopStatus=Boolean.parseBoolean(ReadPLC("系统启停开关").toString()); +// getDeviceData.SystemStartStopStatusNotify.setValue( getDeviceData.SystemStartStopStatus); + +// getDeviceData.OverTemperatureShutdown=Boolean.parseBoolean(ReadPLC("超温停气开关").toString()); +// getDeviceData.OverTemperatureShutdownNotify.setValue(getDeviceData.OverTemperatureShutdown); + +// getDeviceData.IgnideMode =Boolean.parseBoolean(ReadPLC("点火手自动切换开关").toString()); +// getDeviceData.IgnideModeNotify.setValue( getDeviceData.IgnideMode); + +// getDeviceData.SmallFireProportion =Float.parseFloat(ReadPLC("小火比例阀开度").toString()); +// getDeviceData.SmallFireProportionNotify.setValue( getDeviceData.SmallFireProportion); + +// getDeviceData.MediumFireProportion =Float.parseFloat(ReadPLC("中火比例阀开度").toString()); +// getDeviceData.MediumFireProportionNotify.setValue( getDeviceData.MediumFireProportion); + +// getDeviceData.HighFireProportion =Float.parseFloat(ReadPLC("大火比例阀开度").toString()); +// getDeviceData.HighFireProportionNotify.setValue( getDeviceData.HighFireProportion); + +// getDeviceData.StrongFireProportion =Float.parseFloat(ReadPLC("强火比例阀开度").toString()); +// getDeviceData.StrongFireProportionNotify.setValue( getDeviceData.StrongFireProportion); + +// getDeviceData.SmallFireStatus =Boolean.parseBoolean(ReadPLC("小火开关(一圈)").toString()); +// getDeviceData.SmallFireStatusNotify.setValue( getDeviceData.SmallFireStatus); +// +// getDeviceData.MediumFireStatus =Boolean.parseBoolean(ReadPLC("中火开关(二圈)").toString()); +// getDeviceData.MediumFireStatusNotify.setValue( getDeviceData.MediumFireStatus); +// +// getDeviceData.HighFireStatus =Boolean.parseBoolean(ReadPLC("大火开关(三圈)").toString()); +// getDeviceData.HighFireStatusNotify.setValue( getDeviceData.HighFireStatus); +// +// getDeviceData.StrongFireStatus =Boolean.parseBoolean(ReadPLC("强火开关(四圈)").toString()); +// getDeviceData.StrongFireStatusNotify.setValue( getDeviceData.StrongFireStatus); +// +// getDeviceData.IgnitionStatus =Boolean.parseBoolean(ReadPLC("点火启动开关").toString()); +// getDeviceData.IgnitionStatusNotify.setValue( getDeviceData.IgnitionStatus); +// +// getDeviceData.TemperatureCorrectionValue =Float.parseFloat(ReadPLC("炒锅温度修正").toString()); +// getDeviceData.TemperatureCorrectionValueNotify.setValue( getDeviceData.TemperatureCorrectionValue); +// +// getDeviceData.UpperTemperatureLimit =Float.parseFloat(ReadPLC("炒锅温度上限设置").toString()); +// getDeviceData.UpperTemperatureLimitNotify.setValue( getDeviceData.UpperTemperatureLimit); +// +// getDeviceData.StirControlStatus =Boolean.parseBoolean(ReadPLC("搅拌启动开关").toString()); +// getDeviceData.StirControlStatusNotify.setValue( getDeviceData.StirControlStatus); + + Thread.sleep(10); + } + + @Override + public void RunComplete() throws InterruptedException { + + } + }); + } + + + + + /** * 执行配方 * @@ -97,7 +217,7 @@ public class ExecuteTheRecipe { try { //1.解析 if (IsForcedEnd) { - ExecuteTheRecipe.showlog("客官,小菠萝正在强制结束当前炒制菜品,请耐心等候!!!"); + ExecuteTheRecipe.showlog("正在强制结束中,请耐心等待"); return false; } ExecuteTheRecipe.showlog("开始执行:" + recipe.sort + "、" + recipe.processms); @@ -111,7 +231,8 @@ public class ExecuteTheRecipe { ExecuteOperationSteps(recipe.processname, recipe.processvalue); } } catch (Exception ex) { - ToastUtils.error("异常信息:" + ex.getMessage()); +// ToastUtils.error("异常信息:" + ex.getMessage()); + MessageLog.ShowError(ex.toString()); status = false; } finally { return status; @@ -235,10 +356,10 @@ public class ExecuteTheRecipe { try { ExecuteTheRecipe.showlog("准备写入PLC仓号需求:" + silos.num + "," + val); String name = "料仓" + silos.num + "出料"; - WritePLC(name, false); //复位料仓1号 + Write(name, false); //复位料仓1号 - WritePLC("设定重量", val); - WritePLC("设定提前量", 20); + Write("设定重量", val); + Write("设定提前量", 20); ExecuteTheRecipe.showlog("需求值写入成功!"); //減去料仓数量 @@ -246,7 +367,7 @@ public class ExecuteTheRecipe { QueryDB.UpdateYL(silos.id, otherG >= 0 ? otherG : 0); //开始出料 - WritePLC(name, true); + Write(name, true); //等待出料完成,false信号 ThreadWhileMaterialOver(name); @@ -340,18 +461,49 @@ public class ExecuteTheRecipe { } } - WritePLC("搅拌速度", seep); + Write("搅拌速度", seep); if (status) { - BottomClick("搅拌启动开关"); + BottomClickAsync("搅拌启动开关"); } else { - BottomClick("搅拌停止开关"); + BottomClickAsync("搅拌停止开关"); } } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); } } + /** + * 加热流程状态,0:无,1:确认,2:取消 + */ + static int HeatStatus=0; + + static void Delay(long millis){ + try{ + Thread.sleep(millis); + }catch(InterruptedException e){ + + } + } + + static boolean WaitDialog(IDialogAction action){ + while(HeatStatus<=0&&!IsForcedEnd){Delay(100);} + if(HeatStatus==2)IsForcedEnd=true; + if(IsForcedEnd) return false; + if(action!=null) action.ExitDialog(HeatStatus==1); + HeatStatus=0; + return false; + } + + public static void ForcedEndTask(){ + Write("点火启动开关", false);//启动点火 + Write("小火开关(一圈)", false); + Write("中火开关(二圈)", false); + Write("大火开关(三圈)", false); + Write("强火开关(四圈)", false); + BottomClick("搅拌停止开关"); + } + /** * 写PLC 设置加热功率 * @@ -359,6 +511,7 @@ public class ExecuteTheRecipe { */ private static void Write_PLC_Heating(HashMap data) { try { + boolean status = false; int val1 = 0; int val2 = 0; int val3 = 0; @@ -375,13 +528,109 @@ public class ExecuteTheRecipe { val3 = Integer.parseInt(value); } else if (key.contains("四环功率")) { val4 = Integer.parseInt(value); + } else if (key.contains("火力状态")) { + status = value.contains("启动") ? true : false; } } - WritePLC("小火开关(一圈)", val1); - WritePLC("中火开关(二圈)", val2); - WritePLC("大火开关(三圈)", val3); - WritePLC("强火开关(四圈)", val4); + if(status){ + MessageLog.ShowInfo("开火中...."); + + //确认点火提示 + mainActivity.runOnUiThread(()->{ + AlertDialogUtils.showDialog(mainContext, "提示", "是否开始点火?",(s)->{ + HeatStatus=s?1:2; + }); + }); + + //等待弹框关闭 + WaitDialog((s)->{ + if(s){ + MessageLog.ShowInfo("确认开始点火"); + Write("点火手自动切换开关", false);//设置自动点火模式 + Write("点火启动开关", true);//启动点火 + } + }); + + while(!IsForcedEnd){ + if(getDeviceData.IgnitionError){ + MessageLog.ShowInfo("点火失败,请求重试"); +// mainActivity.runOnUiThread(new Runnable() { +// @Override +// public void run() { +// AlertDialogUtils.showDialog(mainContext, "提示", "点火失败,是否复位后重试?", new IDialogAction() { +// @Override +// public void Confirm() { +// MessageLog.ShowInfo("确认重新点火"); +// WriteAsync("点火手自动切换开关", false);//设置自动点火模式 +// WriteAsync("点火启动开关", false);//关闭点火 +// BottomClick("点火复位开关");//复位点火开关 +// WriteAsync("点火启动开关", true);//重新点火 +// } +// @Override +// public void Cancel() { +// IsForcedEnd=true; +// MessageLog.ShowInfo("点火失败,取消继续点火,强制结束任务"); +// } +// +// @Override +// public void ExitDialog(boolean status) { +// +// } +// }); +// } +// }); + + //点火失败提示 + mainActivity.runOnUiThread(()->{ + AlertDialogUtils.showDialog(mainContext, "提示", "点火失败,是否复位后重试?",(s)->{ + HeatStatus=s?1:2; + }); + }); + + //等待弹框被关闭 + WaitDialog((s)->{ + if(s){ + MessageLog.ShowInfo("确认重新点火"); + Write("点火手自动切换开关", false);//设置自动点火模式 + Write("点火启动开关", false);//关闭点火 + BottomClick("点火复位开关");//复位点火开关 + Write("点火启动开关", true);//重新点火 + } + else{ + IsForcedEnd=true; + MessageLog.ShowInfo("点火失败,取消继续点火,强制结束任务"); + } + }); + Delay(2000); + } + Delay(3000); + if(getDeviceData.IgnitionNormal){ + MessageLog.ShowInfo("开火成功"); + break; + } + + Delay(100); + } + + }else{ + MessageLog.ShowInfo("关火中...."); + Write("点火启动开关", false);//关闭点火 + } + + if(!IsForcedEnd){ + Write("小火比例阀开度", val1); + Write("中火比例阀开度", val2); + Write("大火比例阀开度", val3); + Write("强火比例阀开度", val4); + + Write("小火开关(一圈)", val1>0); + Write("中火开关(二圈)", val2>0); + Write("大火开关(三圈)", val3>0); + Write("强火开关(四圈)", val4>0); + } + + } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); } @@ -394,38 +643,83 @@ public class ExecuteTheRecipe { */ private static void Write_PLC_ConstraintCondition(HashMap data) { try { - int time = 0; - int temp = 0; - int val = 0; +// int time = 0; +// float temp = 0; +// float val = 0; +// for (HashMap.Entry entry : data.entrySet()) { +// String key = entry.getKey(); +// String value = entry.getValue(); +// if (key.contains("(秒)")) { +// time = Integer.parseInt(value); +// } +// if (key.contains("锅内重量")) { +// val = Float.parseFloat(value); +// } +// if (key.contains("温度设定")) { +// temp = Float.parseFloat(value); +// } +// } + + for (HashMap.Entry entry : data.entrySet()) { String key = entry.getKey(); String value = entry.getValue(); if (key.contains("(秒)")) { - time = Integer.parseInt(value); + Convert.TryToGenericity(value).OnSource(p->{ + if (p.Content > 0 && !IsForcedEnd) { + MessageLog.ShowInfo("等待时间:"+p.Content+" 秒"); + ThreadDelay(p.Content); + if(IsForcedEnd) MessageLog.ShowInfo("等待时间:强制结束"); + else MessageLog.ShowInfo("等待时间完成"); + } + }); } if (key.contains("锅内重量")) { - val = Integer.parseInt(value); + Convert.TryToGenericity(value).OnSource(p->{ + if (p.Content > 0 && !IsForcedEnd) { + MessageLog.ShowInfo("等待温度:"+p.Content+" ℃"); + ThreadWhile("炒锅当前温度", p.Content); + if(IsForcedEnd) MessageLog.ShowInfo("等待温度:强制结束"); + else MessageLog.ShowInfo("等待温度完成"); + } + }); } if (key.contains("温度设定")) { - temp = Integer.parseInt(value); + Convert.TryToGenericity(value).OnSource(p->{ + if (p.Content > 0 && !IsForcedEnd) { + MessageLog.ShowInfo("等待重量:"+p.Content+"KG"); + ThreadWhile("炒锅当前重量", p.Content); + if(IsForcedEnd) MessageLog.ShowInfo("等待重量:强制结束"); + else MessageLog.ShowInfo("等待重量完成"); + } + }); } } - //1.判断等待时长是否满足 - if (time > 0 && !IsForcedEnd) { - ThreadDelay(time); - } +// if (time > 0 && !IsForcedEnd) { +// MessageLog.ShowInfo("等待时间:"+time+" 秒"); +// ThreadDelay(time); +// if(IsForcedEnd) MessageLog.ShowInfo("等待时间:强制结束"); +// else MessageLog.ShowInfo("等待时间完成"); +// } + //2.判断温度是否满足 - if (temp > 0 && !IsForcedEnd) { - ThreadWhile("炒锅当前温度", temp); - } +// if (temp > 0 && !IsForcedEnd) { +// MessageLog.ShowInfo("等待温度:"+temp+" ℃"); +// ThreadWhile("炒锅当前温度", temp); +// if(IsForcedEnd) MessageLog.ShowInfo("等待温度:强制结束"); +// else MessageLog.ShowInfo("等待温度完成"); +// } //3.判断重量是否到达 - if (val > 0 && !IsForcedEnd) { - ThreadWhile("炒锅当前重量", val); - } +// if (val > 0 && !IsForcedEnd) { +// MessageLog.ShowInfo("等待重量:"+val+"KG"); +// ThreadWhile("炒锅当前重量", val); +// if(IsForcedEnd) MessageLog.ShowInfo("等待重量:强制结束"); +// else MessageLog.ShowInfo("等待重量完成"); +// } } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); @@ -447,14 +741,6 @@ public class ExecuteTheRecipe { ConfigName.getInstance().PLC_Address.put(item.name, item); } } - - new Thread(new Runnable() { - @Override - public void run() { - WritePLC("系统启停开关", true); - } - }).start(); - ThreadManager.Get().StartLong("PLC设备数据监听", true, new IThread() { @Override public void Run() throws InterruptedException { @@ -486,9 +772,9 @@ public class ExecuteTheRecipe { try { if (ConfigName.getInstance().PlcIsConnect) { //心跳 - WritePLC("上位机-PLC", true); + Write("上位机-PLC", true); Thread.sleep(500); - WritePLC("上位机-PLC", false); + Write("上位机-PLC", false); } } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); @@ -506,6 +792,41 @@ public class ExecuteTheRecipe { //region 界面事件 + /** + * 阻断按钮 + * + * @param name + */ + public static void BottomClickAsync(String name) { +// try { +// Log.e("按钮按下", name); +// Write(name, true); +// Thread.sleep(100); +// Write(name, false); +// Log.e("按钮复位", name); +// ExecuteTheRecipe.showlog("写入plc-------" + name); +// } catch (Exception ex) { +// Log.e("按钮异常", name + ex.getMessage()); +// Write(name, false); +// } + + + Executor.get().runThread(()->{ + try { +// Log.e("按钮按下", name); + Write(name, true); + Thread.sleep(100); + Write(name, false); +// Log.e("按钮复位", name); + ExecuteTheRecipe.showlog("写入plc-------" + name); + } catch (Exception ex) { +// Log.e("按钮异常", name + ex.getMessage()); + MessageLog.ShowError(name + ex.getMessage()); + Write(name, false); + } + }); + } + /** * 阻断按钮 * @@ -513,15 +834,13 @@ public class ExecuteTheRecipe { */ public static void BottomClick(String name) { try { - Log.e("按钮按下", name); - WritePLC(name, true); + Write(name, true); Thread.sleep(100); - WritePLC(name, false); - Log.e("按钮复位", name); + Write(name, false); ExecuteTheRecipe.showlog("写入plc-------" + name); } catch (Exception ex) { Log.e("按钮异常", name + ex.getMessage()); - WritePLC(name, false); + Write(name, false); } } @@ -550,7 +869,7 @@ public class ExecuteTheRecipe { * @param delay */ public static void ThreadDelay(int delay) { - ExecuteTheRecipe.showlog("工序线程等待-------时长:" + delay + "秒,请耐心等待,开始计时!"); +// ExecuteTheRecipe.showlog("工序线程等待-------时长:" + delay + "秒,请耐心等待,开始计时!"); long startTime = System.currentTimeMillis(); while ((System.currentTimeMillis() - startTime) <= (delay * 1000) && !IsForcedEnd) { @@ -562,7 +881,7 @@ public class ExecuteTheRecipe { long endTime = System.currentTimeMillis(); //结束时间 int time = (int) ((endTime - startTime) / 1000); - ExecuteTheRecipe.showlog("工序线程等待结束-------总耗时:" + time); +// ExecuteTheRecipe.showlog("工序线程等待结束-------总耗时:" + time); } /** @@ -636,24 +955,19 @@ public class ExecuteTheRecipe { * * @param name */ - public static void ThreadWhile(String name, int val) { + public static void ThreadWhile(String name, Float val) { final boolean[] IsComplete = {false}; long a = System.currentTimeMillis(); - ExecuteTheRecipe.showlog(name + ",等待数据大于" + val); +// ExecuteTheRecipe.showlog(name + ",等待数据大于" + val); while (!IsComplete[0] && !IsForcedEnd) { - if ((System.currentTimeMillis() - a) > 1000 * whileTime) { - ExecuteTheRecipe.showlog(name + ",异常超时退出!"); - break; - } else { Object sb = ReadPLC(name); - int value = sb == null ? 0 : (int) (sb); + float value = sb == null ? 0 : (float) (sb); if (value >= val) { IsComplete[0] = true; - ExecuteTheRecipe.showlog(name + ",接收到信号!"); +// ExecuteTheRecipe.showlog(name + ",接收到信号!"); } else { IsComplete[0] = false; } - } try { Thread.sleep(100); } catch (InterruptedException e) { @@ -661,7 +975,7 @@ public class ExecuteTheRecipe { ExecuteTheRecipe.showlog(name + ",异常退出!" + e.getMessage()); } } - ExecuteTheRecipe.showlog(name + ",等待结束!"); +// ExecuteTheRecipe.showlog(name + ",等待结束!"); } //endregion @@ -817,9 +1131,10 @@ public class ExecuteTheRecipe { * 显示日志 */ public static void showlog(String msg) { - msg=ConfigName.getInstance().user.name+"_"+msg; - Log.e("hbl", msg); - ToastUtils.info(msg); + msg=ConfigName.getInstance().user.name+"-"+msg; + MessageLog.ShowInfo(msg); +// Log.e("hbl", msg); + //ToastUtils.info(msg); } //endregion @@ -831,21 +1146,60 @@ public class ExecuteTheRecipe { * @param name * @param value */ - public static void WritePLC(String name, Object value) { + public static void Write(String name, Object value) { try { if (ConfigName.getInstance().PLC_Address.containsKey(name)) { BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); if (!plcaddress.address.isEmpty()) { - CommHelper.get().writePLC(plcaddress.address, value); showlog(name+"_写入值_"+value); + CommHelper.get().writePLC(plcaddress.address, value); + } + else{ + MessageLog.ShowInfo(name+":写入数据失败,PLC地址为空"); } } + else{ + MessageLog.ShowInfo(name+":写入数据失败,配置文件中不存在该PLC地址"); + } } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); } finally { } } + /** + * 写PLC数据 + * + * @param name + * @param value + */ + public static void WriteAsync(String name, Object value) { + Executor.get().runThread(()->{ + if (ConfigName.getInstance().PLC_Address.containsKey(name)) { + BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); + if (!plcaddress.address.isEmpty()) { + showlog(name+"_写入值_"+value); + CommHelper.get().writePLC(plcaddress.address, value); + } + else{ + MessageLog.ShowInfo(name+":写入数据失败,PLC地址为空"); + } + } + else{ + MessageLog.ShowInfo(name+":写入数据失败,配置文件中不存在该PLC地址"); + } + }); + } + + public static void DischargeControlAsync(Float SetWeight,Float SetLead){ + showlog("手动出料,设定重量:"+SetWeight+",提前量:"+SetLead); + Executor.get().runThread(()->{ + Write("设定重量", SetWeight); + Write("设定提前量", SetLead); + Write("料仓1出料", true); + }); + } + /** * 读PLC数据 * @@ -858,9 +1212,14 @@ public class ExecuteTheRecipe { if (ConfigName.getInstance().PLC_Address.containsKey(name)) { BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); if (!plcaddress.address.isEmpty() ) { - ReturnsVariable = CommHelper.get().readPLC(plcaddress.address); } + else{ + MessageLog.ShowInfo(name+":读取数据失败,PLC地址为空"); + } + } + else{ + MessageLog.ShowInfo(name+":读取数据失败,配置文件中不存在该PLC地址"); } } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); @@ -869,6 +1228,25 @@ public class ExecuteTheRecipe { } } + public static OperateResultT Read(String name) { + try { + if (ConfigName.getInstance().PLC_Address.containsKey(name)) { + BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); + if (!plcaddress.address.isEmpty() ) { + return CommHelper.get().Read(plcaddress.address); + } + else{ + return OperateResultT.CreateFailedT(name+":读取数据失败,PLC地址为空"); + } + } + else{ + return OperateResultT.CreateFailedT(name+":读取数据失败,配置文件中不存在该PLC地址"); + } + } catch (Exception ex) { + return OperateResultT.CreateFailedT("读取异常,异常信息:" + ex.toString()); + } + } + /** * 获取监听变量 * 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 a1a031ef..8f47aca5 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 @@ -335,18 +335,18 @@ public class ConfigName { add(new Res_PLCADDRESS("PLC-上位机", "V280.1", 1, 1)); }}; /** - * 大炒工序模型 + * 燃气炒锅工艺功能的配置 */ 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("温度设定", "锅内重量", "等待(秒)"))); }}; /** - * 根据名称获取变量 + * 根据工艺的功能属性配置属性的数据类型 * * @param item * @return @@ -358,6 +358,9 @@ public class ConfigName { } else if (item.equals("位置动作")) { data = "炒菜位、倒菜位、清洗位"; } + else if (item.equals("火力状态")) { + data = "启动、停止"; + } return data; } diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/Convert.java b/app/src/main/java/com/bonait/bnframework/common/helper/Convert.java new file mode 100644 index 00000000..a9334967 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/helper/Convert.java @@ -0,0 +1,50 @@ +package com.bonait.bnframework.common.helper; + +import com.bonait.bnframework.common.helper.Result.OperateResultT; + +public class Convert { + public static OperateResultT TryToBoolean(Object value){ + if(value==null) return OperateResultT.CreateFailedT("TryToBoolean 解析对象为空"); + try{ + return OperateResultT.CreateSuccess(Boolean.parseBoolean(value.toString())); + }catch (Exception e) { + return OperateResultT.CreateFailedT(e); + } + } + + public static OperateResultT TryToInt(Object value){ + if(value==null) return OperateResultT.CreateFailedT("TryToInt 解析对象为空"); + try{ + return OperateResultT.CreateSuccess(Integer.parseInt(value.toString())); + }catch (Exception e) { + return OperateResultT.CreateFailedT(e); + } + } + + public static OperateResultT TryToShort(Object value){ + if(value==null) return OperateResultT.CreateFailedT("TryToShort 解析对象为空"); + try{ + return OperateResultT.CreateSuccess(Short.parseShort(value.toString())); + }catch (Exception e) { + return OperateResultT.CreateFailedT(e); + } + } + + public static OperateResultT TryToFloat(Object value){ + if(value==null) return OperateResultT.CreateFailedT("TryToFloat 解析对象为空"); + try{ + return OperateResultT.CreateSuccess(Float.parseFloat(value.toString())); + }catch (Exception e) { + return OperateResultT.CreateFailedT(e); + } + } + + public static OperateResultT TryToGenericity( Object value){ + if(value==null) return OperateResultT.CreateFailedT("TryToGenericity 解析对象为空"); + try{ + return OperateResultT.CreateSuccess((T)value); + }catch (Exception e) { + return OperateResultT.CreateFailedT(e); + } + } +} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/Executor.java b/app/src/main/java/com/bonait/bnframework/common/helper/Executor.java new file mode 100644 index 00000000..de0eb445 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/helper/Executor.java @@ -0,0 +1,42 @@ +package com.bonait.bnframework.common.helper; + +import com.bonait.bnframework.common.helper.I.IRun; +import com.bonait.bnframework.common.modbus.s7.CommHelper; +import com.bonait.bnframework.common.utils.ToastUtils; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.function.Supplier; + +public class Executor { + + private static Executor mInstance; //实例变量设置私有,防止直接通过类名访问 + + private Executor() { //默认构造函数私有,防止类外直接new创建对象 + } + + public static synchronized Executor get() { //静态同步方法作为唯一的实例对象获取方式 + if (mInstance == null) { + mInstance = new Executor(); + } + return mInstance; + } + private ExecutorService executor= Executors.newCachedThreadPool() ; + + public void runThread(IRun run) { + executor.submit(new Runnable(){ + @Override + public void run() { + try { + if(run!=null)run.Run(); + }catch(Exception ex) { + ToastUtils.error("异常信息:" + ex.getMessage()); + MessageLog.ShowError("runThread 异常:"+ex.getMessage()); + } + } + }); + } + + +} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/I/IDialogAction.java b/app/src/main/java/com/bonait/bnframework/common/helper/I/IDialogAction.java new file mode 100644 index 00000000..b4e92b5e --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/helper/I/IDialogAction.java @@ -0,0 +1,8 @@ +package com.bonait.bnframework.common.helper.I; + +public interface IDialogAction { +// void Confirm(); +// void Cancel(); + void ExitDialog(boolean status); + +} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/NotifyPropVar.java b/app/src/main/java/com/bonait/bnframework/common/helper/NotifyPropVar.java new file mode 100644 index 00000000..7273a430 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/helper/NotifyPropVar.java @@ -0,0 +1,29 @@ +package com.bonait.bnframework.common.helper; + +import com.bonait.bnframework.common.helper.I.IRunT; +import com.bonait.bnframework.common.helper.Result.OperateResultT; + +public class NotifyPropVar { + + public NotifyPropVar(T defaultValue){ + _value=defaultValue; + } + public IRunT ChangeNotify; + private T _value; + private boolean IsFirst=false; + + public T getValue(){ + return _value; + } + + public void setValue(T value){ + if (value != null && !value.equals(_value) || !IsFirst) + { + _value=value; + if(ChangeNotify!=null) ChangeNotify.Run(value); + IsFirst = true; + } + } + + +} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/Result/IResult.java b/app/src/main/java/com/bonait/bnframework/common/helper/Result/IResult.java new file mode 100644 index 00000000..74336886 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/helper/Result/IResult.java @@ -0,0 +1,45 @@ +package com.bonait.bnframework.common.helper.Result; + +public abstract class IResult { + /** + * 是否成功 + */ + public boolean isSuccess ; + + /** + * 返回消息 + */ + public String message; + + /** + * 操作代码 + */ + public ResultCode resultCode = ResultCode.Default ; + + abstract void setErrorMsg(String msg); + + public boolean getIsSuccess(){ + return resultCode==ResultCode.Success; + } + + public void setIsSuccess(boolean tempSuccess){ + isSuccess= tempSuccess; + resultCode = tempSuccess ? ResultCode.Success : ResultCode.Fail; + } +// +// String getMessage(){ +// return Message; +// } +// +// void setMessage(String message){ +// Message= message; +// } +// +// ResultCode getResultCode(){ +// return ResultCode; +// } +// +// void setResult(ResultCode resultCode){ +// ResultCode=resultCode; +// } +} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/Result/OperateResult.java b/app/src/main/java/com/bonait/bnframework/common/helper/Result/OperateResult.java new file mode 100644 index 00000000..d7b2cf1c --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/helper/Result/OperateResult.java @@ -0,0 +1,77 @@ +package com.bonait.bnframework.common.helper.Result; + +import com.bonait.bnframework.common.helper.I.IRun; +import com.bonait.bnframework.common.helper.MessageLog; + +public class OperateResult extends IResult { + + public OperateResult(){ + + } + + public OperateResult(Exception ex){ + message = ex.getMessage()+"\rException:"+ex.toString(); + resultCode = ResultCode.Exception; + isSuccess=false; + } + + public OperateResult(String msg, ResultCode rc) + { + message = msg; + resultCode = rc; + isSuccess=false; + } + + public OperateResult(ResultCode rc) + { + resultCode = rc; + isSuccess=true; + } + + + @Override + public void setErrorMsg(String msg) { + message =message+ msg; + isSuccess=false; + resultCode = ResultCode.Fail; + } + + public OperateResult OnSource(IRun action){ + if(action!=null&&getIsSuccess())action.Run(); + return this; + } + + public OperateResult OnFailed(IRun action){ + if(action!=null&&!getIsSuccess())action.Run(); + return this; + } + + public OperateResult OnFinally(IRun action){ + if(action!=null)action.Run(); + return this; + } + + public static OperateResult CreateSuccess() + { + return new OperateResult(ResultCode.Success); + } + + public static OperateResult CreateFailed(String msg) + { + MessageLog.ShowError(msg); + return new OperateResult(msg, ResultCode.Fail); + } + + public static OperateResult CreateFailed(Exception ex) + { + MessageLog.ShowError(ex.toString()); + return new OperateResult(ex); + } + + + + +} + + + diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/Result/OperateResultT.java b/app/src/main/java/com/bonait/bnframework/common/helper/Result/OperateResultT.java new file mode 100644 index 00000000..6969c8c5 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/helper/Result/OperateResultT.java @@ -0,0 +1,74 @@ +package com.bonait.bnframework.common.helper.Result; + +import com.bonait.bnframework.common.helper.I.IRunT; +import com.bonait.bnframework.common.helper.MessageLog; + +public class OperateResultT extends OperateResult +{ + public OperateResultT(Exception ex) + { + super(ex); + } + + public OperateResultT(String msg, ResultCode rc ) + { + super(msg, rc); + } + + public OperateResultT(ResultCode rc) + { + super(rc); + } + public OperateResultT() + { + super(); + } + public OperateResultT(T content, String msg, ResultCode rc) + { + Content = content; + message = msg; + resultCode = rc; + isSuccess=getIsSuccess(); + } + + public T Content ; + + public void setContent(T value) + { + Content = value; + resultCode = ResultCode.Success; + isSuccess=true; + } + + public OperateResultT OnSource(IRunT> action){ + if(action!=null&&getIsSuccess())action.Run(this); + return this; + } + + public OperateResultT OnFailed(IRunT> action){ + if(action!=null&&!getIsSuccess())action.Run(this); + return this; + } + + public OperateResultT OnFinally(IRunT> action){ + if(action!=null)action.Run(this); + return this; + } + + public static OperateResultT CreateSuccess(T value) + { + return new OperateResultT(value,"", ResultCode.Success); + } + + public static OperateResultT CreateFailedT(String msg) + { + MessageLog.ShowError(msg); + return new OperateResultT( msg, ResultCode.Fail); + } + + public static OperateResultT CreateFailedT(Exception ex) + { + MessageLog.ShowError(ex.toString()); + return new OperateResultT(ex); + } +} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/Result/ResultCode.java b/app/src/main/java/com/bonait/bnframework/common/helper/Result/ResultCode.java new file mode 100644 index 00000000..02c287c6 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/helper/Result/ResultCode.java @@ -0,0 +1,38 @@ +package com.bonait.bnframework.common.helper.Result; + +public enum ResultCode { + /** + * 默认 + */ + Default, + + /** + * 错误 + */ + Error, + + /** + * 异常 + */ + Exception, + + /** + * 成功 + */ + Success, + + /** + * 失败 + */ + Fail, + + /** + * 操作超时 + */ + Overtime, + + /** + * 操作取消 + */ + Canceled +} diff --git a/app/src/main/java/com/bonait/bnframework/common/helper/Stopwatch.java b/app/src/main/java/com/bonait/bnframework/common/helper/Stopwatch.java new file mode 100644 index 00000000..40a6db0f --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/common/helper/Stopwatch.java @@ -0,0 +1,37 @@ +package com.bonait.bnframework.common.helper; + +public class Stopwatch { + + private long ElapsedMilliseconds; + + private boolean IsRunning; + + private long StartTime; + + public long getElapsedMilliseconds() { + return ElapsedMilliseconds; + } + + public void Reset(){ + ElapsedMilliseconds=0; + StartTime =0; + } + + public void Restart(){ + ElapsedMilliseconds=0; + StartTime =System.currentTimeMillis(); + IsRunning=true; + } + + public void Start(){ + StartTime =System.currentTimeMillis(); + IsRunning=true; + } + + public void Stop(){ + if(IsRunning){ + ElapsedMilliseconds = System.currentTimeMillis()- StartTime; + } + IsRunning=false; + } +} diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/s7/CommHelper.java b/app/src/main/java/com/bonait/bnframework/common/modbus/s7/CommHelper.java index 64941888..088b0e04 100644 --- a/app/src/main/java/com/bonait/bnframework/common/modbus/s7/CommHelper.java +++ b/app/src/main/java/com/bonait/bnframework/common/modbus/s7/CommHelper.java @@ -1,15 +1,14 @@ package com.bonait.bnframework.common.modbus.s7; -import android.util.Log; - import com.bonait.bnframework.common.constant.ConfigName; +import com.bonait.bnframework.common.helper.Convert; import com.bonait.bnframework.common.helper.I.IRun; import com.bonait.bnframework.common.helper.MessageLog; +import com.bonait.bnframework.common.helper.Result.OperateResult; +import com.bonait.bnframework.common.helper.Result.OperateResultT; import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.LineNumberReader; +import kotlin.UShort; public class CommHelper { @@ -24,10 +23,12 @@ public class CommHelper { } return mInstance; } - + public boolean IsConnected(){ + return siemens.IsConnected; + } public IRun ConnectOk; - SiemensHelper siemens=new SiemensHelper(EPlcType.S200_SMART, ConfigName.getInstance().Address); + public SiemensHelper siemens=new SiemensHelper(EPlcType.S200_SMART, ConfigName.getInstance().Address); public void Connect(){ new Thread(new Runnable() { @@ -38,27 +39,36 @@ public class CommHelper { while (!siemens.checkConnected()){ try{ tempFlag++; + siemens=new SiemensHelper(EPlcType.S200_SMART, ConfigName.getInstance().Address); siemens.connect(); + siemens.Delay(1000); }catch (Exception e){ if(tempFlag==1)MessageLog.ShowInfo("PLC连接失败:"+e.getMessage()); siemens.Delay(1000); } } if(ConnectOk!=null)ConnectOk.Run(); + siemens.IsConnected=true; MessageLog.ShowInfo("PLC连接成功"); } }).start(); } + + public void writePLC(String add,Object value){ + if(!IsConnected()) { + MessageLog.ShowInfo(add+":写入数据失败,连接已断开"); + return; + } if(value==null) { MessageLog.ShowInfo("writePLC:写入值为空"); return; } try{ if(add.toUpperCase().contains("VD")){ - Integer tempVD= Integer.parseInt(value.toString()); - siemens.WriteInt32(add,tempVD); + Float tempVD= Float.parseFloat(value.toString()); + siemens.WriteFloat32(add,tempVD); } else if (add.toUpperCase().contains("VW")){ Integer tempVW= Integer.parseInt(value.toString()); @@ -75,9 +85,13 @@ public class CommHelper { } public Object readPLC(String add){ + if(!IsConnected()) { + MessageLog.ShowInfo(add+":读取数据失败,连接已断开"); + return new Object(); + } try{ if(add.toUpperCase().contains("VD")){ - return siemens.ReadInt32(add); + return siemens.ReadFloat32(add); } else if (add.toUpperCase().contains("VW")){ return siemens.ReadUInt16(add); @@ -91,4 +105,59 @@ public class CommHelper { return new Object(); } + public OperateResultT Read(String add){ + if(!IsConnected()) return OperateResultT.CreateFailedT(add+":读取数据失败,连接已断开"); + OperateResultT result = new OperateResultT<>(); + String typeName=result.Content.getClass() .getName(); + try{ + if(typeName.contains("Boolean")){ + return Convert.TryToGenericity(siemens.ReadBoolean(add)); + }else if(typeName.contains("Integer")){ + if(add.toUpperCase().contains("VD")){ + return Convert.TryToGenericity(siemens.ReadInt32(add)); + } + else if (add.toUpperCase().contains("VW")){ + return Convert.TryToGenericity(siemens.ReadUInt16(add)); + } + }else if(typeName.contains("Short")){ + return Convert.TryToGenericity(siemens.ReadInt16(add)); + }else if(typeName.contains("Float")){ + return Convert.TryToGenericity(siemens.ReadFloat32(add)); + }else{ + return OperateResultT.CreateFailedT(typeName+" 暂不支持的数据类型"); + } + }catch (Exception e){ + return OperateResultT.CreateFailedT(e); + } + return result; + } + + public OperateResult Write(String add, T value){ + if(!IsConnected()) return OperateResult.CreateFailed(add+":读取数据失败,连接已断开"); + if(value ==null) return OperateResult.CreateFailed(add+":写入值无效"); + String typeName=value.getClass() .getName(); + try{ + + if(typeName.contains("Boolean")){ + Convert.TryToGenericity(value).OnSource(s->{ siemens.WriteBoolean(add,s.Content);}); + }else if(typeName.contains("Integer")){ + if(add.toUpperCase().contains("VD")){ + Convert.TryToGenericity(value).OnSource(s->{ siemens.WriteInt32(add,s.Content);}); + } + else if (add.toUpperCase().contains("VW")){ + Convert.TryToGenericity(value).OnSource(s->{ siemens.WriteUInt16(add,s.Content);}); + } + }else if(typeName.contains("Short")){ + Convert.TryToGenericity(value).OnSource(s->{ siemens.WriteInt16(add,s.Content);}); + }else if(typeName.contains("Float")){ + Convert.TryToGenericity(value).OnSource(s->{ siemens.WriteFloat32(add,s.Content);}); + }else{ + return OperateResult.CreateFailed(typeName+" 暂不支持的数据类型"); + } + return OperateResult.CreateSuccess(); + }catch (Exception e){ + return OperateResult.CreateFailed(e); + } + } + } diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/s7/SiemensHelper.java b/app/src/main/java/com/bonait/bnframework/common/modbus/s7/SiemensHelper.java index f78ef81b..79826963 100644 --- a/app/src/main/java/com/bonait/bnframework/common/modbus/s7/SiemensHelper.java +++ b/app/src/main/java/com/bonait/bnframework/common/modbus/s7/SiemensHelper.java @@ -4,6 +4,7 @@ import static com.github.xingshuangs.iot.common.constant.GeneralConst.S7_PORT; import android.util.Log; +import com.bonait.bnframework.common.helper.MessageLog; import com.github.xingshuangs.iot.exceptions.SocketRuntimeException; import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType; import com.github.xingshuangs.iot.protocol.s7.model.DataItem; @@ -21,18 +22,20 @@ import java.util.List; public class SiemensHelper extends S7PLC { - /** - * 判断PLC连接是否成功 - * @return - */ - public boolean IsConnected(){ - try { - socket.sendUrgentData(0xff); - return true; - }catch(Exception e){ - return false; - } - } +// /** +// * 判断PLC连接是否成功 +// * @return +// */ +// public boolean IsConnected(){ +// try { +// socket.sendUrgentData(0xff); +// return true; +// }catch(Exception e){ +// return false; +// } +// } + + public Boolean IsConnected=false; public void Delay(long millis){ try{ @@ -43,187 +46,317 @@ public class SiemensHelper extends S7PLC { } public boolean ReadBoolean(String address){ + if(!IsConnected){ + MessageLog.ShowInfo(address+":读取数据失败,连接已断开"); + return false; + } try { - return this.readBoolean(address); + boolean result=this.readBoolean(address); + IsConnected=true; + return result; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; } return false; } public List ReadBoolean(String... address) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":读取数据失败,连接已断开"); + return new ArrayList(); + } try { - return this.readBoolean(Arrays.asList(address)); + List result=this.readBoolean(Arrays.asList(address)); + IsConnected=true; + return result; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; } return new ArrayList(); } public short ReadInt16(String address) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":读取数据失败,连接已断开"); + return 0; + } try { DataItem dataItem = this.readS7Data(AddressUtil.parseByte(address, 2)); - return ShortUtil.toInt16(dataItem.getData()); + short result= ShortUtil.toInt16(dataItem.getData()); + IsConnected=true; + return result; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; } return 0; } public List ReadInt16(String... address) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":读取数据失败,连接已断开"); + return new ArrayList(); + } try { - return this.readInt16(Arrays.asList(address)); + List result=this.readInt16(Arrays.asList(address)); + IsConnected=true; + return result; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; } return new ArrayList(); } public int ReadUInt16(String address) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":读取数据失败,连接已断开"); + return 0; + } try { DataItem dataItem = this.readS7Data(AddressUtil.parseByte(address, 2)); - return ShortUtil.toUInt16(dataItem.getData()); + int result= ShortUtil.toUInt16(dataItem.getData()); + IsConnected=true; + return result; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; } return 0; } public List ReadUInt16(String... address) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":读取数据失败,连接已断开"); + return new ArrayList(); + } try { - return this.readUInt16(Arrays.asList(address)); + List result=this.readUInt16(Arrays.asList(address)); + IsConnected=true; + return result; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; } return new ArrayList(); } public int ReadInt32(String address) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":读取数据失败,连接已断开"); + return 0; + } try { DataItem dataItem = this.readS7Data(AddressUtil.parseByte(address, 4)); - return IntegerUtil.toInt32(dataItem.getData()); + int result= IntegerUtil.toInt32(dataItem.getData()); + IsConnected=true; + return result; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; } return 0; } public List ReadInt32(String... address) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":读取数据失败,连接已断开"); + return new ArrayList(); + } try { - return this.readInt32(Arrays.asList(address)); + List result=this.readInt32(Arrays.asList(address)); + IsConnected=true; + return result; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; } return new ArrayList(); } public float ReadFloat32(String address) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":读取数据失败,连接已断开"); + return 0; + } try { DataItem dataItem = this.readS7Data(AddressUtil.parseByte(address, 4)); - return FloatUtil.toFloat32(dataItem.getData()); + float result= FloatUtil.toFloat32(dataItem.getData()); + IsConnected=true; + return result; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; } return 0; } public List ReadFloat32(String... address) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":读取数据失败,连接已断开"); + return new ArrayList(); + } try { - return this.readFloat32(Arrays.asList(address)); + List result=this.readFloat32(Arrays.asList(address)); + IsConnected=true; + return result; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; } return new ArrayList(); } public void WriteBoolean(String address, boolean data) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":写入数据失败,连接已断开"); + return; + } while (true) { try { this.writeS7Data(AddressUtil.parseBit(address), DataItem.createReqByBoolean(data)); + IsConnected=true; break; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; Delay(100); } + catch (Exception e){ + MessageLog.ShowError("WriteBoolean 写入异常:"+e.toString()); + break; + } } } public void WriteUInt16(String address, int data) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":写入数据失败,连接已断开"); + return; + } while (true) { try { this.writeByte(address, ShortUtil.toByteArray(data)); + IsConnected=true; break; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; Delay(100); } + catch (Exception e){ + MessageLog.ShowError("WriteUInt16 写入异常:"+e.toString()); + break; + } } } public void WriteInt16(String address, short data) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":写入数据失败,连接已断开"); + return; + } while (true) { try { Log.e("info","准备写入数据:"+data); this.writeByte(address, ShortUtil.toByteArray(data)); + IsConnected=true; break; } catch(SocketRuntimeException ex){ Log.e("socketException","写入:"+data+"失败"); this.close(); + IsConnected=false; Delay(100); } + catch (Exception e){ + MessageLog.ShowError("WriteInt16 写入异常:"+e.toString()); + break; + } } } public void WriteUInt32(String address, long data) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":写入数据失败,连接已断开"); + return; + } while (true) { try { this.writeByte(address, IntegerUtil.toByteArray(data)); + IsConnected=true; break; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; Delay(100); } + catch (Exception e){ + MessageLog.ShowError("WriteUInt32 写入异常:"+e.toString()); + break; + } } } public void WriteInt32(String address, int data) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":写入数据失败,连接已断开"); + return; + } while (true) { try { this.writeByte(address, IntegerUtil.toByteArray(data)); + IsConnected=true; break; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; Delay(100); } + catch (Exception e){ + MessageLog.ShowError("WriteInt32 写入异常:"+e.toString()); + break; + } } } public void WriteFloat32(String address, float data) { + if(!IsConnected){ + MessageLog.ShowInfo(address+":写入数据失败,连接已断开"); + return; + } while (true) { try { this.writeByte(address, FloatUtil.toByteArray(data)); + IsConnected=true; break; } catch(SocketRuntimeException ex){ this.close(); + IsConnected=false; Delay(100); } + catch (Exception e){ + MessageLog.ShowError("WriteFloat32 写入异常:"+e.toString()); + break; + } } } diff --git a/app/src/main/java/com/bonait/bnframework/common/utils/AlertDialogUtils.java b/app/src/main/java/com/bonait/bnframework/common/utils/AlertDialogUtils.java index 1ed9d6b1..8b959b67 100644 --- a/app/src/main/java/com/bonait/bnframework/common/utils/AlertDialogUtils.java +++ b/app/src/main/java/com/bonait/bnframework/common/utils/AlertDialogUtils.java @@ -2,6 +2,9 @@ package com.bonait.bnframework.common.utils; import android.content.Context; +import com.bonait.bnframework.common.helper.Executor; +import com.bonait.bnframework.common.helper.I.IDialogAction; +import com.bonait.bnframework.common.helper.I.IRun; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; @@ -65,6 +68,38 @@ public class AlertDialogUtils { .create(mCurrentDialogStyle).show(); } + /** + * 对话框,有取消确定按钮 + * */ + public static void showDialog(Context context, String title, String message, IDialogAction action) { + new QMUIDialog.MessageDialogBuilder(context) + .setCancelable(false) + .setTitle(title) + .setMessage(message) + .addAction("取消", new QMUIDialogAction.ActionListener() { + @Override + public void onClick(QMUIDialog dialog, int index) { +// if(action!=null)action.Cancel(); + if(action!=null)action.ExitDialog(false); + dialog.dismiss(); +// Executor.get().runThread(()->{ +// if(action!=null)action.ExitDialog(false); +// }); + } + }) + .addAction("确定", new QMUIDialogAction.ActionListener() { + @Override + public void onClick(QMUIDialog dialog, int index) { + if(action!=null)action.ExitDialog(true); + dialog.dismiss(); +// Executor.get().runThread(()->{ +// if(action!=null)action.ExitDialog(true); +// }); + } + }) + .create(mCurrentDialogStyle).show(); + } + /** * 对话框,自定义确定按钮 * */ diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java index 61454329..43dfee3c 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java @@ -101,7 +101,8 @@ public class BottomNavigationMainActivity extends BaseActivity { ConfigData.getInstance().ToggleEnvironment(); //2.初始化PLC // ReconnectModbus(); - CommHelper.get().Connect(); +// ConfigData.getInstance().PLC_Init(); +// CommHelper.get().Connect(); } /** diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java index 9fc3428a..00a6c204 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java @@ -2,60 +2,58 @@ package com.bonait.bnframework.modules.home.fragment; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.StaggeredGridLayoutManager; import android.app.Activity; import android.content.Context; import android.os.Bundle; -import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; -import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; +import android.widget.RadioButton; import android.widget.RelativeLayout; import android.widget.Spinner; import android.widget.TextView; import com.bonait.bnframework.R; +import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.business.ExecuteTheRecipe; import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.DataBus; -import com.bonait.bnframework.common.constant.MessageName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.res.StatusMode; -import com.bonait.bnframework.common.db.res.lcMode; import com.bonait.bnframework.common.helper.CountDownTimerExt; +import com.bonait.bnframework.common.helper.Convert; +import com.bonait.bnframework.common.helper.I.IRun; import com.bonait.bnframework.common.helper.I.IRunT; -import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.I.MyClickListener; +import com.bonait.bnframework.common.helper.MessageLog; +import com.bonait.bnframework.common.helper.Result.OperateResultT; import com.bonait.bnframework.common.image.MyBitmapUtils; -import com.bonait.bnframework.common.message.MessageLooper; -import com.bonait.bnframework.common.message.MessageManager; +import com.bonait.bnframework.common.modbus.s7.CommHelper; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.modules.home.adapter.devicestatus_adapter; -import com.bonait.bnframework.modules.home.adapter.liaochang_adapter; import com.bonait.bnframework.modules.home.fragment.from.CpxzActivity; import com.capton.colorfulprogressbar.ColorfulProgressbar; import com.litao.slider.NiftySlider; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; -import com.qmuiteam.qmui.widget.textview.QMUILinkTextView; import com.suke.widget.SwitchButton; import java.util.ArrayList; import java.util.List; +import java.util.stream.Stream; import butterknife.BindView; import butterknife.ButterKnife; @@ -132,12 +130,201 @@ public class MakeGoodFragment extends BaseFragment { super.onViewCreated(view, savedInstanceState); activity = getActivity(); context = getContext(); + ExecuteTheRecipe.mainContext=context; + ExecuteTheRecipe.mainActivity=activity; + NotifyProp(); initTopBar(); Initdata(); - StatusOrMakeGoodThread(); + CommHelper.get().ConnectOk = new IRun() { + @Override + public void Run() { + ConfigData.getInstance().PLC_Init(); + StatusOrMakeGoodThread(); + ExecuteTheRecipe.DeviceMonitor(); + } + }; + CommHelper.get().Connect(); Init_弹窗(); } + /** + * 通知属性初始化 + */ + private void NotifyProp(){ + + //系统启停状态更新 + ExecuteTheRecipe.getDeviceData.SystemStartStopStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + switch_系统启停.setChecked(s); + });}; + + //超温停气状态更新 + ExecuteTheRecipe.getDeviceData.OverTemperatureShutdownNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + switch_超温停气.setChecked(s); + });}; + + //点火模式状态更新 + ExecuteTheRecipe.getDeviceData.IgnideModeNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + RB_Hand.setChecked(s?true:false); +// editsp_点火模式.setSelection(s?0:1); + });}; + + //小火比例阀开度更新 + ExecuteTheRecipe.getDeviceData.SmallFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + slider_小火.setValue( s,false); + });}; + + //中火比例阀开度更新 + ExecuteTheRecipe.getDeviceData.MediumFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + slider_中火.setValue( s,false); + });}; + + //大火比例阀开度更新 + ExecuteTheRecipe.getDeviceData.HighFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + slider_大火.setValue( s,false); + });}; + + //强火比例阀开度更新 + ExecuteTheRecipe.getDeviceData.StrongFireProportionNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + slider_强火.setValue( s,false); + });}; + + //小火控制状态更新 + ExecuteTheRecipe.getDeviceData.SmallFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + switch_小火.setChecked(s); + });}; + + //中火控制状态更新 + ExecuteTheRecipe.getDeviceData.MediumFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + switch_中火.setChecked(s); + });}; + + //大火控制状态更新 + ExecuteTheRecipe.getDeviceData.HighFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + switch_大火.setChecked(s); + });}; + + //强火控制状态更新 + ExecuteTheRecipe.getDeviceData.StrongFireStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + switch_强火.setChecked(s); + });}; + + //点火控制状态更新 + ExecuteTheRecipe.getDeviceData.IgnitionStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + switch_点火控制.setChecked(s); + });}; + + //温度修正值更新 + ExecuteTheRecipe.getDeviceData.TemperatureCorrectionValueNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + edit_温度修正.setText(s.toString()); + });}; + + //炒锅温度上限设置值更新 + ExecuteTheRecipe.getDeviceData.UpperTemperatureLimitNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + edit_温度上限.setText(s.toString()); + });}; + + //搅拌控制状态更新 + ExecuteTheRecipe.getDeviceData.StirControlStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + switch_搅拌控制.setChecked(s); + });}; + + //抽油启停状态更新 + ExecuteTheRecipe.getDeviceData.OilPumpingStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + switch_抽油启停.setChecked(s); + });}; + + //备用气缸起停状态更新 + ExecuteTheRecipe.getDeviceData.StandbyCylinderStatusNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + switch_备用气缸.setChecked(s); + });}; + + //设定重量状态更新 + ExecuteTheRecipe.getDeviceData.SetWeightNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + edit_设定重量.setText(s.toString()); + });}; + + //提前量状态更新 + ExecuteTheRecipe.getDeviceData.LeadNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + edit_提前量.setText(s.toString()); + });}; + + //急停故障 + ExecuteTheRecipe.getDeviceData.EstopFaultNotify.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + MessageLog.ShowError(s?"急停故障触发":"急停故障复位"); + for (StatusMode mode : gzzt) { + if(mode.Name.equals("急停按下")) { + mode.Status = s; + break; + } + } + });}; + + //油泵故障 + ExecuteTheRecipe.getDeviceData.OilPumpFault.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + MessageLog.ShowError(s?"油泵故障触发":"油泵故障复位"); + for (StatusMode mode : gzzt) { + if(mode.Name.equals("油泵故障")) { + mode.Status = s; + break; + } + } + });}; + + //搅拌故障 + ExecuteTheRecipe.getDeviceData.MixingFailure.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + MessageLog.ShowError(s?"搅拌故障触发":"搅拌故障复位"); + for (StatusMode mode : gzzt) { + if(mode.Name.equals("搅拌故障")) { + mode.Status = s; + break; + } + } + });}; + + //点火异常故障 + ExecuteTheRecipe.getDeviceData.IgnitionMalfunction.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + MessageLog.ShowError(s?"点火故障触发":"点火故障复位"); + for (StatusMode mode : gzzt) { + if(mode.Name.equals("点火异常")) { + mode.Status = s; + break; + } + } + });}; + + //高温报警故障 + ExecuteTheRecipe.getDeviceData.HighTemperatureAlarm.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + MessageLog.ShowError(s?"高温故障触发":"高温故障复位"); + for (StatusMode mode : gzzt) { + if(mode.Name.equals("高温报警")) { + mode.Status = s; + break; + } + } + });}; + + //备用故障1 + ExecuteTheRecipe.getDeviceData.StandbyFailure.ChangeNotify=(s)->{getActivity().runOnUiThread(()->{ + MessageLog.ShowError(s?"备用故障1触发":"备用故障1复位"); + for (StatusMode mode : gzzt) { + if(mode.Name.equals("备用故障1")) { + mode.Status = s; + break; + } + } + });}; + + //自动任务状态通知 + ExecuteTheRecipe.IsStart.ChangeNotify=(s)->{ + getActivity().runOnUiThread(()->{ + dialog_xtkz.setVisibility(s? View.GONE:View.VISIBLE); + dialog_hlkz.setVisibility(s? View.GONE:View.VISIBLE); + dialog_kbkz.setVisibility(s? View.GONE:View.VISIBLE); + dialog_jykz.setVisibility(s? View.GONE:View.VISIBLE); + }); + }; + } + /** * 初始化TopBar */ @@ -160,6 +347,15 @@ public class MakeGoodFragment extends BaseFragment { //region 点击事件处理 + public boolean ConnectPrompt(){ + if(!CommHelper.get().IsConnected()){ + AlertDialogUtils.showDialog(context, "通讯提示", "请先连接设备!"); + return false; + } + return true; + } + + /** * 点击事件 * @@ -170,12 +366,7 @@ public class MakeGoodFragment extends BaseFragment { , R.id.btn_sjkz, R.id.btn_jykz , R.id.close_xtkz, R.id.close_hlkz , R.id.close_kbkz, R.id.close_jykz - - - , R.id.button_搅拌点动 - , R.id.button_搅拌上升, R.id.button_搅拌下降 - , R.id.button_锅前倾, R.id.button_锅后仰 - +,R.id.button_写入参数 , R.id.button_出料 , R.id.button_点火复位 }) @@ -205,10 +396,11 @@ public class MakeGoodFragment extends BaseFragment { SetVisibility(0); break; case R.id.startbutton: - if (ExecuteTheRecipe.IsStart) { + + if (ExecuteTheRecipe.IsStart.getValue()) { //按钮点击 String title = "停止操作提示!"; - String message = "请问客官确定要停止制作吗,小菠萝会生气的,啊啊啊啊啊啊啊...我的饭饭?"; + String message = "强制停止会提前结束任务,请问是否停止?"; AlertDialogUtils.showDialog(context, title, message, new QMUIDialogAction.ActionListener() { @Override public void onClick(QMUIDialog dialog, int index) { @@ -218,45 +410,31 @@ public class MakeGoodFragment extends BaseFragment { } }); } else { - if (good == null) { - ToastUtils.info("请先选择一个商品"); - return; - } - -// if (!IsMake(false)) { -// return; -// } + if (!IsMake(true)) return; - //按钮点击 - String title = "开始操作提示!"; - String message = "请问客官确定要开始制作吗,小菠萝好开心呀,马上就有好吃的耶?"; - AlertDialogUtils.showDialog(context, title, message, new QMUIDialogAction.ActionListener() { - @Override - public void onClick(QMUIDialog dialog, int index) { + AlertDialogUtils.showDialog(context, "提示", "是否开始制作商品?", (s)->{ + if(s){ + ExecuteTheRecipe.showlog("开始任务"); ExecuteTheRecipe.StopForcedEnd(); onRecordStart(); - dialog.dismiss(); } }); + + //按钮点击 +// AlertDialogUtils.showDialog(context, "提示", "是否开始制作商品?", new QMUIDialogAction.ActionListener() { +// @Override +// public void onClick(QMUIDialog dialog, int index) { +// ExecuteTheRecipe.StopForcedEnd(); +// onRecordStart(); +// dialog.dismiss(); +// } +// }); } break; //endregion //region PLC操作 - case R.id.button_搅拌上升: - ExecuteTheRecipe.BottomClick("搅拌上升"); - break; - case R.id.button_搅拌下降: - ExecuteTheRecipe.BottomClick("搅拌下降"); - break; - case R.id.button_锅前倾: - ExecuteTheRecipe.BottomClick("锅口向前"); - break; - case R.id.button_锅后仰: - ExecuteTheRecipe.BottomClick("锅口向后"); - break; - case R.id.button_出料: String s1 = edit_设定重量.getText().toString(); String s2 = edit_提前量.getText().toString(); @@ -268,92 +446,204 @@ public class MakeGoodFragment extends BaseFragment { ToastUtils.warning("提前量不能为空!"); return; } - int s1_1 = 0; - int s2_1 = 0; - try { - s1_1 = Integer.parseInt(s1); - s2_1 = Integer.parseInt(s2); - } catch (Exception ex) { - ToastUtils.warning("数据解析异常!" + ex.getMessage()); - return; +// float s1_1 = 0; +// float s2_1 = 0; +// try { +// s1_1 = Float.parseFloat(s1); +// s2_1 = Float.parseFloat(s2); +// } catch (Exception ex) { +// ToastUtils.warning("数据解析异常!" + ex.getMessage()); +// return; +// } + + OperateResultT s1_1 = Convert.TryToFloat(s1); + OperateResultT s2_1 = Convert.TryToFloat(s2); + if(s1_1.getIsSuccess()&&s2_1.getIsSuccess()){ + ExecuteTheRecipe.DischargeControlAsync(s1_1.Content,s2_1.Content); } - ExecuteTheRecipe.WritePLC("设定重量", s1_1); - ExecuteTheRecipe.WritePLC("设定提前量", s2_1); - ExecuteTheRecipe.WritePLC("设定提前量", s2_1); - ExecuteTheRecipe.WritePLC("料仓1出料", true); +// try { +// s1_1 = Float.parseFloat(s1); +// s2_1 = Float.parseFloat(s2); +// } catch (Exception ex) { +// ToastUtils.warning("数据解析异常!" + ex.getMessage()); +// return; +// } +// +// DataParse.TryToFloat(s1_1).OnSource((p1)->{ +// DataParse.TryToFloat(s2_1).OnSource((p2)->{ +// +// }); +// }); +// ExecuteTheRecipe.DischargeControlAsync(s1_1,s2_1); break; case R.id.button_点火复位: - ExecuteTheRecipe.BottomClick("点火复位开关"); + ExecuteTheRecipe.showlog("手动操作点火复位开关"); + ExecuteTheRecipe.BottomClickAsync("点火复位开关"); + break; + case R.id.button_写入参数: +// float temperatureCorrect= Float.parseFloat(edit_温度修正.getText().toString()); +// float temperatureUpperLimit= Float.parseFloat(edit_温度修正.getText().toString()); +// Executor.get().runThread(()->{ +// ExecuteTheRecipe.Write("炒锅温度修正",temperatureCorrect); +// ExecuteTheRecipe.Write("炒锅温度上限设置",temperatureUpperLimit); +// }); + + Convert.TryToFloat(edit_温度修正.getText()).OnSource((s)-> + { + ExecuteTheRecipe.showlog("手动设置温度修正值"); + ExecuteTheRecipe.WriteAsync("炒锅温度修正",s.Content); + }); + Convert.TryToFloat(edit_温度上限.getText()).OnSource((s)-> + { + ExecuteTheRecipe.showlog("手动设置温度上限值"); + ExecuteTheRecipe.WriteAsync("炒锅温度上限设置",s.Content); + }); break; //endregion } } +// /** +// * 开关事件处理 +// */ +// public SwitchButton.OnCheckedChangeListener checkedChangeListener = new SwitchButton.OnCheckedChangeListener() { +// @Override +// public void onCheckedChanged(SwitchButton view, boolean isChecked) { +// switch (view.getId()) { +// case R.id.switch_系统启停: +// ExecuteTheRecipe.Write("系统启停开关", isChecked); +// break; +// case R.id.switch_超温停气: +// ExecuteTheRecipe.Write("超温停气开关", isChecked); +// break; +// case R.id.switch_搅拌控制: +// if (isChecked) { +// ExecuteTheRecipe.BottomClickAsync("搅拌启动开关"); +// } else { +// ExecuteTheRecipe.BottomClickAsync("搅拌停止开关"); +// } +// break; +// case R.id.switch_抽油启停: +// ExecuteTheRecipe.Write("料仓1出料", isChecked); +// break; +// case R.id.switch_备用气缸: +// ExecuteTheRecipe.Write("料仓2出料", isChecked); +// break; +// case R.id.switch_点火控制: +// ExecuteTheRecipe.Write("点火启动开关", isChecked); +// break; +// case R.id.switch_小火: +// ExecuteTheRecipe.Write("小火开关(一圈)", isChecked); +// break; +// case R.id.switch_中火: +// ExecuteTheRecipe.Write("中火开关(二圈)", isChecked); +// break; +// case R.id.switch_大火: +// ExecuteTheRecipe.Write("大火开关(三圈)", isChecked); +// break; +// case R.id.switch_强火: +// ExecuteTheRecipe.Write("强火开关(四圈)", isChecked); +// break; +// } +// } +// }; + + /** * 开关事件处理 */ - public SwitchButton.OnCheckedChangeListener checkedChangeListener = new SwitchButton.OnCheckedChangeListener() { + public SwitchButton.OnTouchListener TouchListener = new SwitchButton.OnTouchListener() { @Override - public void onCheckedChanged(SwitchButton view, boolean isChecked) { - switch (view.getId()) { - case R.id.switch_系统启停: - ExecuteTheRecipe.WritePLC("系统启停开关", isChecked); - break; - case R.id.switch_超温停气: - ExecuteTheRecipe.WritePLC("超温停气开关", isChecked); - break; - case R.id.switch_搅拌控制: - if (isChecked) { - ExecuteTheRecipe.BottomClick("搅拌启动开关"); - } else { - ExecuteTheRecipe.BottomClick("搅拌停止开关"); - } - break; - case R.id.switch_抽油启停: - ExecuteTheRecipe.WritePLC("料仓1出料", isChecked); - break; - case R.id.switch_备用气缸: - ExecuteTheRecipe.WritePLC("料仓2出料", isChecked); - break; - case R.id.switch_点火控制: - ExecuteTheRecipe.WritePLC("点火启动开关", isChecked); - break; - - case R.id.switch_小火: - ExecuteTheRecipe.WritePLC("小火开关(一圈)", isChecked); - break; - case R.id.switch_中火: - ExecuteTheRecipe.WritePLC("中火开关(二圈)", isChecked); - break; - case R.id.switch_大火: - ExecuteTheRecipe.WritePLC("大火开关(三圈)", isChecked); - break; - case R.id.switch_强火: - ExecuteTheRecipe.WritePLC("强火开关(四圈)", isChecked); - break; - + public boolean onTouch(View view, MotionEvent motionEvent) { + if (motionEvent.getAction() == MotionEvent.ACTION_UP) { + switch (view.getId()) { + case R.id.switch_系统启停: + ExecuteTheRecipe.showlog("手动操作-系统启停开关,值:"+!switch_系统启停.isChecked()); + ExecuteTheRecipe.WriteAsync("系统启停开关", !switch_系统启停.isChecked()); + break; + case R.id.switch_超温停气: + ExecuteTheRecipe.showlog("手动操作-超温停气开关,值:"+!switch_超温停气.isChecked()); + ExecuteTheRecipe.WriteAsync("超温停气开关",!switch_超温停气.isChecked()); + break; + case R.id.switch_搅拌控制: + if (!switch_搅拌控制.isChecked()) { + ExecuteTheRecipe.showlog("手动启动搅拌"); + ExecuteTheRecipe.BottomClickAsync("搅拌启动开关"); + } else { + ExecuteTheRecipe.showlog("手动停止搅拌"); + ExecuteTheRecipe.BottomClickAsync("搅拌停止开关"); + } + break; + case R.id.switch_抽油启停: + ExecuteTheRecipe.showlog("手动操作-抽油启停开关,值:"+!switch_抽油启停.isChecked()); + ExecuteTheRecipe.WriteAsync("料仓1出料",!switch_抽油启停.isChecked()); + break; + case R.id.switch_备用气缸: + ExecuteTheRecipe.showlog("手动操作-备用气缸开关,值:"+!switch_备用气缸.isChecked()); + ExecuteTheRecipe.WriteAsync("料仓2出料",!switch_备用气缸.isChecked()); + break; + case R.id.switch_点火控制: + ExecuteTheRecipe.showlog("手动操作-点火启动开关,值:"+!switch_点火控制.isChecked()); + ExecuteTheRecipe.WriteAsync("点火启动开关",!switch_点火控制.isChecked()); + break; + case R.id.switch_小火: + ExecuteTheRecipe.showlog("手动操作-小火开关,值:"+!switch_小火.isChecked()); + ExecuteTheRecipe.WriteAsync("小火开关(一圈)", !switch_小火.isChecked()); + break; + case R.id.switch_中火: + ExecuteTheRecipe.showlog("手动操作-中火开关,值:"+!switch_中火.isChecked()); + ExecuteTheRecipe.WriteAsync("中火开关(二圈)", !switch_中火.isChecked()); + break; + case R.id.switch_大火: + ExecuteTheRecipe.showlog("手动操作-大火开关,值:"+!switch_大火.isChecked()); + ExecuteTheRecipe.WriteAsync("大火开关(三圈)", !switch_大火.isChecked()); + break; + case R.id.switch_强火: + ExecuteTheRecipe.showlog("手动操作-强火开关,值:"+!switch_强火.isChecked()); + ExecuteTheRecipe.WriteAsync("强火开关(四圈)", !switch_强火.isChecked()); + break; + } } + return false; } }; + public void InchingControl(View view,Boolean IsChick) + { + switch (view.getId()) { + case R.id.button_搅拌点动: + ExecuteTheRecipe.showlog("手动操作-搅拌点动开关,值:"+IsChick); + ExecuteTheRecipe.WriteAsync("搅拌点动开关", IsChick); + break; + case R.id.button_搅拌上升: + ExecuteTheRecipe.showlog("手动操作-搅拌上升开关,值:"+IsChick); + ExecuteTheRecipe.WriteAsync("搅拌上升", IsChick); + break; + case R.id.button_搅拌下降: + ExecuteTheRecipe.showlog("手动操作-搅拌下降开关,值:"+IsChick); + ExecuteTheRecipe.WriteAsync("搅拌下降", IsChick); + break; + case R.id.button_锅前倾: + ExecuteTheRecipe.showlog("手动操作-锅口向前开关,值:"+IsChick); + ExecuteTheRecipe.WriteAsync("锅口向前", IsChick); + break; + case R.id.button_锅后仰: + ExecuteTheRecipe.showlog("手动操作-锅口向后开关,值:"+IsChick); + ExecuteTheRecipe.WriteAsync("锅口向后", IsChick); + break; + } + } + public View.OnTouchListener touchListener = new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { boolean IsChick = false; if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { - Log.e("鼠标", "按下: "); - IsChick = true; + InchingControl(view,true); } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { - Log.e("鼠标", "松开: "); - IsChick = false; - } - - switch (view.getId()) { - case R.id.button_搅拌点动: - ExecuteTheRecipe.WritePLC("搅拌点动开关", IsChick); - break; + InchingControl(view,false); } return false; } @@ -392,7 +682,7 @@ public class MakeGoodFragment extends BaseFragment { }; } countDownTimer.start(); - ExecuteTheRecipe.IsStart = true; + ExecuteTheRecipe.IsStart.setValue(true); } } }); @@ -416,7 +706,9 @@ public class MakeGoodFragment extends BaseFragment { countDownTimer.stop(); countDownTimer = null; } - ExecuteTheRecipe.IsStart = false; + ExecuteTheRecipe.IsStart.setValue(false); + MessageLog.ShowInfo("复位启动状态"); + } } }); @@ -446,19 +738,35 @@ public class MakeGoodFragment extends BaseFragment { * @return */ public boolean IsMake(boolean k) { - if (!ConfigName.getInstance().PlcIsConnect) { - ToastUtils.warning("PLC未准备就绪!!!"); + + if(!CommHelper.get().IsConnected() && k){ + AlertDialogUtils.showDialog(context, "提示", "设备未连接,请先连接设备!"); return false; } - Object chushiover = ExecuteTheRecipe.getListingValue("监控_急停按钮"); - if (chushiover == null || (boolean) chushiover) { - ToastUtils.warning("设备停止,请先启动设备!!!"); + if (good == null) { + AlertDialogUtils.showDialog(context, "提示", "请先选择一个商品!"); return false; } - if (ExecuteTheRecipe.IsStart && k) { - ToastUtils.warning("客官,商品制作未结束请勿进行其他操作.请耐心等待商品制作结束!!!"); + if (!ExecuteTheRecipe.getDeviceData.PostPotLimit && k) { + AlertDialogUtils.showDialog(context, "提示", "请先将炒锅回到原位!"); + return false; + } + + if (!ExecuteTheRecipe.getDeviceData.MixingLowerLimit && k) { + AlertDialogUtils.showDialog(context, "提示", "请先将摆臂回到原位!"); + return false; + } + + if (!ExecuteTheRecipe.getDeviceData.EStop && k) { + AlertDialogUtils.showDialog(context, "提示", "设备急停中,请先检查设备后重试!"); + return false; + } + + if (ExecuteTheRecipe.IsStart.getValue() && k) { + AlertDialogUtils.showDialog(context, "提示", "商品制作中,请勿进行其它操作!"); +// ToastUtils.warning("客官,商品制作未结束请勿进行其他操作.请耐心等待商品制作结束!!!"); return false; } @@ -575,15 +883,20 @@ public class MakeGoodFragment extends BaseFragment { * @param val */ public void SetImageViewUrl(ImageView image, Object val, int index) { - if (val == null) { - image.setImageResource(R.mipmap.status_y); - } else { - if (index == 1) { - image.setImageResource((boolean) val ? R.mipmap.status_z : R.mipmap.status_y); - } else { - image.setImageResource((!(boolean) val) ? R.mipmap.status_z : R.mipmap.status_y); + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + if (val == null) { + image.setImageResource(R.mipmap.status_y); + } else { + if (index == 1) { + image.setImageResource((boolean) val ? R.mipmap.status_z : R.mipmap.status_y); + } else { + image.setImageResource((!(boolean) val) ? R.mipmap.status_z : R.mipmap.status_y); + } + } } - } + }); } //endregion @@ -603,6 +916,7 @@ public class MakeGoodFragment extends BaseFragment { * 初始化数据 */ public void InitStatusdata() { + //设备状态 sbzt.clear(); sbzt.add(new StatusMode("急停按钮", "监控_急停按钮", false, R.mipmap.status_y, R.mipmap.status_z, 0)); sbzt.add(new StatusMode("搅拌上限", "监控_搅拌上限", false, R.mipmap.status_y, R.mipmap.status_z, 0)); @@ -612,6 +926,7 @@ public class MakeGoodFragment extends BaseFragment { sbzt.add(new StatusMode("点火正常", "监控_点火正常", false, R.mipmap.status_y, R.mipmap.status_z, 0)); + //故障状态 gzzt.clear(); gzzt.add(new StatusMode("急停按下", "急停按下!", false, R.mipmap.status_y, R.mipmap.status_z, 0)); gzzt.add(new StatusMode("油泵故障", "油泵故障!", false, R.mipmap.status_y, R.mipmap.status_z, 0)); @@ -696,11 +1011,9 @@ public class MakeGoodFragment extends BaseFragment { public void run() { while (true) { try { - - if (ExecuteTheRecipe.IsStart && good != null) { + if (ExecuteTheRecipe.IsStart.getValue() && good != null) { long startTime = System.currentTimeMillis(); //起始时间 - ExecuteTheRecipe.showlog("--------------------------------------"); - ExecuteTheRecipe.showlog("开始烹饪菜谱【" + good.name + "】"); + ExecuteTheRecipe.showlog("开始执行任务:【" + good.name + "】"); ExecuteTheRecipe.HandTime = 0;//默认将手动操作时间复位 try { //获取工艺 @@ -711,6 +1024,7 @@ public class MakeGoodFragment extends BaseFragment { } } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); + MessageLog.ShowError("执行任务【"+good.name+"】出错,"+ex.toString()); } finally { int time = (int) ((System.currentTimeMillis() - startTime) / 1000);//使用总时间 ExecuteTheRecipe.showlog("结束烹饪菜谱【" + good.name + "】," + String.format("方法使用时间 %d s", time)); @@ -719,19 +1033,27 @@ public class MakeGoodFragment extends BaseFragment { int ztime = time - ExecuteTheRecipe.HandTime; good.maketime = ztime > 0 ? ztime : time; QueryDB.UpdateGoodsMakeTime(good.id, good.maketime); + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + AlertDialogUtils.showDialog(context, "提示", "菜谱【"+good.name+"】:已炒制完成,请出料后再继续!"); + } + }); } else { ExecuteTheRecipe.showlog("菜谱【" + good.name + "】已强制结束..."); } - onRecordStop(); + ExecuteTheRecipe.ForcedEndTask(); ExecuteTheRecipe.StopForcedEnd();//设置恢复强制结束 - ExecuteTheRecipe.showlog("--------------------------------------"); } } Thread.sleep(1000); } catch (InterruptedException e) { } + catch (Exception e) { + MessageLog.ShowError(e.getMessage()); + } } } }).start(); @@ -742,56 +1064,89 @@ public class MakeGoodFragment extends BaseFragment { public void run() { while (true) { try { - if (ConfigName.getInstance().PlcIsConnect) { - for (StatusMode mode : sbzt) { - Object obj = ExecuteTheRecipe.ReadPLC(mode.YName); - if (obj != null) { - mode.Status = (boolean) obj; - } - } - for (StatusMode mode : gzzt) { - Object obj = ExecuteTheRecipe.ReadPLC(mode.YName); - if (obj != null) { - mode.Status = (boolean) obj; - } - } +// if (ConfigName.getInstance().PlcIsConnect) { - //读取锅体重量 - Object zl = ExecuteTheRecipe.ReadPLC("炒锅当前重量"); - if (zl != null) { - PanWeight.setText(zl + ""); - main_weight.setText(zl + ""); + //设备状态更新 + for (StatusMode mode : sbzt) { + Object obj = ExecuteTheRecipe.ReadPLC(mode.YName); + if (obj != null) { + mode.Status = (boolean) obj; } + } - //读取温度 - Object temp = ExecuteTheRecipe.ReadPLC("炒锅当前温度"); - if (temp != null) { - main_temp.setText(temp + ""); - } + //故障状态更新 +// for (StatusMode mode : gzzt) { +// Object obj = ExecuteTheRecipe.ReadPLC(mode.YName); +// if (obj != null) { +// mode.Status = (boolean) obj; +// } +// } - SetImageViewUrl(image_搅拌上升, ExecuteTheRecipe.ReadPLC("监控_搅拌上限"), 1); - SetImageViewUrl(image_搅拌下降, ExecuteTheRecipe.ReadPLC("监控_搅拌下限"), 1); + //读取锅体重量 + activity.runOnUiThread(()->{ + main_weight.setText("重量:"+String.format("%.2f",ExecuteTheRecipe.getDeviceData.CurrentWeight) + "KG"); + PanWeight.setText(String.format("%.2f",ExecuteTheRecipe.getDeviceData.CurrentWeight) + "KG"); + }); +// Object zl = ExecuteTheRecipe.ReadPLC("炒锅当前重量"); +// if (zl != null) { +// activity.runOnUiThread(new Runnable() { +// @Override +// public void run() { +// main_weight.setText("重量:"+String.format("%.2f",zl) + "KG"); +// PanWeight.setText(String.format("%.2f",zl) + "KG"); +// } +// }); +// +// } - SetImageViewUrl(image_锅后仰, ExecuteTheRecipe.ReadPLC("监控_锅后限位"), 1); - SetImageViewUrl(image_锅前倾, ExecuteTheRecipe.ReadPLC("监控_锅后限位"), 0); - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - ReshData(); - } - }); - } + + + //读取温度 + activity.runOnUiThread(()->{ + main_temp.setText("温度:" + String.format("%.2f",ExecuteTheRecipe.getDeviceData.CurrentTemperature) + "°C"); + }); +// Object temp = ExecuteTheRecipe.ReadPLC("炒锅当前温度"); +// if (temp != null) { +// activity.runOnUiThread(new Runnable() { +// @Override +// public void run() { +// main_temp.setText("温度:" + String.format("%.2f",temp) + "°C"); +// } +// }); +// +// +// } + + + SetImageViewUrl(image_搅拌上升, ExecuteTheRecipe.getDeviceData.MixingUpperLimit, 1); + SetImageViewUrl(image_搅拌下降, ExecuteTheRecipe.getDeviceData.MixingLowerLimit, 1); + + SetImageViewUrl(image_锅后仰, ExecuteTheRecipe.getDeviceData.PostPotLimit, 1); + SetImageViewUrl(image_锅前倾,ExecuteTheRecipe.getDeviceData.PostPotLimit, 0); + +// SetImageViewUrl(image_搅拌上升, ExecuteTheRecipe.ReadPLC("监控_搅拌上限"), 1); +// SetImageViewUrl(image_搅拌下降, ExecuteTheRecipe.ReadPLC("监控_搅拌下限"), 1); +// +// SetImageViewUrl(image_锅后仰, ExecuteTheRecipe.ReadPLC("监控_锅后限位"), 1); +// SetImageViewUrl(image_锅前倾, ExecuteTheRecipe.ReadPLC("监控_锅后限位"), 0); + + activity.runOnUiThread(()->{ ReshData();}); +// } Thread.sleep(1000); } catch (InterruptedException e) { ToastUtils.info("异常信息:" + e.getMessage()); } + catch (Exception e) { + MessageLog.ShowError(e.getMessage()); + } } } }).start(); + //初始化读取PLC数据 @@ -834,11 +1189,19 @@ public class MakeGoodFragment extends BaseFragment { @BindView(R.id.switch_备用气缸) SwitchButton switch_备用气缸; - @BindView(R.id.editsp_物料) - Spinner editsp_物料; +// @BindView(R.id.editsp_物料) +// Spinner editsp_物料; - @BindView(R.id.editsp_点火模式) - Spinner editsp_点火模式; +// @BindView(R.id.editsp_点火模式) +// Spinner editsp_点火模式; + + //点火模式:手动 + @BindView(R.id.RB_Hand) + RadioButton RB_Hand; + + //点火模式:自动 + @BindView(R.id.RB_Auto) + RadioButton RB_Auto; @BindView(R.id.switch_点火控制) SwitchButton switch_点火控制; @@ -847,6 +1210,18 @@ public class MakeGoodFragment extends BaseFragment { @BindView(R.id.button_搅拌点动) Button button_搅拌点动;//button_搅拌点动 + @BindView(R.id.button_搅拌上升) + Button button_搅拌上升;// + + @BindView(R.id.button_搅拌下降) + Button button_搅拌下降;// + + @BindView(R.id.button_锅前倾) + Button button_锅前倾;// + + @BindView(R.id.button_锅后仰) + Button button_锅后仰;// + @BindView(R.id.image_搅拌上升) ImageView image_搅拌上升; @@ -872,39 +1247,67 @@ public class MakeGoodFragment extends BaseFragment { * 初始化弹框中的事件 */ public void Init_弹窗_事件() { - switch_系统启停.setOnCheckedChangeListener(checkedChangeListener); - switch_超温停气.setOnCheckedChangeListener(checkedChangeListener); - switch_搅拌控制.setOnCheckedChangeListener(checkedChangeListener); - switch_抽油启停.setOnCheckedChangeListener(checkedChangeListener); - switch_备用气缸.setOnCheckedChangeListener(checkedChangeListener); - - switch_点火控制.setOnCheckedChangeListener(checkedChangeListener); - - switch_小火.setOnCheckedChangeListener(checkedChangeListener); - switch_中火.setOnCheckedChangeListener(checkedChangeListener); - switch_大火.setOnCheckedChangeListener(checkedChangeListener); - switch_强火.setOnCheckedChangeListener(checkedChangeListener); - - editsp_点火模式.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView adapterView, View view, int i, long l) { - String name = editsp_点火模式.getSelectedItem().toString(); - if (name.equals("手动")) { - ExecuteTheRecipe.WritePLC("点火手自动切换开关", true); - } else { - ExecuteTheRecipe.WritePLC("点火手自动切换开关", false); - } - } - - @Override - public void onNothingSelected(AdapterView adapterView) { - - } - }); + switch_系统启停.setOnTouchListener(TouchListener); + switch_超温停气.setOnTouchListener(TouchListener); + switch_搅拌控制.setOnTouchListener(TouchListener); + switch_抽油启停.setOnTouchListener(TouchListener); + switch_备用气缸.setOnTouchListener(TouchListener); + switch_点火控制.setOnTouchListener(TouchListener); + switch_小火.setOnTouchListener(TouchListener); + switch_中火.setOnTouchListener(TouchListener); + switch_大火.setOnTouchListener(TouchListener); + switch_强火.setOnTouchListener(TouchListener); + + +// switch_系统启停.setOnCheckedChangeListener(checkedChangeListener); +// switch_超温停气.setOnCheckedChangeListener(checkedChangeListener); +// switch_搅拌控制.setOnCheckedChangeListener(checkedChangeListener); +// +// switch_抽油启停.setOnCheckedChangeListener(checkedChangeListener); +// switch_备用气缸.setOnCheckedChangeListener(checkedChangeListener); +// +// switch_点火控制.setOnCheckedChangeListener(checkedChangeListener); +// +// switch_小火.setOnCheckedChangeListener(checkedChangeListener); +// switch_中火.setOnCheckedChangeListener(checkedChangeListener); +// switch_大火.setOnCheckedChangeListener(checkedChangeListener); +// switch_强火.setOnCheckedChangeListener(checkedChangeListener); + + + RB_Hand.setOnClickListener((s)->{ + ExecuteTheRecipe.showlog("手动切换为 手动点火"); + ExecuteTheRecipe.WriteAsync("点火手自动切换开关", true); + });//手动点火模式 + RB_Auto.setOnClickListener((s)->{ + ExecuteTheRecipe.showlog("手动切换为 自动点火"); + ExecuteTheRecipe.WriteAsync("点火手自动切换开关", false); + });//自动点火模式 + +// editsp_点火模式.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { +// @Override +// public void onItemSelected(AdapterView adapterView, View view, int i, long l) { +// String name = editsp_点火模式.getSelectedItem().toString(); +// if (name.equals("手动")) { +// ExecuteTheRecipe.WriteAsync("点火手自动切换开关", true); +// } else { +// ExecuteTheRecipe.WriteAsync("点火手自动切换开关", false); +// } +// } +// +// @Override +// public void onNothingSelected(AdapterView adapterView) { +// +// } +// }); button_搅拌点动.setOnTouchListener(touchListener); + button_搅拌上升.setOnTouchListener(touchListener); + button_搅拌下降.setOnTouchListener(touchListener); + button_锅前倾.setOnTouchListener(touchListener); + button_锅后仰.setOnTouchListener(touchListener); + } @@ -930,12 +1333,12 @@ public class MakeGoodFragment extends BaseFragment { materials.add(item); names.add(item.name); } - SetAdapter(editsp_物料, names); +// SetAdapter(editsp_物料, names); - List ms = new ArrayList<>(); - ms.add("手动"); - ms.add("自动"); - SetAdapter(editsp_点火模式, ms); +// List ms = new ArrayList<>(); +// ms.add("手动"); +// ms.add("自动"); +// SetAdapter(editsp_点火模式, ms); } @@ -973,30 +1376,36 @@ public class MakeGoodFragment extends BaseFragment { * 初始化火力 */ public void Init_火力() { - slider_小火.setOnValueChangeListener(new NiftySlider.OnValueChangeListener() { - @Override - public void onValueChange(@NonNull NiftySlider niftySlider, float v, boolean b) { - slider_小火.setThumbText((int) v + ""); - } - }); - slider_中火.setOnValueChangeListener(new NiftySlider.OnValueChangeListener() { - @Override - public void onValueChange(@NonNull NiftySlider niftySlider, float v, boolean b) { - slider_中火.setThumbText((int) v + ""); - } - }); - slider_大火.setOnValueChangeListener(new NiftySlider.OnValueChangeListener() { - @Override - public void onValueChange(@NonNull NiftySlider niftySlider, float v, boolean b) { - slider_大火.setThumbText((int) v + ""); - } - }); - slider_强火.setOnValueChangeListener(new NiftySlider.OnValueChangeListener() { - @Override - public void onValueChange(@NonNull NiftySlider niftySlider, float v, boolean b) { - slider_强火.setThumbText((int) v + ""); - } - }); + + slider_小火.setOnValueChangeListener((n,v,b)->{slider_小火.setThumbText((int) v + "");}); + slider_中火.setOnValueChangeListener((n,v,b)->{slider_中火.setThumbText((int) v + "");}); + slider_大火.setOnValueChangeListener((n,v,b)->{slider_大火.setThumbText((int) v + "");}); + slider_强火.setOnValueChangeListener((n,v,b)->{slider_强火.setThumbText((int) v + "");}); + +// slider_小火.setOnValueChangeListener(new NiftySlider.OnValueChangeListener() { +// @Override +// public void onValueChange(@NonNull NiftySlider niftySlider, float v, boolean b) { +// slider_小火.setThumbText((int) v + ""); +// } +// }); +// slider_中火.setOnValueChangeListener(new NiftySlider.OnValueChangeListener() { +// @Override +// public void onValueChange(@NonNull NiftySlider niftySlider, float v, boolean b) { +// slider_中火.setThumbText((int) v + ""); +// } +// }); +// slider_大火.setOnValueChangeListener(new NiftySlider.OnValueChangeListener() { +// @Override +// public void onValueChange(@NonNull NiftySlider niftySlider, float v, boolean b) { +// slider_大火.setThumbText((int) v + ""); +// } +// }); +// slider_强火.setOnValueChangeListener(new NiftySlider.OnValueChangeListener() { +// @Override +// public void onValueChange(@NonNull NiftySlider niftySlider, float v, boolean b) { +// slider_强火.setThumbText((int) v + ""); +// } +// }); slider_小火.setOnSliderTouchListener(new NiftySlider.OnSliderTouchListener() { @@ -1008,7 +1417,8 @@ public class MakeGoodFragment extends BaseFragment { @Override public void onStopTrackingTouch(@NonNull NiftySlider niftySlider) { int temp = (int) slider_小火.getValue(); - ExecuteTheRecipe.WritePLC("小火比例阀开度", temp); + ExecuteTheRecipe.showlog("手动设置-小火比例值:"+temp); + ExecuteTheRecipe.WriteAsync("小火比例阀开度", temp); ToastUtils.info("小火比例阀开度:" + temp); } }); @@ -1022,7 +1432,8 @@ public class MakeGoodFragment extends BaseFragment { @Override public void onStopTrackingTouch(@NonNull NiftySlider niftySlider) { int temp = (int) slider_中火.getValue(); - ExecuteTheRecipe.WritePLC("中火比例阀开度", temp); + ExecuteTheRecipe.showlog("手动设置-中火比例值:"+temp); + ExecuteTheRecipe.WriteAsync("中火比例阀开度", temp); ToastUtils.info("中火比例阀开度:" + temp); } }); @@ -1036,7 +1447,8 @@ public class MakeGoodFragment extends BaseFragment { @Override public void onStopTrackingTouch(@NonNull NiftySlider niftySlider) { int temp = (int) slider_大火.getValue(); - ExecuteTheRecipe.WritePLC("大火比例阀开度", temp); + ExecuteTheRecipe.showlog("手动设置-大火比例值:"+temp); + ExecuteTheRecipe.WriteAsync("大火比例阀开度", temp); ToastUtils.info("大火比例阀开度:" + temp); } }); @@ -1050,7 +1462,8 @@ public class MakeGoodFragment extends BaseFragment { @Override public void onStopTrackingTouch(@NonNull NiftySlider niftySlider) { int temp = (int) slider_强火.getValue(); - ExecuteTheRecipe.WritePLC("强火比例阀开度", temp); + ExecuteTheRecipe.showlog("手动设置-强火比例值:"+temp); + ExecuteTheRecipe.WriteAsync("强火比例阀开度", temp); ToastUtils.info("强火比例阀开度:" + temp); } }); diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc_control.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc_control.java index cae57a2b..4137c2f8 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc_control.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc_control.java @@ -2,16 +2,13 @@ package com.bonait.bnframework.modules.home.fragment.mode; import android.content.Context; import android.os.Handler; -import android.text.InputType; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; -import android.widget.CheckBox; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.RelativeLayout; -import android.widget.Switch; import android.widget.TextView; import androidx.annotation.Nullable; @@ -19,16 +16,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.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; -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; import com.suke.widget.SwitchButton; -import java.util.HashMap; - import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; @@ -188,7 +179,7 @@ public class fragment_plc_control extends LinearLayout { @Override public void onCheckedChanged(SwitchButton view, boolean isChecked) { boolean ischick= control_switch.isChecked(); - ExecuteTheRecipe.WritePLC(model.name,ischick); + ExecuteTheRecipe.Write(model.name,ischick); ToastUtils.info("写入地址:"+model.address+"成功!状态:"+(ischick?"打开":"关闭")); } }); @@ -199,11 +190,11 @@ public class fragment_plc_control extends LinearLayout { control_botton.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { - ExecuteTheRecipe.WritePLC(model.name,true); + ExecuteTheRecipe.Write(model.name,true); new Handler().postDelayed(new Runnable() { @Override public void run() { - ExecuteTheRecipe.WritePLC(model.name, false); + ExecuteTheRecipe.Write(model.name, false); } }, 500); @@ -223,7 +214,7 @@ public class fragment_plc_control extends LinearLayout { return; } int val=Integer.parseInt(text); - ExecuteTheRecipe.WritePLC(model.name,val); + ExecuteTheRecipe.Write(model.name,val); ToastUtils.info("写入地址:"+model.address+"成功!"); break; diff --git a/app/src/main/res/drawable/input_bj.xml b/app/src/main/res/drawable/input_bj.xml index b77ec622..6c2bbdbf 100644 --- a/app/src/main/res/drawable/input_bj.xml +++ b/app/src/main/res/drawable/input_bj.xml @@ -4,9 +4,9 @@ + android:left="0dp" + android:right="0dp" + android:top="0dp"> + android:textSize="12sp" /> @@ -110,8 +113,9 @@ android:inputType="number" android:maxLines="1" android:padding="3dp" + tools:ignore="TouchTargetSizeCheck" android:text="0" - android:textSize="12dp" /> + android:textSize="12sp" /> @@ -158,6 +163,7 @@