From 03d8b853f006b23ecd613e61097ae3f056170df6 Mon Sep 17 00:00:00 2001 From: liup <1454939542@qq.com> Date: Sat, 6 Jul 2024 11:20:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HBL/Communication/Modbus/ModbusMaster.java | 8 +++++++- .../ui/activity/RecProcessActivity.java | 4 ++++ .../ui/fragment/HomeDevicesFragment.java | 4 ++++ .../layout/dialog/layout/layout_stir_control.xml | 14 ++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ModbusMaster.java b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ModbusMaster.java index 61a4ee7e..ad933eab 100644 --- a/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ModbusMaster.java +++ b/app/src/main/java/com/bonait/bnframework/HBL/Communication/Modbus/ModbusMaster.java @@ -280,7 +280,6 @@ public class ModbusMaster implements IRead,IWrite ,IModbusMaster{ new ExceptionServer(address, length, new IExceptionHandling() { @Override public void onSuccess(int add) throws InterruptedException, ExecutionException, ModbusTransportException, ModbusInitException, ModbusRespException { - IsConnected = true; ReadCoilsResponse res = mw.syncReadCoil(SlaveId, add, length); boolean[] data = res.getBooleanData(); boolean[] result = Arrays.copyOfRange(data, 0, length); @@ -288,6 +287,7 @@ public class ModbusMaster implements IRead,IWrite ,IModbusMaster{ LogUtils.d(TAG+"ReadBool address="+address+" 读操作 成功:data="+data.toString()+" bytes="+result); } resultValue.set(OperateResultT.CreateSuccess(result)); + IsConnected = true; } @Override @@ -329,6 +329,7 @@ public class ModbusMaster implements IRead,IWrite ,IModbusMaster{ boolean[] data = res.getBooleanData(); boolean[] result = Arrays.copyOfRange(data, 0, length); resultValue.set(OperateResultT.CreateSuccess(result)); + IsConnected = true; } @Override @@ -370,6 +371,7 @@ public class ModbusMaster implements IRead,IWrite ,IModbusMaster{ } if (data.length == length) { resultValue.set(OperateResultT.CreateSuccess(data)); + IsConnected = true; } } @@ -409,6 +411,7 @@ public class ModbusMaster implements IRead,IWrite ,IModbusMaster{ int[] tempValues= IntLib.ToInts(res.getData(),ReadDataFormat); if(tempValues.length==length){ resultValue.set(OperateResultT.CreateSuccess(tempValues)); + IsConnected = true; }else{ resultValue.set(OperateResultT.CreateFailedT(address+",读取失败,返回长度和实际读取长度不匹配")); } @@ -458,6 +461,7 @@ public class ModbusMaster implements IRead,IWrite ,IModbusMaster{ if(data.length==tempLength){ byte[] result = Arrays.copyOfRange(data, 0, length); resultValue.set(OperateResultT.CreateSuccess(result)); + IsConnected = true; }else{ resultValue.set(OperateResultT.CreateFailedT(address+",读取失败,返回长度和实际读取长度不匹配")); } @@ -485,6 +489,7 @@ public class ModbusMaster implements IRead,IWrite ,IModbusMaster{ try { if (data.length ==length*2) { resultValue.set(OperateResultT.CreateSuccess(new String(data, "UTF-8").trim())); + IsConnected = true; } } catch (UnsupportedEncodingException ex) { resultValue.set(OperateResultT.CreateFailedT(address+",读取失败,字符串解析失败:"+ex.toString())); @@ -512,6 +517,7 @@ public class ModbusMaster implements IRead,IWrite ,IModbusMaster{ float[] tempValues = FloatLib.ToFloats(res.getData(),ReadDataFormat); if (tempValues.length == length) { resultValue.set(OperateResultT.CreateSuccess(tempValues)); + IsConnected = true; }else{ resultValue.set(OperateResultT.CreateFailedT(address+",读取失败,返回长度和实际读取长度不匹配")); } diff --git a/app/src/main/java/com/bonait/bnframework/ui/activity/RecProcessActivity.java b/app/src/main/java/com/bonait/bnframework/ui/activity/RecProcessActivity.java index 321d0005..57b7963a 100644 --- a/app/src/main/java/com/bonait/bnframework/ui/activity/RecProcessActivity.java +++ b/app/src/main/java/com/bonait/bnframework/ui/activity/RecProcessActivity.java @@ -359,6 +359,10 @@ public class RecProcessActivity extends BaseActivity { break; case "打散搅拌": + if(isUp){ + NewToastUtil.getInstance().showToast("上升状态无法启动搅拌"); + return; + } isScatterStir = true; viewBinding.device.btnStir.setBackgroundResource(R.drawable.bg_btn_run_anim_looper); ((AnimationDrawable)viewBinding.device.btnStir.getBackground()).start(); diff --git a/app/src/main/java/com/bonait/bnframework/ui/fragment/HomeDevicesFragment.java b/app/src/main/java/com/bonait/bnframework/ui/fragment/HomeDevicesFragment.java index c6f2f83b..0101040b 100644 --- a/app/src/main/java/com/bonait/bnframework/ui/fragment/HomeDevicesFragment.java +++ b/app/src/main/java/com/bonait/bnframework/ui/fragment/HomeDevicesFragment.java @@ -242,6 +242,10 @@ public class HomeDevicesFragment extends BaseFragment { break; case "打散搅拌": + if(isUp){ + NewToastUtil.getInstance().showToast("上升状态无法启动搅拌"); + return; + } isScatterStir = true; viewBinding.device.btnStir.setBackgroundResource(R.drawable.bg_btn_run_anim_looper); ((AnimationDrawable)viewBinding.device.btnStir.getBackground()).start(); diff --git a/app/src/main/res/layout/dialog/layout/layout_stir_control.xml b/app/src/main/res/layout/dialog/layout/layout_stir_control.xml index 2bc44ab2..5218eecb 100644 --- a/app/src/main/res/layout/dialog/layout/layout_stir_control.xml +++ b/app/src/main/res/layout/dialog/layout/layout_stir_control.xml @@ -18,6 +18,20 @@ android:paddingLeft="@dimen/dp_20" /> + +