From d549d8f7ae505ab54d982e2a611b3fe4e1d9fafd Mon Sep 17 00:00:00 2001 From: Nah <15196688790@163.com> Date: Mon, 4 Dec 2023 14:14:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=B1=E6=96=99=E6=A0=A1?= =?UTF-8?q?=E5=87=86=E5=92=8C=E6=A8=A1=E6=8B=9F=E5=87=BA=E6=96=99=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=EF=BC=8C=E9=80=82=E9=85=8D=E9=85=8D=E6=96=99=E5=90=A7?= =?UTF-8?q?=E5=8F=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/ExecuteTheRecipe.java | 40 +- .../business/deviceControl/DeviceManager.java | 20 - .../business/deviceControl/PLCControl.java | 436 ++++++++++++ .../{seasonBar => }/ScaleDevice.java | 3 +- .../deviceControl/seasonBar/PLCControl.java | 229 ------- .../common/constant/ConfigName.java | 66 +- .../bnframework/common/constant/DataBus.java | 36 +- .../common/modbus/ModbusRTUServer.java | 632 ------------------ .../BottomNavigationMainActivity.java | 15 +- .../modules/home/adapter/wdsz_adapter.java | 7 +- .../home/fragment/MakeGoodFragment.java | 34 +- .../home/fragment/from/DzcjyActivity.java | 2 +- .../home/fragment/from/RealTimeActivity.java | 89 ++- .../from/SystemParameterActivity.java | 103 ++- .../mode/Silos_item_jiaoyan_fragment.java | 4 +- .../home/fragment/mode/add_silos_ck.java | 25 +- .../fragment/mode/fragment_plc_control.java | 22 +- .../home/fragment/mode/silos_jiaoyan.java | 121 +++- .../res/layout/activity_systemparameter.xml | 9 +- .../main/res/layout/fragment_make_good.xml | 14 + app/src/main/res/layout/fragment_she_zhi.xml | 2 +- .../layout/item/layout/silos_jiaoyan_item.xml | 27 +- 22 files changed, 824 insertions(+), 1112 deletions(-) delete mode 100644 app/src/main/java/com/bonait/bnframework/business/deviceControl/DeviceManager.java create mode 100644 app/src/main/java/com/bonait/bnframework/business/deviceControl/PLCControl.java rename app/src/main/java/com/bonait/bnframework/business/deviceControl/{seasonBar => }/ScaleDevice.java (96%) delete mode 100644 app/src/main/java/com/bonait/bnframework/business/deviceControl/seasonBar/PLCControl.java delete mode 100644 app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java 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 8a013d66..c6cb7a03 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java +++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java @@ -5,8 +5,8 @@ import android.os.Looper; import androidx.annotation.NonNull; -import com.bonait.bnframework.business.deviceControl.seasonBar.PLCControl; -import com.bonait.bnframework.business.deviceControl.seasonBar.ScaleDevice; +import com.bonait.bnframework.business.deviceControl.PLCControl; +import com.bonait.bnframework.business.deviceControl.ScaleDevice; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.db.QueryDB; @@ -272,8 +272,10 @@ public class ExecuteTheRecipe { try { if(!IsMakeGood) { - Object zl= ExecuteTheRecipe.ReadPLC("称当前重量"); - OutletWeigh=zl==null?0:(int)zl; +// Object zl= ExecuteTheRecipe.ReadPLC("称当前重量"); +// OutletWeigh=zl==null?0:(int)zl; + OutletWeigh=ScaleDevice.get().getCurrentWeight(); + Object bz= ExecuteTheRecipe.ReadPLC("出料口检测"); IsCup=bz==null?false:(boolean) bz; Object obj1= ExecuteTheRecipe.ReadPLC("水池温度"); @@ -553,6 +555,7 @@ public class ExecuteTheRecipe { * @param value */ public static void WritePLC(String name, Object value, IWriteCallBack callback) { + try { if (ConfigName.getInstance().PLC_Address.containsKey(name)) { BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); @@ -791,9 +794,22 @@ public class ExecuteTheRecipe { */ public static void ReadPLCStatus() { try { - if (ConfigName.getInstance().PLC_Address.containsKey("实时状态")) { - BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get("实时状态"); - if (!plcaddress.address.isEmpty() && ConfigName.getInstance().PlcIsConnect) { + boolean[] states; + switch (ConfigName.getInstance().versionSelectionEnum){ + case "调味吧台": + states=PLCControl.get().getAllMotorState(); + if (states!=null && states.length==24){ + for (int i=0;i< states.length;i++){ + IoStatus.put(i,states[i]); + } + } + break; + default: + break; + } +// if (ConfigName.getInstance().PLC_Address.containsKey("实时状态")) { +// BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get("实时状态"); +// if (!plcaddress.address.isEmpty() && ConfigName.getInstance().PlcIsConnect) { // ModbusClient.get().ReadStatus(plcaddress.address, 4, (data) -> { // for (int i = 0; i < data.length; i++) { // byte status=data[i];//0x92 @@ -807,11 +823,12 @@ public class ExecuteTheRecipe { // IoStatus.put(i*8+7, ByteHelper.getBit(status,7)==1); // } // }); - } - } +// } +// } + + } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); - } finally { } } @@ -1119,7 +1136,7 @@ public class ExecuteTheRecipe { final double maxWeight=Double.parseDouble(silo.maxweight); final double minWeight=Double.parseDouble(silo.minweight); final double[] coefficients=stringToDoubleArray(silo.bcsfValue); - if (weight<=minWeight || weight>=maxWeight){ + if (weightmaxWeight){ return 0; } @@ -1128,7 +1145,6 @@ public class ExecuteTheRecipe { for (int i=0;i TDataType readPLC(String address,Class dataType, IReadCallBack callBack) { + if (Boolean.class.equals(dataType)) { + + return dataType.cast(true); + } else if (Short.class.equals(dataType)) { + + + return dataType.cast((short) 0); + } else if (Integer.class.equals(dataType)) { + + + return dataType.cast(0); + } else if (Float.class.equals(dataType)) { + + return dataType.cast(0.0f); + } else { + // 其他类型的处理逻辑 + return null; // 默认返回 null + } + } + + + public void writePLC(String address,TDataType value, IWriteCallBack callBack) { + + if (ModbusMaster.get().IsConnected && ConfigName.PLC_Address.containsKey(address)){ + String addr=ConfigName.PLC_Address.get(address).address; + if (!addr.isEmpty()&&getModAddr(addr)!=-1){ + try{ + String startAddr=String.valueOf(getModAddr(addr)); + //String startAddr=address; + if (value instanceof Boolean){ + ModbusMaster.get().WriteBool(startAddr,(boolean)value,slaveId,callBack); + } else if (value instanceof boolean[]) { + ModbusMaster.get().WriteBool(startAddr,(boolean[])value,slaveId,callBack); + } else if (value instanceof Integer) { + ModbusMaster.get().WriteInt(startAddr,(int) value,slaveId,callBack); + }else if (value instanceof int[]) { + ModbusMaster.get().WriteInt(startAddr,(int[]) value,slaveId,callBack); + }else if (value instanceof Short) { + ModbusMaster.get().WriteShort(startAddr,(short) value,slaveId,callBack); + }else if (value instanceof short[]) { + ModbusMaster.get().WriteShort(startAddr,(short[])value,slaveId,callBack ); + }else if (value instanceof Float) { + ModbusMaster.get().WriteFloat(startAddr,(float)value,slaveId,callBack ); + }else if (value instanceof Float[]) { + ModbusMaster.get().WriteFloat(startAddr,(float[]) value,slaveId,callBack ); + } + }catch (Exception ex){ + ToastUtils.error("Write PLC error:"+ex.getMessage()); + } + + } + } + } + + + public int getCleanTemp(){ + final short[] temp=new short[]{0}; + if (ModbusMaster.get().IsConnected && ConfigName.PLC_Address.containsKey("清洗温度")){ + String addr=ConfigName.PLC_Address.get("清洗温度").address; + if (!addr.isEmpty()&& getModAddr(addr)!=-1){ + try{ + String startAddr=String.valueOf(getModAddr(addr)); + ModbusMaster.get().ReadShort(startAddr,1,slaveId,val->{ + temp[0]=val[0]; + }); + }catch (Exception ex){ + ToastUtils.error("Write PLC error:"+ex.getMessage()); + } + } + } + return (int)temp[0]; + } + + public boolean[] getAllMotorState(){ + final int readLength=24; + boolean[] states=new boolean[readLength]; + if (ModbusMaster.get().IsConnected){ + int startAddr=getModAddr("D1"); + if (startAddr!=-1){ + ModbusMaster.get() + .ReadShort(String.valueOf(startAddr),readLength,slaveId,val->{ + if (val.length==readLength){ + for (int i=0;i0?true:false; + } + } + }); + } + + } + + return states; + } + /**适用于普通仓 + * @param index 仓位编号。 + * @param delayTime 开启时间。 + * */ + public void openMotorAndClose(int index, int delayTime, IWriteCallBack callBack) { + try { + openMotor(index, new IWriteCallBack() { + @Override + public void onSuccess() { + new Handler(Looper.getMainLooper()).postDelayed(()->{ + closeMotor(index, new IWriteCallBack() { + @Override + public void onSuccess() { + if (callBack != null){ + callBack.onSuccess(); + } + } + + @Override + public void onFailure(String ErrorMsg) { + if (callBack!=null){ + callBack.onFailure(ErrorMsg); + } + } + }); + },delayTime); + } + @Override + public void onFailure(String ErrorMsg) { + if (callBack != null) { + callBack.onFailure(ErrorMsg); + } + } + }); + } catch (Exception ex) { + ToastUtils.error("OpenMotorAndClose Exception:" + ex.getMessage()); + } + } + + /**适用于带有反转回收功能的仓 + * @param index 仓位编号。 + * @param delayTime 开启时间。单位为ms。 + * @param reverseTime 反转时间。单位为ms。 + * */ + public void openMotorAndReverse(int index, int delayTime,int reverseTime, IWriteCallBack callBack) { + try { + openMotor(index, new IWriteCallBack() { + @Override + public void onSuccess() { + new Handler(Looper.getMainLooper()).postDelayed(()->{ + closeMotor(index, new IWriteCallBack() { + @Override + public void onSuccess() { + reverseMotor(index, new IWriteCallBack() { + @Override + public void onSuccess() { + new Handler(Looper.getMainLooper()).postDelayed(()->{ + stopRverseMotor(index, new IWriteCallBack() { + @Override + public void onSuccess() { + if (callBack!=null){ + callBack.onSuccess(); + } + } + + @Override + public void onFailure(String ErrorMsg) { + if (callBack!=null){ + callBack.onFailure(ErrorMsg); + } + } + }); + },reverseTime); + } + + @Override + public void onFailure(String ErrorMsg) { + if (callBack!=null){ + callBack.onFailure(ErrorMsg); + } + } + }); + } + + @Override + public void onFailure(String ErrorMsg) { + if (callBack!=null){ + callBack.onFailure(ErrorMsg); + } + } + }); + },delayTime); + } + @Override + public void onFailure(String ErrorMsg) { + if (callBack!=null){ + callBack.onFailure(ErrorMsg); + } + } + }); + } catch (Exception ex) { + ToastUtils.error("OpenMotorAndReverse Exception:" + ex.getMessage()); + } + } + + /**反转后自动停止 + * @param index 通道序号 + * @param reverseTime 反转时间 + */ + public void reverMotorAndClose(int index,int reverseTime,IWriteCallBack callBack){ + try { + reverseMotor(index, new IWriteCallBack() { + @Override + public void onSuccess() { + new Handler(Looper.getMainLooper()).postDelayed(()->{ + stopRverseMotor(index, new IWriteCallBack() { + @Override + public void onSuccess() { + if (callBack!=null){ + callBack.onSuccess(); + } + } + + @Override + public void onFailure(String ErrorMsg) { + if (callBack!=null){ + callBack.onFailure(ErrorMsg); + } + } + }); + },reverseTime); + } + @Override + public void onFailure(String ErrorMsg) { + if (callBack!=null){ + callBack.onFailure(ErrorMsg); + } + } + }); + } catch (Exception ex) { + ToastUtils.error("ReverMotorAndClose Exception:" + ex.getMessage()); + } + } + + public void openMotor(int index, IWriteCallBack callBack) { + String name="通道"+index+"开关"; + try { + if (ConfigName.getInstance().PLC_Address.containsKey(name)) { + BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); + if (!plcaddress.address.isEmpty() && ModbusMaster.get().IsConnected) { + int startAddr = getModAddr(plcaddress.address); + if (startAddr!=-1){ + ModbusMaster.get().WriteShort(String.valueOf(startAddr),(short)1,slaveId,callBack); + } + } + } + } catch (Exception ex) { + ToastUtils.error("OpenMotor Exception:" + ex.getMessage()); + } + } + + public void reverseMotor(int index,IWriteCallBack callBack){ + String name="通道"+index+"反转"; + try { + if (ConfigName.getInstance().PLC_Address.containsKey(name)) { + BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); + if (!plcaddress.address.isEmpty() && ModbusMaster.get().IsConnected) { + int startAddr = getModAddr(plcaddress.address); + if (startAddr!=-1){ + ModbusMaster.get().WriteShort(String.valueOf(startAddr),(short)1,slaveId,callBack); + } + } + } + } catch (Exception ex) { + ToastUtils.error("OpenMotor Exception:" + ex.getMessage()); + } + } + + public void stopRverseMotor(int index,IWriteCallBack callBack){ + String name="通道"+index+"反转"; + try { + if (ConfigName.getInstance().PLC_Address.containsKey(name)) { + BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); + if (!plcaddress.address.isEmpty() && ModbusMaster.get().IsConnected) { + int startAddr = getModAddr(plcaddress.address); + if (startAddr!=-1){ + ModbusMaster.get().WriteShort(String.valueOf(startAddr),(short)0,slaveId,callBack); + } + } + } + } catch (Exception ex) { + ToastUtils.error("OpenMotor Exception:" + ex.getMessage()); + } + } + + public void closeMotor(int index, IWriteCallBack callBack) { + String name="通道"+index+"开关"; + try { + if (ConfigName.getInstance().PLC_Address.containsKey(name)) { + BPA_PLCADDRESS plcaddress = ConfigName.getInstance().PLC_Address.get(name); + if (!plcaddress.address.isEmpty() && ModbusMaster.get().IsConnected) { + int startAddr = getModAddr(plcaddress.address); + if (startAddr!=-1){ + ModbusMaster.get().WriteShort(String.valueOf(startAddr),(short)0,slaveId,callBack); + } + } + } + } catch (Exception ex) { + ToastUtils.error("OpenMotor Exception:" + ex.getMessage()); + } + } + + + /**适用于普通仓(打开后即可关闭,不需要反转)。 + * @param name 仓位名称 + * @param delayTime 打开时间 + * */ + public void openMotorAndClose(String name, int delayTime, IWriteCallBack callBack) { + + } + + /**打开电机并反转,最后关闭 + * @param name 仓位名称。 + * @param delayTime 开启时间。 + * @param reverseTime 反转时间。 + * */ + public void openAndReverse(String name,int delayTime,int reverseTime,IWriteCallBack callBack){ + + } + + public void openMotor(String name, IWriteCallBack callBack) { + writePLC(name,true,callBack); + } + public void reverseMotor(String name, IWriteCallBack callBack) { + writePLC(name,false,callBack); + } + + public void closeMotor(String name, IWriteCallBack callBack) { + + } + + + public void clrHeartbeat(IWriteCallBack callBack) { + writePLC("心跳时间",(short)0,callBack); + } + + + public boolean isTimeOut() { + final boolean[] result = {true}; + if (ModbusMaster.get().IsConnected && ConfigName.PLC_Address.containsKey("断线标志")) { + String addr = ConfigName.PLC_Address.get("断线标志").address; + try { + int startAddr=getModAddr(addr); + if (!addr.isEmpty()&& startAddr!= -1) { + ModbusMaster.get().ReadBool(String.valueOf(startAddr), 1, slaveId, val->{ + result[0]=val[0]; + }); + } + } catch (Exception ex) { + ToastUtils.error("Exception message:" + ex.getMessage()); + } + } + return result[0]; + } + + + /**适用于三菱PLC,只有X,Y,M,D区*/ + private int getModAddr(String address){ + if (address == null) return -1; + address = address.toUpperCase().trim(); + + try { + if (address.length() < 2) return Integer.parseInt(address); + + String res = address.substring(1); + if (res == null) return -1; + + int startAddress=Integer.parseInt(res) ; + //如果是M区地址。 + if (address.contains("M")) { + return startAddress + 4000; + } else if (address.contains("D")) { + return startAddress; + }else if(address.contains("X")){ + return Integer.parseInt(res,8); + }else if(address.contains("Y")){ + return Integer.parseInt(res,8)+300; + }else{ + return Integer.parseInt(address); + } + } catch (Exception e) { + return -1; + } + } +} diff --git a/app/src/main/java/com/bonait/bnframework/business/deviceControl/seasonBar/ScaleDevice.java b/app/src/main/java/com/bonait/bnframework/business/deviceControl/ScaleDevice.java similarity index 96% rename from app/src/main/java/com/bonait/bnframework/business/deviceControl/seasonBar/ScaleDevice.java rename to app/src/main/java/com/bonait/bnframework/business/deviceControl/ScaleDevice.java index c8262099..9f8e63a6 100644 --- a/app/src/main/java/com/bonait/bnframework/business/deviceControl/seasonBar/ScaleDevice.java +++ b/app/src/main/java/com/bonait/bnframework/business/deviceControl/ScaleDevice.java @@ -1,6 +1,5 @@ -package com.bonait.bnframework.business.deviceControl.seasonBar; +package com.bonait.bnframework.business.deviceControl; -import com.bonait.bnframework.business.deviceControl.ScaleAble; import com.bonait.bnframework.common.helper.DataFormat; import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.modbus.ModbusMaster; diff --git a/app/src/main/java/com/bonait/bnframework/business/deviceControl/seasonBar/PLCControl.java b/app/src/main/java/com/bonait/bnframework/business/deviceControl/seasonBar/PLCControl.java deleted file mode 100644 index 5664a1c6..00000000 --- a/app/src/main/java/com/bonait/bnframework/business/deviceControl/seasonBar/PLCControl.java +++ /dev/null @@ -1,229 +0,0 @@ -package com.bonait.bnframework.business.deviceControl.seasonBar; - -import android.os.Handler; -import android.os.Looper; - -import com.bonait.bnframework.business.deviceControl.PLCType; -import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.helper.I.IReadCallBack; -import com.bonait.bnframework.common.helper.I.IWriteCallBack; -import com.bonait.bnframework.common.modbus.ModbusMaster; -import com.bonait.bnframework.common.utils.ToastUtils; - -/**PLC控制类*/ -public class PLCControl{ - - //region 单例模式 - private static volatile PLCControl instance = null; - public static PLCControl get() { - PLCControl manager = instance; - if (manager == null) { - synchronized (PLCControl.class) { - manager = instance; - if (manager == null) { - manager = new PLCControl(); - instance = manager; - } - } - } - return manager; - } - private PLCControl(){}; - //endregion - - //region 私有变量 - /**设备的从站ID*/ - private final int slaveId=1; - /**PLC类型是三菱的*/ - private final PLCType plcType=PLCType.MELSEC; - //endregion - - - public void inital(IWriteCallBack callBack) { - - //TODO:确定初始化逻辑再写。 - } - - - public TDataType readPLC(String address,Class dataType, IReadCallBack callBack) { - if (Boolean.class.equals(dataType)) { - - return dataType.cast(true); - } else if (Short.class.equals(dataType)) { - - - return dataType.cast((short) 0); - } else if (Integer.class.equals(dataType)) { - - - return dataType.cast(0); - } else if (Float.class.equals(dataType)) { - - return dataType.cast(0.0f); - } else { - // 其他类型的处理逻辑 - return null; // 默认返回 null - } - } - - - public void writePLC(String address,TDataType value, IWriteCallBack callBack) { - - if (ModbusMaster.get().IsConnected && ConfigName.PLC_Address.containsKey(address)){ - String addr=ConfigName.PLC_Address.get(address).address; - if (!addr.isEmpty()&&getModAddr(addr)!=-1){ - try{ - String startAddr=String.valueOf(getModAddr(addr)); - //String startAddr=address; - if (value instanceof Boolean){ - ModbusMaster.get().WriteBool(startAddr,(boolean)value,slaveId,callBack); - } else if (value instanceof boolean[]) { - ModbusMaster.get().WriteBool(startAddr,(boolean[])value,slaveId,callBack); - } else if (value instanceof Integer) { - ModbusMaster.get().WriteInt(startAddr,(int) value,slaveId,callBack); - }else if (value instanceof int[]) { - ModbusMaster.get().WriteInt(startAddr,(int[]) value,slaveId,callBack); - }else if (value instanceof Short) { - ModbusMaster.get().WriteShort(startAddr,(short) value,slaveId,callBack); - }else if (value instanceof short[]) { - ModbusMaster.get().WriteShort(startAddr,(short[])value,slaveId,callBack ); - }else if (value instanceof Float) { - ModbusMaster.get().WriteFloat(startAddr,(float)value,slaveId,callBack ); - }else if (value instanceof Float[]) { - ModbusMaster.get().WriteFloat(startAddr,(float[]) value,slaveId,callBack ); - } - }catch (Exception ex){ - ToastUtils.error("Write PLC error:"+ex.getMessage()); - } - - } - } - } - - - /**适用于普通仓 - * @param index 仓位编号。 - * @param delayTime 开启时间。 - * */ - public void openMotorAndClose(int index, int delayTime, IWriteCallBack callBack) { - try { - openMotor(index, new IWriteCallBack() { - @Override - public void onSuccess() { - new Handler(Looper.getMainLooper()).postDelayed(()->{ - closeMotor(index, new IWriteCallBack() { - @Override - public void onSuccess() { - callBack.onSuccess(); - } - - @Override - public void onFailure(String ErrorMsg) { - callBack.onFailure(ErrorMsg); - } - }); - },delayTime); - } - @Override - public void onFailure(String ErrorMsg) { - callBack.onFailure(ErrorMsg); - } - }); - } catch (Exception ex) { - ToastUtils.error("OpenMotorAndClose Exception:" + ex.getMessage()); - } - } - - - public void openMotor(int index, IWriteCallBack callBack) { - - } - - - public void closeMotor(int index, IWriteCallBack callBack) { - - } - - - /**适用于普通仓(打开后即可关闭,不需要反转)。 - * @param name 仓位名称 - * @param delayTime 打开时间 - * */ - public void openMotorAndClose(String name, int delayTime, IWriteCallBack callBack) { - - } - - /**打开电机并反转,最后关闭 - * @param name 仓位名称。 - * @param delayTime 开启时间。 - * @param reverseTime 反转时间。 - * */ - public void openAndReverse(String name,int delayTime,int reverseTime,IWriteCallBack callBack){ - - } - - public void openMotor(String name, IWriteCallBack callBack) { - writePLC(name,true,callBack); - } - public void reverseMotor(String name, IWriteCallBack callBack) { - writePLC(name,false,callBack); - } - - public void closeMotor(String name, IWriteCallBack callBack) { - - } - - - public void clrHeartbeat(IWriteCallBack callBack) { - writePLC("心跳时间",(short)0,callBack); - } - - - public boolean isTimeOut() { - final boolean[] result = {true}; - if (ModbusMaster.get().IsConnected && ConfigName.PLC_Address.containsKey("断线标志")) { - String addr = ConfigName.PLC_Address.get("断线标志").address; - try { - int startAddr=getModAddr(addr); - if (!addr.isEmpty()&& startAddr!= -1) { - ModbusMaster.get().ReadBool(String.valueOf(startAddr), 1, slaveId, val->{ - result[0]=val[0]; - }); - } - } catch (Exception ex) { - ToastUtils.error("Exception message:" + ex.getMessage()); - } - } - return result[0]; - } - - - /**适用于三菱PLC,只有X,Y,M,D区*/ - private int getModAddr(String address){ - if (address == null) return -1; - address = address.toUpperCase().trim(); - - try { - if (address.length() < 2) return Integer.parseInt(address); - - String res = address.substring(1); - if (res == null) return -1; - - int startAddress=Integer.parseInt(res) ; - //如果是M区地址。 - if (address.contains("M")) { - return startAddress + 4000; - } else if (address.contains("D")) { - return startAddress; - }else if(address.contains("X")){ - return Integer.parseInt(res,8); - }else if(address.contains("Y")){ - return Integer.parseInt(res,8)+300; - }else{ - return Integer.parseInt(address); - } - } catch (Exception e) { - return -1; - } - } -} 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 18e8ed3f..1d51cde4 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 @@ -238,7 +238,7 @@ public class ConfigName { }}; - //endreion + //endregion //region 奶茶机 /** @@ -870,43 +870,49 @@ public class ConfigName { */ public List PlcAddress_调味吧台 = new ArrayList() {{ add(new Res_PLCADDRESS("心跳时间","D0",1 , 1 )); - add(new Res_PLCADDRESS("外置仓正转1","D1",1 , 1 )); - add(new Res_PLCADDRESS("外置仓正转2","D2",1 , 1 )); - add(new Res_PLCADDRESS("外置仓正转3","D3",1 , 1 )); - add(new Res_PLCADDRESS("外置仓正转4","D4",1 , 1 )); - add(new Res_PLCADDRESS("外置仓正转5","D5",1 , 1 )); - add(new Res_PLCADDRESS("外置仓正转6","D6",1 , 1 )); - add(new Res_PLCADDRESS("加热仓正转1","D7",1 , 1 )); - add(new Res_PLCADDRESS("加热仓正转2","D8",1 , 1 )); - add(new Res_PLCADDRESS("外置仓反转1","D9",1 , 1 )); - add(new Res_PLCADDRESS("外置仓反转2","D10",1 , 1 )); - add(new Res_PLCADDRESS("外置仓反转3","D11",1, 1)); - add(new Res_PLCADDRESS("外置仓反转4","D12",1, 1)); - add(new Res_PLCADDRESS("外置仓反转5","D13",1, 1)); - add(new Res_PLCADDRESS("外置仓反转6","D14",1, 1)); - add(new Res_PLCADDRESS("加热仓反转1","D15",1, 1)); - add(new Res_PLCADDRESS("加热仓反转2","D16",1, 1)); - add(new Res_PLCADDRESS("粉料仓1","D17",1, 1)); - add(new Res_PLCADDRESS("粉料仓2","D18",1, 1)); - add(new Res_PLCADDRESS("粉料仓3","D19",1, 1)); - add(new Res_PLCADDRESS("粉料仓4","D20",1, 1)); - add(new Res_PLCADDRESS("粉料仓5","D21",1, 1)); - add(new Res_PLCADDRESS("粉料仓6","D22",1, 1)); - add(new Res_PLCADDRESS("普通液体仓1","D23",1, 1)); - add(new Res_PLCADDRESS("普通液体仓2","D24",1, 1)); + + add(new Res_PLCADDRESS("通道1开关","D1",1 , 1 )); + add(new Res_PLCADDRESS("通道2开关","D2",1 , 1 )); + add(new Res_PLCADDRESS("通道3开关","D3",1 , 1 )); + add(new Res_PLCADDRESS("通道4开关","D4",1 , 1 )); + add(new Res_PLCADDRESS("通道5开关","D5",1 , 1 )); + add(new Res_PLCADDRESS("通道6开关","D6",1 , 1 )); + add(new Res_PLCADDRESS("通道7开关","D7",1 , 1 )); + add(new Res_PLCADDRESS("通道8开关","D8",1 , 1 )); + + add(new Res_PLCADDRESS("通道1反转","D9",1 , 1 )); + add(new Res_PLCADDRESS("通道2反转","D10",1 , 1 )); + add(new Res_PLCADDRESS("通道3反转","D11",1, 1)); + add(new Res_PLCADDRESS("通道4反转","D12",1, 1)); + add(new Res_PLCADDRESS("通道5反转","D13",1, 1)); + add(new Res_PLCADDRESS("通道6反转","D14",1, 1)); + add(new Res_PLCADDRESS("通道7反转","D15",1, 1)); + add(new Res_PLCADDRESS("通道8反转","D16",1, 1)); + + add(new Res_PLCADDRESS("通道9开关","D17",1, 1)); + add(new Res_PLCADDRESS("通道10开关","D18",1, 1)); + add(new Res_PLCADDRESS("通道11开关","D19",1, 1)); + add(new Res_PLCADDRESS("通道12开关","D20",1, 1)); + add(new Res_PLCADDRESS("通道13开关","D21",1, 1)); + add(new Res_PLCADDRESS("通道14开关","D22",1, 1)); + add(new Res_PLCADDRESS("通道15开关","D23",1, 1)); + add(new Res_PLCADDRESS("通道16开关","D24",1, 1)); + add(new Res_PLCADDRESS("进水阀","D40",1, 1)); add(new Res_PLCADDRESS("排水阀","D41",1, 1)); add(new Res_PLCADDRESS("加热仓管道1","D42",1, 1)); add(new Res_PLCADDRESS("加热仓管道2","D43",1, 1)); + add(new Res_PLCADDRESS("三色灯红","D44",1, 1)); add(new Res_PLCADDRESS("三色灯绿","D45",1, 1)); add(new Res_PLCADDRESS("三色灯黄","D46",1, 1)); + add(new Res_PLCADDRESS("清洗加热","D47",1, 1)); - add(new Res_PLCADDRESS("清洗温度","D85",1, 1)); + add(new Res_PLCADDRESS("清洗温度","D85",1, 0)); add(new Res_PLCADDRESS("断线标志","M0",1, 0)); add(new Res_PLCADDRESS("按钮启动","M1",1, 1)); - add(new Res_PLCADDRESS("清洗液位","M2",1, 1)); + add(new Res_PLCADDRESS("清洗液位","M2",1, 0)); }}; /** @@ -919,8 +925,10 @@ public class ConfigName { add(new ResSilosModel("外置仓",4 , 4 )); add(new ResSilosModel("外置仓",5 , 5 )); add(new ResSilosModel("外置仓",6 , 6 )); - add(new ResSilosModel("加热仓",7 , 7 )); - add(new ResSilosModel("加热仓",8 , 8 )); + //加热仓 + add(new ResSilosModel("外置仓",7 , 7 )); + add(new ResSilosModel("外置仓",8 , 8 )); + add(new ResSilosModel("粉料仓",9 , 9 )); add(new ResSilosModel("粉料仓",10, 10)); add(new ResSilosModel("粉料仓",11, 11)); diff --git a/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java b/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java index 7cf1d696..5ed7adf6 100644 --- a/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java +++ b/app/src/main/java/com/bonait/bnframework/common/constant/DataBus.java @@ -1,16 +1,10 @@ package com.bonait.bnframework.common.constant; -import android.app.Activity; -import android.content.Intent; -import android.widget.LinearLayout; - import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; +import com.bonait.bnframework.business.deviceControl.PLCControl; import com.bonait.bnframework.common.db.QueryDB; -import com.bonait.bnframework.common.db.mode.BPA_ALERTLOG; import com.bonait.bnframework.common.db.mode.BPA_GOODPROPERTY; -import com.bonait.bnframework.common.db.mode.BPA_GOODS; -import com.bonait.bnframework.common.db.mode.BPA_LOG; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.mode.BPA_SILOS; import com.bonait.bnframework.common.db.mode.BPA_SUBORDER; @@ -19,29 +13,19 @@ import com.bonait.bnframework.common.db.res.MakeStatus; import com.bonait.bnframework.common.db.res.ResGoodProperty; import com.bonait.bnframework.common.db.res.ResGoodsMake; import com.bonait.bnframework.common.db.res.ResGoodsRecipe; -import com.bonait.bnframework.common.db.res.Res_PLCADDRESS1; -import com.bonait.bnframework.common.db.res.SilosLsjyMode; import com.bonait.bnframework.common.db.res.StatusMode; -import com.bonait.bnframework.common.db.res.UserLogEnum; import com.bonait.bnframework.common.db.res.lcMode; import com.bonait.bnframework.common.db.res.wdszMode; -import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.helper.MessageLog; -import com.bonait.bnframework.common.helper.mode.OrderA; -import com.bonait.bnframework.common.helper.mode.ResultA; import com.bonait.bnframework.common.linktab.LinkMode; import com.bonait.bnframework.modules.home.adapter.loadinggood_adapter; import com.bonait.bnframework.modules.home.adapter.pfsx_adapter; import com.bonait.bnframework.modules.home.adapter.wdsz_adapter; import com.bonait.bnframework.modules.home.adapter.zdqxchid_adapter; -import com.bonait.bnframework.modules.home.fragment.mode.sdkz_control; -import com.bonait.bnframework.modules.home.fragment.mode.tab_control; import java.util.ArrayList; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; /** * 单例模式 @@ -401,13 +385,23 @@ public class DataBus { names.add("水池温度"); names.add("果糖左温度"); names.add("果糖右温度"); + }else if (ConfigName.getInstance().versionSelectionEnum.equals("调味吧台")) + { + names.add("清洗温度"); } + for (String item:names) { wdszMode mode=new wdszMode(); mode.name=item; mode.temp=0; - Object sx=ExecuteTheRecipe.ReadPLC(item+"设置"); + Object sx; + if (ConfigName.getInstance().versionSelectionEnum.equals("调味吧台")){ + sx= PLCControl.get().getCleanTemp(); + }else{ + sx=ExecuteTheRecipe.ReadPLC(item+"设置"); + } + mode.tempup=sx==null?0:(int)sx; mode.autoheat=false; if(item.equals("水池温度")) @@ -442,7 +436,11 @@ public class DataBus { { Object sx=ExecuteTheRecipe.ReadPLC(item.name); item.autoheat=sx==null?false:(boolean)sx; - }else + }else if(item.name.equals("清洗温度")){ + Object sx=PLCControl.get().getCleanTemp(); + item.autoheat=sx==null?false:(boolean)sx; + } + else { Object sx=ExecuteTheRecipe.ReadPLC(item.name+"设置"); item.tempup=sx==null?0:(int)sx; diff --git a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java b/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java deleted file mode 100644 index 377688a5..00000000 --- a/app/src/main/java/com/bonait/bnframework/common/modbus/ModbusRTUServer.java +++ /dev/null @@ -1,632 +0,0 @@ -package com.bonait.bnframework.common.modbus; - -import com.bonait.bnframework.business.ConfigData; -import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.helper.DataFormat; -import com.bonait.bnframework.common.helper.I.IReadCallBack; -import com.bonait.bnframework.common.helper.I.IWriteCallBack; -import com.bonait.bnframework.common.helper.MessageLog; -import com.licheedev.modbus4android.ModbusCallback; -import com.licheedev.modbus4android.ModbusParam; -import com.licheedev.modbus4android.ModbusRespException; -import com.licheedev.modbus4android.param.SerialParam; -import com.serotonin.modbus4j.ModbusMaster; -import com.serotonin.modbus4j.exception.ModbusInitException; -import com.serotonin.modbus4j.exception.ModbusTransportException; -import com.serotonin.modbus4j.msg.ReadCoilsResponse; -import com.serotonin.modbus4j.msg.ReadHoldingRegistersResponse; - -import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.concurrent.ExecutionException; - -public class ModbusRTUServer { - //region 单例模式 - private static volatile ModbusRTUServer instance = null; - - public static ModbusRTUServer get() { - ModbusRTUServer manager = instance; - if (manager == null) { - synchronized (ModbusRTUServer.class) { - manager = instance; - if (manager == null) { - manager = new ModbusRTUServer(); - instance = manager; - } - } - } - return manager; - } - private ModbusRTUServer() { - } - //endregion - - - static ModbusParam param; - - /**适用于三菱PLC,只有X,Y,M,D区*/ - public static int GetAddress(String address){ - if (address == null) return -1; - address = address.toUpperCase().trim(); - - try { - if (address.length() < 2) return Integer.parseInt(address); - - String res = address.substring(1); - if (res == null) return -1; - - int startAddress=Integer.parseInt(res) ; - //如果是M区地址。 - if (address.contains("M")) { - return startAddress + 4000; - } else if (address.contains("D")) { - return startAddress; - }else if(address.contains("X")){ - return Integer.parseInt(res,8); - }else if(address.contains("Y")){ - return Integer.parseInt(res,8)+300; - }else{ - return Integer.parseInt(address); - } - } catch (Exception e) { - return -1; - } - } - - - /** 连接PLC*/ - public void ConnectPLC() - { - int baudRate=ConfigName.getInstance().SerialBaudRate; - int dataBits=ConfigName.getInstance().SerialDataBits; - int parity=ConfigName.getInstance().SerialParity; - int stopBits=ConfigName.getInstance().SerialStopBits; - //String com="COM0"; - - param = SerialParam.create("/dev/ttyCOM0", baudRate) // 串口地址和波特率 - .setDataBits(dataBits) // 数据位 - .setParity(parity) // 校验位 - .setStopBits(stopBits) // 停止位 - .setTimeout(3000).setRetries(0); // 不重试 - - ModbusTcpHelper.get().init(param, new ModbusCallback() { - @Override - public void onSuccess(ModbusMaster modbusMaster) { - //ToastUtils.info("串口 ["+com+"] 连接成功"); - - //MessageLog.ShowInfo("串口 ["+com+"] 连接成功"); - ConfigName.getInstance().SerialIsConnect = true; - ConfigData.getInstance().PLC_Init(); - } - - @Override - public void onFailure(Throwable tr) { - ConfigName.getInstance().SerialIsConnect = false; - //ToastUtils.info("串口 ["+com+"] 连接失败:" + tr.getMessage()); - //MessageLog.ShowError("串口 ["+com+"] 连接失败:" + tr.getMessage()); - } - @Override - public void onFinally() { - } - }); - } - - - //region 数据类型转换 - private Float BytesToFloat(byte[] buffers, DataFormat df) { - if (buffers.length == 4) { - byte[] bytes = new byte[4]; - if (df == DataFormat.ABCD) { - bytes[0] = buffers[3]; - bytes[1] = buffers[2]; - bytes[2] = buffers[1]; - bytes[3] = buffers[0]; - } else if (df == DataFormat.CDAB) { - bytes[0] = buffers[1]; - bytes[1] = buffers[0]; - bytes[2] = buffers[3]; - bytes[3] = buffers[2]; - } else if (df == DataFormat.BADC) { - bytes[0] = buffers[2]; - bytes[1] = buffers[3]; - bytes[2] = buffers[0]; - bytes[3] = buffers[1]; - } else if (df == DataFormat.DCBA) { - bytes[0] = buffers[0]; - bytes[1] = buffers[1]; - bytes[2] = buffers[2]; - bytes[3] = buffers[3]; - } - return ByteBuffer.wrap(bytes).getFloat(); - } - return 0.0f; - } - - private Integer BytesToInt(byte[] buffers, DataFormat df) { - if (buffers.length == 4) { - byte[] bytes = new byte[4]; - if (df == DataFormat.ABCD) { - bytes[0] = buffers[3]; - bytes[1] = buffers[2]; - bytes[2] = buffers[1]; - bytes[3] = buffers[0]; - } else if (df == DataFormat.CDAB) { - bytes[0] = buffers[1]; - bytes[1] = buffers[0]; - bytes[2] = buffers[3]; - bytes[3] = buffers[2]; - } else if (df == DataFormat.BADC) { - bytes[0] = buffers[2]; - bytes[1] = buffers[3]; - bytes[2] = buffers[0]; - bytes[3] = buffers[1]; - } else if (df == DataFormat.DCBA) { - bytes[0] = buffers[0]; - bytes[1] = buffers[1]; - bytes[2] = buffers[2]; - bytes[3] = buffers[3]; - } - return ByteBuffer.wrap(bytes).getInt(); - } - return 0; - } - - private byte[] IntToByte(int number) { - int temp = number; - byte[] b = new byte[4]; - for (int i = 0; i < b.length; i++) { - b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位 - temp = temp >> 8; // 向右移8位 - } - return b; - } - - private short[] IntToShorts(int value) { - short[] res = new short[2]; - int temp = value; - byte[] b = new byte[4]; - for (int i = 0; i < b.length; i++) { - b[i] = new Integer(temp & 0xff).byteValue();// 将最低位保存在最低位 - temp = temp >> 8; // 向右移8位 - } - for (int i = 0; i < res.length; i++) { - short s0 = (short) (b[i * 2] & 0xff);// 最低位 - short s1 = (short) (b[i * 2 + 1] & 0xff); - s1 <<= 8; - res[i] = (short) (s0 | s1); - } - return res; - } - - public static String GetString(short[] src, int start, int len) throws UnsupportedEncodingException { - short[] temp = new short[len]; - for (int i = 0; i < len; i++) { - temp[i] = src[i + start]; - } - byte[] bytesTemp = shorts2Bytes(temp); - for (int i = 0; i < bytesTemp.length; i++) { - byte b = bytesTemp[i]; - } - String str = new String(bytesTemp, "UTF-8"); - return str; - } - - public static byte[] shorts2Bytes(short[] data) { - byte[] byteValue = new byte[data.length * 2]; - for (int i = 0; i < data.length; i++) { - byteValue[i * 2] = (byte) (data[i] & 0xff); - byteValue[i * 2 + 1] = (byte) ((data[i] & 0xff00) >> 8); - } - return byteValue; - } - //endregion - - //region 读取及写入方法 - - /**写入字符串*/ - public void WriteString(int slaveAddress,String Address, int length, IWriteCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - short[] send = new short[length]; - for (short item : send) { - item = 0; - } - try { - ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, add, send); - if (callback != null) - callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - /**写入字符串*/ - public void WriteString(int slaveAddress,int Address, short[] values, IWriteCallBack callback) { - if (slaveAddress<0) return; - if (Address < 0) return; - if (values ==null || values.length==0) return; - try { - ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, values); - if (callback != null) - callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteString onFailure,Address=" + Address + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - - /**根据地址批量读取16位寄存器*/ - public void ReadShorts(int slaveAddress,int Address, int length, IReadCallBack callback) { - //int add = GetAddress(Address); - if (Address < 0) return; - try { - ReadHoldingRegistersResponse res = ModbusTcpHelper.get() - .syncReadHoldingRegisters(slaveAddress, Address, length); - short[] data = res.getShortData(); - if (data.length == length) { - if (callback != null) callback.onSuccess(data); - } - } catch (InterruptedException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadShort onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - public void ReadBools(int slaveAddress,String Address, int length, IReadCallBack callback) { - int add = GetAddress(Address); - if (add < 0) return; - try { - ReadCoilsResponse res = ModbusTcpHelper.get() - .syncReadCoil(slaveAddress, add, length); - boolean[] data = res.getBooleanData(); - boolean[] result = Arrays.copyOfRange(data, 0, length); - if (result.length == length) { - if (callback != null) callback.onSuccess(result); - } - } catch (InterruptedException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - }catch (Exception e){ - MessageLog.ShowError("ReadBool onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - public void ReadFloats(int slaveAddress,int Address, int length, IReadCallBack callback) { - //int add = GetAddress(Address); - if (Address < 0) return; - try { - ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(slaveAddress, Address, length*2); - byte[] data = res.getData(); - float[] tempValues = new float[length]; - for (int i = 0; i < length; i++) { - byte[] tempData = new byte[4]; - for (int m = 0; m < 4; m++) { - tempData[m] = data[i * 4 + m]; - } - tempValues[i] = BytesToFloat(tempData, DataFormat.BADC); - } - if (tempValues.length == length) { - if (callback != null) callback.onSuccess(tempValues); - } - } catch (InterruptedException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadFloat onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - public void ReadInts(int slaveAddress,int Address, int length,DataFormat dataFormat, IReadCallBack callback) { - //int add = GetAddress(Address); - if (Address < 0) return; - try { - ReadHoldingRegistersResponse res = ModbusTcpHelper.get().syncReadHoldingRegisters(slaveAddress, Address, length * 2); - byte[] data = res.getData(); - int[] tempValues = new int[length]; - if(data.length>=4) - { - for (int i = 0; i < length; i++) { - byte[] tempData = new byte[4]; - for (int m = 0; m < 4; m++) { - tempData[m] = data[i * 4 + m]; - } - tempValues[i] = BytesToInt(tempData, dataFormat); - } - }else - { - MessageLog.ShowError("ReadInt onFailure,Address=" ); - - } - if (callback != null) callback.onSuccess(tempValues); - } catch (InterruptedException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("ReadInt onFailure,Address=" + Address + ",length=" + length + ",msg:" + e.toString()); - } - } - - public void WriteShort(int slaveAddress,int Address, short Value, IWriteCallBack callback) { - //int add = GetAddress(Address); - if (Address < 0) return; - short[] send = new short[1]; - send[0] = Value; - try { - ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send); - if (callback != null) - callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void WriteShorts(int slaveAddress,int Address, short[] Value, IWriteCallBack callback) { - //int add = GetAddress(Address); - if (Address < 0) return; - try { - ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, Value); - if (callback != null) - callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void WriteBool(int slaveAddress,int Address, boolean Value, IWriteCallBack callback) { - //int add = GetAddress(Address); - if (Address < 0) return; - try { - ModbusTcpHelper.get().syncWriteCoil(slaveAddress, Address, Value); - if (callback != null) - callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void WriteBools(int slaveAddress,int Address, boolean[] Value, IWriteCallBack callback) { - //int add = GetAddress(Address); - if (Address < 0) return; - try { - ModbusTcpHelper.get().syncWriteCoils(slaveAddress, Address, Value); - if (callback != null) - callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - public void WriteFloat(int slaveAddress,int Address, float Value, IWriteCallBack callback) { - //int add = GetAddress(Address); - if (Address < 0) return; - int intBits = Float.floatToRawIntBits(Value); - short[] send = IntToShorts(intBits); - try { - ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send); - - if (callback != null) callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void WriteInt(int slaveAddress,int Address, int Value, IWriteCallBack callback) { - //int add = GetAddress(Address); - if (Address < 0) return; - short[] send = IntToShorts(Value); - try { - ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send); - if (callback != null) callback.onSuccess(); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - if (callback != null) callback.onFailure(e.toString()); - } - } - - public void WriteShort(int slaveAddress,int Address, short Value) { - //int add = GetAddress(Address); - if (Address < 0) return; - short[] send = new short[1]; - send[0] = Value; - try { - ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteShort onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } - } - - public void WriteBool(int slaveAddress,int Address, boolean Value) { - //int add = GetAddress(Address); - if (Address < 0) return; - - try { - ModbusTcpHelper.get().syncWriteCoil(slaveAddress, Address, Value); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteBool onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } - } - - public void WriteFloat(int slaveAddress,int Address, float Value) { - //int add = GetAddress(Address); - if (Address < 0) return; - int intBits = Float.floatToRawIntBits(Value); - short[] send = new short[]{(short) ((intBits >> 16) & 0xffff), (short) (intBits & 0xffff)}; - try { - ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteFloat onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } - } - - public void WriteInt(int slaveAddress,int Address, int Value) { - //int add = GetAddress(Address); - if (Address < 0) return; - short[] send = IntToShorts(Value); - try { - ModbusTcpHelper.get().syncWriteRegisters(slaveAddress, Address, send); - } catch (InterruptedException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ExecutionException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusTransportException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusInitException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } catch (ModbusRespException e) { - MessageLog.ShowError("WriteInt onFailure,Address=" + Address + ",length=" + Value + ",msg:" + e.toString()); - } - } - - //endregion -} 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 6609e53e..7fba751a 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 @@ -1,29 +1,20 @@ package com.bonait.bnframework.modules.home.activity; +import android.os.Bundle; + import androidx.fragment.app.Fragment; import androidx.viewpager.widget.ViewPager; -import android.os.Bundle; -import android.util.Log; - import com.bonait.bnframework.R; import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.business.OrderServer; import com.bonait.bnframework.common.base.BaseActivity; import com.bonait.bnframework.common.constant.ConfigName; -import com.bonait.bnframework.common.helper.DataFormat; -import com.bonait.bnframework.common.helper.I.IThread; -import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.MQTT; import com.bonait.bnframework.common.helper.MediaPlayerHelper; import com.bonait.bnframework.common.helper.MessageLog; -import com.bonait.bnframework.common.helper.ThreadManager; -import com.bonait.bnframework.common.modbus.ByteLib; -import com.bonait.bnframework.common.modbus.FloatLib; import com.bonait.bnframework.common.modbus.IOperateResult; -import com.bonait.bnframework.common.modbus.ModbusClient; import com.bonait.bnframework.common.modbus.ModbusMaster; -import com.bonait.bnframework.common.modbus.ShortLib; import com.bonait.bnframework.common.tabbar.MainNavigateTabBar; import com.bonait.bnframework.common.utils.NetworkUtils; import com.bonait.bnframework.common.utils.ToastUtils; @@ -134,7 +125,7 @@ public class BottomNavigationMainActivity extends BaseActivity { @Override public void onFailure(String message) { ConfigName.getInstance().PlcIsConnect = false; - ToastUtils.info("设备 " + ConfigName.getInstance().Address + " 连接失败:" + message); + ToastUtils.info("设备 " + ConfigName.getInstance().SerialPortName + " 连接失败:" + message); } @Override diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/wdsz_adapter.java b/app/src/main/java/com/bonait/bnframework/modules/home/adapter/wdsz_adapter.java index a213a4b5..c16b6b3f 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/wdsz_adapter.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/adapter/wdsz_adapter.java @@ -20,12 +20,9 @@ import androidx.recyclerview.widget.RecyclerView; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.business.ExecuteTheRecipe; -import com.bonait.bnframework.business.MainInit; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.DataBus; -import com.bonait.bnframework.common.db.res.SilosLsjyMode; import com.bonait.bnframework.common.db.res.wdszMode; -import com.bonait.bnframework.common.helper.I.IRun; import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.InputFilterMinMax; import com.bonait.bnframework.common.utils.ToastUtils; @@ -92,6 +89,10 @@ public class wdsz_adapter extends RecyclerView.Adapter myViewHolder.show_wd.setVisibility(View.GONE); myViewHolder.show_wdsz.setVisibility(View.GONE); myViewHolder.save_value.setVisibility(View.GONE); + }else if (goodsMake.name.equals("清洗温度")) { + myViewHolder.zdbs1.setVisibility(View.GONE); + myViewHolder.zdbs2.setVisibility(View.GONE); + myViewHolder.edittext_sx.setFilters(new InputFilter[]{ new InputFilterMinMax("0", "60")}); } myViewHolder.temp.setText(goodsMake.temp+""); myViewHolder.control_switch.setChecked(goodsMake.autoheat); 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 b68fbfd8..eb1dc3f7 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 @@ -1,37 +1,29 @@ package com.bonait.bnframework.modules.home.fragment; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.content.ContextCompat; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - import android.app.Activity; import android.content.Context; -import android.content.res.Resources; import android.graphics.Color; import android.os.Bundle; import android.os.Handler; import android.os.Message; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; -import android.widget.Button; -import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import com.bonait.bnframework.R; -import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.business.ExecuteTheRecipe; -import com.bonait.bnframework.business.deviceControl.seasonBar.ScaleDevice; +import com.bonait.bnframework.business.deviceControl.ScaleDevice; 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_GOODPROPERTY; import com.bonait.bnframework.common.db.mode.BPA_GOODS; import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPENAME; import com.bonait.bnframework.common.db.mode.BPA_GOODSTYPE; @@ -39,17 +31,12 @@ import com.bonait.bnframework.common.db.mode.BPA_ORDER; import com.bonait.bnframework.common.db.mode.BPA_SUBORDER; import com.bonait.bnframework.common.db.res.ResGoodProperty; import com.bonait.bnframework.common.db.res.ResGoodsMake; -import com.bonait.bnframework.common.db.res.SilosLsjyMode; import com.bonait.bnframework.common.helper.I.IRun; import com.bonait.bnframework.common.helper.I.IRunT; -import com.bonait.bnframework.common.helper.I.IThread; import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.I.MyClickListener; -import com.bonait.bnframework.common.helper.ThreadManager; import com.bonait.bnframework.common.linktab.LinkMode; import com.bonait.bnframework.common.linktab.TopItemDecoration; -import com.bonait.bnframework.common.linktab.good.GoodLeftAdapter; -import com.bonait.bnframework.common.linktab.good.GoodRightAdapter; import com.bonait.bnframework.common.linktab.makegood.MakeGoodLeftAdapter; import com.bonait.bnframework.common.linktab.makegood.MakeGoodRightAdapter; import com.bonait.bnframework.common.message.MessageLooper; @@ -57,11 +44,8 @@ import com.bonait.bnframework.common.message.MessageManager; import com.bonait.bnframework.common.utils.AlertDialogUtils; import com.bonait.bnframework.common.utils.ToastUtils; import com.bonait.bnframework.modules.home.adapter.loadinggood_adapter; -import com.bonait.bnframework.modules.home.adapter.wl_adapter; import com.bonait.bnframework.modules.home.fragment.mode.add_makegood_control; import com.bonait.bnframework.modules.home.fragment.mode.add_manguan_control; -import com.bonait.bnframework.modules.home.fragment.mode.add_pf_control; -import com.litao.slider.NiftySlider; import com.orhanobut.logger.Logger; import com.qmuiteam.qmui.widget.QMUITopBarLayout; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; @@ -69,7 +53,6 @@ import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedHashMap; import java.util.List; import butterknife.BindView; @@ -118,8 +101,9 @@ public class MakeGoodFragment extends BaseFragment { */ @BindView(R.id.wendu1) TextView wendu1; - // @BindView(R.id.pf_ms) -// TextView pf_ms; + + //@BindView(R.id.pf_ms) + //TextView pf_ms; @BindView(R.id.plc_status) TextView plc_status; @BindView(R.id.dianzichen) diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DzcjyActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DzcjyActivity.java index f4a2cf9a..f32b338b 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DzcjyActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/DzcjyActivity.java @@ -10,7 +10,7 @@ import android.widget.EditText; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; -import com.bonait.bnframework.business.deviceControl.seasonBar.ScaleDevice; +import com.bonait.bnframework.business.deviceControl.ScaleDevice; import com.bonait.bnframework.common.base.BaseActivity; import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.utils.ToastUtils; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/RealTimeActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/RealTimeActivity.java index eb98cf6c..006d0376 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/RealTimeActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/RealTimeActivity.java @@ -15,6 +15,7 @@ import com.bonait.bnframework.common.base.BaseActivity; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.constant.DataBus; import com.bonait.bnframework.common.db.res.StatusMode; +import com.bonait.bnframework.common.modbus.ModbusMaster; import com.bonait.bnframework.common.view.MyLayoutManager; import com.bonait.bnframework.modules.home.adapter.devstatus_adapter; import com.qmuiteam.qmui.widget.QMUITopBarLayout; @@ -72,27 +73,61 @@ public class RealTimeActivity extends BaseActivity { public void Initdata() { try{ - if (ConfigName.getInstance().versionSelectionEnum.equals("味魔方")){ - DataBus.getInstance().statusModes=new ArrayList<>(); - - - DataBus.getInstance().statusModes.add(new StatusMode("通道一开关",R.mipmap.rdl1,R.mipmap.rdl2,false)); - DataBus.getInstance().statusModes.add(new StatusMode("通道二开关",R.mipmap.csf1,R.mipmap.csf2,false)); - DataBus.getInstance().statusModes.add(new StatusMode("通道三开关",R.mipmap.csf1,R.mipmap.csf2,false)); - DataBus.getInstance().statusModes.add(new StatusMode("通道四开关",R.mipmap.rdl1,R.mipmap.rdl2,false)); - - DataBus.getInstance().statusModes.add(new StatusMode("通道五开关",R.mipmap.rdl1,R.mipmap.rdl2,false)); - DataBus.getInstance().statusModes.add(new StatusMode("通道六开关",R.mipmap.csf1,R.mipmap.csf2,false)); - DataBus.getInstance().statusModes.add(new StatusMode("通道七开关",R.mipmap.csf1,R.mipmap.csf2,false)); - DataBus.getInstance().statusModes.add(new StatusMode("通道八开关",R.mipmap.rdl1,R.mipmap.rdl2,false)); - - DataBus.getInstance().statusModes.add(new StatusMode("通道九开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); - DataBus.getInstance().statusModes.add(new StatusMode("通道十开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); - DataBus.getInstance().statusModes.add(new StatusMode("通道十一开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); - DataBus.getInstance().statusModes.add(new StatusMode("通道十二开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); - DataBus.getInstance().statusModes.add(new StatusMode("通道十三开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); - DataBus.getInstance().statusModes.add(new StatusMode("通道十四开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); - + DataBus.getInstance().statusModes=new ArrayList<>(); + switch (ConfigName.getInstance().versionSelectionEnum){ + case "味魔方": + DataBus.getInstance().statusModes.add(new StatusMode("通道一开关",R.mipmap.rdl1,R.mipmap.rdl2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("通道二开关",R.mipmap.csf1,R.mipmap.csf2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("通道三开关",R.mipmap.csf1,R.mipmap.csf2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("通道四开关",R.mipmap.rdl1,R.mipmap.rdl2,false)); + + DataBus.getInstance().statusModes.add(new StatusMode("通道五开关",R.mipmap.rdl1,R.mipmap.rdl2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("通道六开关",R.mipmap.csf1,R.mipmap.csf2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("通道七开关",R.mipmap.csf1,R.mipmap.csf2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("通道八开关",R.mipmap.rdl1,R.mipmap.rdl2,false)); + + DataBus.getInstance().statusModes.add(new StatusMode("通道九开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("通道十开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("通道十一开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("通道十二开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("通道十三开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("通道十四开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); + break; + + case "调味吧台": + DataBus.getInstance().statusModes.add(new StatusMode("外置仓一正转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("外置仓二正转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("外置仓三正转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("外置仓四正转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("外置仓五正转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("外置仓六正转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + + DataBus.getInstance().statusModes.add(new StatusMode("加热仓一正转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("加热仓二正转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + + DataBus.getInstance().statusModes.add(new StatusMode("外置仓一反转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("外置仓二反转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("外置仓三反转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("外置仓四反转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("外置仓五反转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("外置仓六反转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + + DataBus.getInstance().statusModes.add(new StatusMode("加热仓一反转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("加热仓二反转",R.mipmap.rdl1,R.mipmap.rdl2,false)); + + DataBus.getInstance().statusModes.add(new StatusMode("粉料仓一开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("粉料仓二开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("粉料仓三开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("粉料仓四开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("粉料仓五开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("粉料仓六开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); + + DataBus.getInstance().statusModes.add(new StatusMode("普通液体仓一开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); + DataBus.getInstance().statusModes.add(new StatusMode("普通液体仓二开关",R.mipmap.djcgq1,R.mipmap.djcgq2,false)); + break; + + case "奶茶机": + break; } Run(); @@ -125,7 +160,7 @@ public class RealTimeActivity extends BaseActivity { @Override public void run() { //while (ConfigName.getInstance().SerialIsConnect) { - while (!ExecuteTheRecipe.isTimeOut) { + while (ModbusMaster.get().IsConnected) { try { runOnUiThread(new Runnable() { @Override @@ -138,6 +173,16 @@ public class RealTimeActivity extends BaseActivity { SetStatus(i,ExecuteTheRecipe.getConcurrentHash(i)); } break; + case "调味吧台": + for (int i=0;i<24;i++){ + SetStatus(i,ExecuteTheRecipe.getConcurrentHash(i)); + } + break; + case "奶茶机": + + break; + default: + break; } adapter.refresh(); } catch (Exception e) { diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java index 6d351878..182e6dc3 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/SystemParameterActivity.java @@ -2,15 +2,9 @@ package com.bonait.bnframework.modules.home.fragment.from; import static com.bonait.bnframework.MainApplication.getContext; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; - import android.content.Context; import android.os.Bundle; -import android.view.LayoutInflater; import android.view.View; -import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.Spinner; @@ -18,16 +12,11 @@ import android.widget.Spinner; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ConfigData; import com.bonait.bnframework.common.base.BaseActivity; -import com.bonait.bnframework.common.base.BaseFragment; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_SYSTEMSET; import com.bonait.bnframework.common.utils.ToastUtils; -import com.bonait.bnframework.modules.home.fragment.GuanLifragment; -import com.bonait.bnframework.modules.home.fragment.SheZhifragment; import com.qmuiteam.qmui.widget.QMUITopBarLayout; -import com.qmuiteam.qmui.widget.QMUIViewPager; -import com.qmuiteam.qmui.widget.tab.QMUITabSegment; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -197,22 +186,22 @@ public class SystemParameterActivity extends BaseActivity { ConfigName.getInstance().DeviceAutoKey = item.value; edittext4.setText(item.value); break; - case 20: - ConfigName.getInstance().SerialBaudRate = Integer.parseInt(item.value); - serialBaudRate.setSelection(baudRate_map.get(item.value)); - break; - case 21: - ConfigName.getInstance().SerialDataBits = Integer.parseInt(item.value); - serialDataBits.setSelection(dataBits_map.get(item.value)); - break; - case 22: - ConfigName.getInstance().SerialParity = Integer.parseInt(item.value); - serialParity.setSelection(parity_map.get(item.value)); - break; - case 23: - ConfigName.getInstance().SerialStopBits = Integer.parseInt(item.value); - serialStopBits.setSelection(stop_Bits.get(item.value)); - break; +// case 20: +// ConfigName.getInstance().SerialBaudRate = Integer.parseInt(item.value); +// serialBaudRate.setSelection(baudRate_map.get(item.value)); +// break; +// case 21: +// ConfigName.getInstance().SerialDataBits = Integer.parseInt(item.value); +// serialDataBits.setSelection(dataBits_map.get(item.value)); +// break; +// case 22: +// ConfigName.getInstance().SerialParity = Integer.parseInt(item.value); +// serialParity.setSelection(parity_map.get(item.value)); +// break; +// case 23: +// ConfigName.getInstance().SerialStopBits = Integer.parseInt(item.value); +// serialStopBits.setSelection(stop_Bits.get(item.value)); +// break; } } } @@ -268,7 +257,7 @@ public class SystemParameterActivity extends BaseActivity { set_vis.userID = ConfigName.getInstance().user.userID; QueryDB.AddSystemset(set_vis); - saveSerialParam(); + //saveSerialParam(); if (isgb) { ConfigData.getInstance().RevertPLCProcess(); @@ -281,35 +270,35 @@ public class SystemParameterActivity extends BaseActivity { //-------------------------配置viewPager与fragment关联----------------------------// /**保存串口设置参数*/ - private void saveSerialParam(){ - BPA_SYSTEMSET set_baudrate = new BPA_SYSTEMSET(); - set_baudrate.type = 20; - set_baudrate.value =serialBaudRate.getSelectedItem().toString(); - set_baudrate.deviceID = ConfigName.getInstance().DeviceId; - set_baudrate.userID = ConfigName.getInstance().user.userID; - QueryDB.AddSystemset(set_baudrate); - - BPA_SYSTEMSET set_dataBits = new BPA_SYSTEMSET(); - set_dataBits.type = 21; - set_dataBits.value = serialDataBits.getSelectedItem().toString(); - set_dataBits.deviceID = ConfigName.getInstance().DeviceId; - set_dataBits.userID = ConfigName.getInstance().user.userID; - QueryDB.AddSystemset(set_dataBits); - - BPA_SYSTEMSET set_parity = new BPA_SYSTEMSET(); - set_parity.type = 22; - set_parity.value =serialParity.getSelectedItem().toString(); - set_parity.deviceID = ConfigName.getInstance().DeviceId; - set_parity.userID = ConfigName.getInstance().user.userID; - QueryDB.AddSystemset(set_parity); - - BPA_SYSTEMSET set_stopBits = new BPA_SYSTEMSET(); - set_stopBits.type = 23; - set_stopBits.value = serialStopBits.getSelectedItem().toString(); - set_stopBits.deviceID = ConfigName.getInstance().DeviceId; - set_stopBits.userID = ConfigName.getInstance().user.userID; - QueryDB.AddSystemset(set_stopBits); - } +// private void saveSerialParam(){ +// BPA_SYSTEMSET set_baudrate = new BPA_SYSTEMSET(); +// set_baudrate.type = 20; +// set_baudrate.value =serialBaudRate.getSelectedItem().toString(); +// set_baudrate.deviceID = ConfigName.getInstance().DeviceId; +// set_baudrate.userID = ConfigName.getInstance().user.userID; +// QueryDB.AddSystemset(set_baudrate); +// +// BPA_SYSTEMSET set_dataBits = new BPA_SYSTEMSET(); +// set_dataBits.type = 21; +// set_dataBits.value = serialDataBits.getSelectedItem().toString(); +// set_dataBits.deviceID = ConfigName.getInstance().DeviceId; +// set_dataBits.userID = ConfigName.getInstance().user.userID; +// QueryDB.AddSystemset(set_dataBits); +// +// BPA_SYSTEMSET set_parity = new BPA_SYSTEMSET(); +// set_parity.type = 22; +// set_parity.value =serialParity.getSelectedItem().toString(); +// set_parity.deviceID = ConfigName.getInstance().DeviceId; +// set_parity.userID = ConfigName.getInstance().user.userID; +// QueryDB.AddSystemset(set_parity); +// +// BPA_SYSTEMSET set_stopBits = new BPA_SYSTEMSET(); +// set_stopBits.type = 23; +// set_stopBits.value = serialStopBits.getSelectedItem().toString(); +// set_stopBits.deviceID = ConfigName.getInstance().DeviceId; +// set_stopBits.userID = ConfigName.getInstance().user.userID; +// QueryDB.AddSystemset(set_stopBits); +// } @Override public void onDestroy() { diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/Silos_item_jiaoyan_fragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/Silos_item_jiaoyan_fragment.java index 3eda2b21..271bbda4 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/Silos_item_jiaoyan_fragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/Silos_item_jiaoyan_fragment.java @@ -18,7 +18,7 @@ import androidx.annotation.Nullable; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; -import com.bonait.bnframework.business.deviceControl.seasonBar.PLCControl; +import com.bonait.bnframework.business.deviceControl.ScaleDevice; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.res.lcMode; @@ -369,7 +369,7 @@ public class Silos_item_jiaoyan_fragment extends LinearLayout { */ public void dzcql() { //ExecuteTheRecipe.WritePLC("重量清零", true, new IWriteCallBack() { - PLCControl.get().tare(new IWriteCallBack() { + ScaleDevice.get().tare(new IWriteCallBack() { @Override public void onSuccess() { ToastUtils.info("清零成功!"); diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_silos_ck.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_silos_ck.java index 9de03af8..19ec70d9 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_silos_ck.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/add_silos_ck.java @@ -24,12 +24,11 @@ import androidx.annotation.Nullable; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; -import com.bonait.bnframework.business.deviceControl.seasonBar.PLCControl; +import com.bonait.bnframework.business.deviceControl.PLCControl; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.mode.BPA_SILOSANDMATERIAL; import com.bonait.bnframework.common.db.res.lcMode; -import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.I.MyClickListener; import com.bonait.bnframework.common.utils.ToastUtils; import com.qmuiteam.qmui.widget.dialog.QMUIDialog; @@ -368,18 +367,20 @@ public class add_silos_ck extends LinearLayout { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { Log.e("鼠标", "按下: "); - ExecuteTheRecipe.WritePLC("手自切换", false, new IWriteCallBack() { - @Override - public void onSuccess() { - ExecuteTheRecipe.WritePLC("M_外置仓" + lcMode.num + "反转", true, null); - } - @Override - public void onFailure(String ErrorMsg) { - } - }); +// ExecuteTheRecipe.WritePLC("手自切换", false, new IWriteCallBack() { +// @Override +// public void onSuccess() { +// ExecuteTheRecipe.WritePLC("M_外置仓" + lcMode.num + "反转", true, null); +// } +// @Override +// public void onFailure(String ErrorMsg) { +// } +// }); + PLCControl.get().reverseMotor(lcMode.num,null); } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { Log.e("鼠标", "松开: "); - ExecuteTheRecipe.WritePLC("M_外置仓" + lcMode.num + "反转", false, null); + //ExecuteTheRecipe.WritePLC("M_外置仓" + lcMode.num + "反转", false, null); + PLCControl.get().stopRverseMotor(lcMode.num,null); } return false; } 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 8dc8ae6b..94c9c0d9 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,33 +2,25 @@ 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; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; +import com.bonait.bnframework.business.deviceControl.PLCControl; 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 +180,7 @@ public class fragment_plc_control extends LinearLayout { @Override public void onCheckedChanged(SwitchButton view, boolean isChecked) { boolean ischick= control_switch.isChecked(); - ExecuteTheRecipe.WritePLCForRTU(model.name,ischick,null); + PLCControl.get().writePLC(model.name,isChecked,null); ToastUtils.info("写入地址:"+model.address+"成功!状态:"+(ischick?"打开":"关闭")); } }); @@ -237,8 +229,14 @@ public class fragment_plc_control extends LinearLayout { // ExecuteTheRecipe.WritePLC(model.name,val,null); // } - ExecuteTheRecipe.WritePLCForRTU(model.name,text,null); - //TODO:修改手动写入操作代码。 + //ExecuteTheRecipe.WritePLCForRTU(model.name,text,null); + + switch (ConfigName.getInstance().versionSelectionEnum){ + case "调味吧台": + PLCControl.get().writePLC(model.name,Short.parseShort(text),null); + break; + } + ToastUtils.info("写入地址:"+model.address+"成功!"); break; diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java index 5cbb5936..6900332c 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/silos_jiaoyan.java @@ -22,8 +22,8 @@ import androidx.fragment.app.FragmentManager; import com.bonait.bnframework.R; import com.bonait.bnframework.business.ExecuteTheRecipe; -import com.bonait.bnframework.business.deviceControl.seasonBar.PLCControl; -import com.bonait.bnframework.business.deviceControl.seasonBar.ScaleDevice; +import com.bonait.bnframework.business.deviceControl.PLCControl; +import com.bonait.bnframework.business.deviceControl.ScaleDevice; import com.bonait.bnframework.common.constant.ConfigName; import com.bonait.bnframework.common.db.QueryDB; import com.bonait.bnframework.common.db.mode.BPA_SILOS; @@ -158,6 +158,13 @@ public class silos_jiaoyan extends LinearLayout { @BindView(R.id.txt_jljz_adjFreq) EditText txt_jljz_adjFreq; +// /**酱料校准反转时间输入框*/ +// @BindView(R.id.text_jljz_ftime1) +// EditText text_jljz_ftime1; + + /**酱料校准反转时间输入框*/ + @BindView(R.id.text_jljz_ftime) + EditText text_jljz_ftime; /**开始酱料校准*/ @BindView(R.id.btn_jljz_startAdj) Button btn_jljz_startAdj; @@ -444,6 +451,15 @@ public class silos_jiaoyan extends LinearLayout { wljz1.setText(time); wljz2.setText(ftime); wljz3.setText(jvalue); + text_jljz_ftime.setText(ftime); + + String minWeight=lcMode.minweight==null?"0.0":lcMode.minweight; + String maxWeight=lcMode.maxweight==null?"0.0":lcMode.maxweight; + String jFrequency=lcMode.jfrequency==null?"0.0":lcMode.jfrequency; + txt_jljz_lowLimit.setText(minWeight); + txt_jljz_highLimit.setText(maxWeight); + txt_jljz_adjFreq.setText(jFrequency); + String Gxs = lcMode.Gxs == null ? "0.0" : lcMode.Gxs; String Lxs = lcMode.Lxs == null ? "0.0" : lcMode.Lxs; @@ -603,6 +619,7 @@ public class silos_jiaoyan extends LinearLayout { //short kkk = (short) ((int) (zl * 10)); final int[] delayTime=new int[]{0}; + final int ftime=(int)(Double.parseDouble(lcMode.fTime)*1000); if (TypeName.equals("酱料校准")){ delayTime[0]=(int)(ExecuteTheRecipe.getDelayTimeByLCID(lcMode.id,zl)*1000); }else{ @@ -620,6 +637,19 @@ public class silos_jiaoyan extends LinearLayout { // ExecuteTheRecipe.WritePLC("手自切换", true, null); ExecuteTheRecipe.isAutoMode=false; + + if (lcMode.name.equals("外置仓")){ + PLCControl.get().openMotorAndReverse(lcMode.num, delayTime[0],ftime, new IWriteCallBack() { + @Override + public void onSuccess() { + ToastUtils.success("Start Simulation Success......"); + } + @Override + public void onFailure(String ErrorMsg) { + ToastUtils.error("Start Simulation Failure:"+ ErrorMsg); + } + }); + }else{ PLCControl.get().openMotorAndClose(lcMode.num, delayTime[0], new IWriteCallBack() { @Override public void onSuccess() { @@ -630,6 +660,8 @@ public class silos_jiaoyan extends LinearLayout { ToastUtils.error("Start Simulation Failure:"+ ErrorMsg); } }); + } + } catch (Exception e) { ToastUtils.error("Simulation Open:"+ e.getMessage()); } @@ -647,6 +679,7 @@ public class silos_jiaoyan extends LinearLayout { String highLimit=txt_jljz_highLimit.getText().toString().trim(); String lowLimit=txt_jljz_lowLimit.getText().toString().trim(); String text_adjFreq=txt_jljz_adjFreq.getText().toString().trim(); + String text_ftime=text_jljz_ftime.getText().toString().trim(); if (lowLimit.isEmpty() || lowLimit.equals("")){ ToastUtils.warning("校准范围下限不能为空!"); @@ -660,10 +693,15 @@ public class silos_jiaoyan extends LinearLayout { ToastUtils.warning("校准频率不能为空!"); return; } + if (text_ftime.isEmpty()||text_ftime.equals("")){ + ToastUtils.warning("反转时间不能为空!"); + return; + } final double weightLowLimit; final double weightHighLimit; final int adjFreq; + final double ftime; try { weightLowLimit=Double.parseDouble(lowLimit); @@ -683,6 +721,12 @@ public class silos_jiaoyan extends LinearLayout { ToastUtils.error("校准频率异常!" + e.getMessage()); return; } + try { + ftime=Double.parseDouble(text_ftime); + }catch (Exception e){ + ToastUtils.error("反转时间异常!" + e.getMessage()); + return; + } if (weightLowLimit<0 || (weightLowLimit>=weightHighLimit)){ ToastUtils.error("校准范围值异常,下限应大于0,且小于上限值!"); return; @@ -702,9 +746,13 @@ public class silos_jiaoyan extends LinearLayout { //HashMap outMaterialMap=new HashMap(); WeightedObservedPoints points=new WeightedObservedPoints(); - long startTime=System.currentTimeMillis(); + ToastUtils.info("开始酱料校准,时间较长,请耐心等待。"); + + //总共出料时间 和 开始时间。。 + final long[] time = {0,0}; while (currentWeight[0]<=weightHighLimit){ + //region 错误代码 // PLCControl.get().openMotorAndClose(lcMode.num, adjFreq * 1000, new IWriteCallBack() { // @Override // public void onSuccess() { @@ -721,22 +769,66 @@ public class silos_jiaoyan extends LinearLayout { // //ToastUtils.error("酱料校准开关电机错误,校准失败"); // } // }); +// PLCControl.get().openMotor(lcMode.num, new IWriteCallBack() { +// @Override +// public void onSuccess() { +// try { +// Thread.sleep(adjFreq*1000); +// PLCControl.get().closeMotor(lcMode.num, new IWriteCallBack() { +// @Override +// public void onSuccess() { +// currentWeight[0]=ExecuteTheRecipe.OutletWeigh/10.0; +// if (currentWeight[0]>=weightLowLimit){ +// //出料时间 +// long outTime=System.currentTimeMillis()-startTime; +// double time=((double)outTime)/1000; +// //outMaterialMap.put(time,currentWeight[0]); +// //方程式里,x是重量,Y才是时间 +// points.add(currentWeight[0],time); +// } +// } +// @Override +// public void onFailure(String ErrorMsg) { +// +// } +// }); +// } catch (Exception e) { +// ToastUtils.error("酱料校准错误 :"+e.getMessage()); +// } +// } +// @Override +// public void onFailure(String ErrorMsg) { +// +// } +// }); +//endregion + + PLCControl.get().openMotor(lcMode.num, new IWriteCallBack() { @Override public void onSuccess() { try { - Thread.sleep(adjFreq*1000); + time[1] = System.currentTimeMillis(); + Thread.sleep(adjFreq * 1000); PLCControl.get().closeMotor(lcMode.num, new IWriteCallBack() { @Override public void onSuccess() { - currentWeight[0]=ExecuteTheRecipe.OutletWeigh/10.0; - if (currentWeight[0]>=weightLowLimit){ + currentWeight[0] = ExecuteTheRecipe.OutletWeigh / 10.0; + if (currentWeight[0] >= weightLowLimit) { //出料时间 - long outTime=System.currentTimeMillis()-startTime; - double time=((double)outTime)/1000; - //outMaterialMap.put(time,currentWeight[0]); + long outTime = System.currentTimeMillis() - time[1]; + time[0] += outTime; + double allOutTime = ((double) time[0]) / 1000; //方程式里,x是重量,Y才是时间 - points.add(currentWeight[0],time); + points.add(currentWeight[0], allOutTime); + try { + if (lcMode.num <= 8) { + PLCControl.get().reverMotorAndClose(lcMode.num, (int) (ftime * 1000), null); + Thread.sleep((int)(ftime*1000)); + } + }catch (Exception e){ + ToastUtils.error("酱料校准错误 :"+e.getMessage()); + } } } @Override @@ -755,8 +847,6 @@ public class silos_jiaoyan extends LinearLayout { }); } - //没出错就保存。 - //String result= jzDataToString(outMaterialMap); activity.runOnUiThread(new Runnable() { @Override public void run() { @@ -786,6 +876,7 @@ public class silos_jiaoyan extends LinearLayout { QueryDB.UpdateSilosBcsfValue(lcMode.id,String.valueOf(weightLowLimit),String.valueOf(weightHighLimit),String.valueOf(adjFreq)); //QueryDB.UpdateSilosBcsfValue(lcMode.id, result); QueryDB.UpdateSilosBcsfValue(lcMode.id, Arrays.toString(coefficients)); + QueryDB.UpdateSilosJZTime(lcMode.id,"0",text_ftime); //ToastUtils.success("酱料校准结果保存成功!"); MessageLog.ShowUserMessage(UserLogEnum.角色操作日志,lcMode.num+"仓位酱料校准结果保存成功。"); } @@ -809,7 +900,7 @@ public class silos_jiaoyan extends LinearLayout { } } }).start(); - ToastUtils.info("需求值下发成功!开始配料......"); + ToastUtils.info("开始校准......"); } //endregion @@ -897,9 +988,7 @@ public class silos_jiaoyan extends LinearLayout { //region 物料校准 public void WLJZ() { - //TODO:重写物料校准。 - - //region 物料校准--可提取为内部方法 + //region 物料校准 String stime = wljz1.getText().toString(); String ftime = wljz2.getText().toString(); diff --git a/app/src/main/res/layout/activity_systemparameter.xml b/app/src/main/res/layout/activity_systemparameter.xml index 7332631f..2c0423f6 100644 --- a/app/src/main/res/layout/activity_systemparameter.xml +++ b/app/src/main/res/layout/activity_systemparameter.xml @@ -71,6 +71,7 @@ + diff --git a/app/src/main/res/layout/fragment_make_good.xml b/app/src/main/res/layout/fragment_make_good.xml index 0c96e8f5..77acc3b4 100644 --- a/app/src/main/res/layout/fragment_make_good.xml +++ b/app/src/main/res/layout/fragment_make_good.xml @@ -135,6 +135,20 @@ android:text="正常" android:textColor="@color/green_primary" android:textSize="@dimen/TitleSize" /> + + - @@ -547,6 +547,27 @@ android:textSize="12dp" android:layout_marginBottom="10dp" /> + +