diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b3ec7717..6e0ab20a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -47,10 +47,10 @@ android:name=".modules.home.fragment.from.fragment.SystemCsFltlFragment" android:exported="false" /> testComms = new ConcurrentLinkedQueue<>(); - - public void testAddComm(int value) { - testComms.offer(value); - } - - public void TestInit() { - ThreadManager.Get().StartLong("TestInit", true, new IThread() { - @Override - public void Run() throws InterruptedException { - while (testComms.size() > 0) { - Thread.sleep(5000); - if (OnChargeMixtureComNotPar != null) { - OnChargeMixtureComNotPar.Run(testComms.poll()); - } - } - Thread.sleep(100); - } - - @Override - public void RunComplete() throws InterruptedException { - - } - }); - ; - } - //----------------------------------------------------------------End 模拟测试 ---------------------------------------------------------------- - - //region 初始化 - public void Init() { - ThreadManager.Get().StartLong("Plc设备数据监听", true, new IThread() { - @Override - public void Run() throws InterruptedException { - -// //获取校准值-增加两个果糖通道 -// ModbusTcpServer.get().ReadShort("VW100", 12, (shorts) -> { -// for (int i = 0; i < shorts.length; i++) { -// CalibrationValue.put(i + 1, shorts[i]); -// } -// }); -// -// //获取称当前重量 -// ModbusTcpServer.get().ReadInt("VD260", 9, ints -> { -// for (int i = 0; i < ints.length; i++) { -// CallCurrentWeight.put(i + 1, ints[i]); -// } -// }); -// -// //获取温度参数 -// ModbusTcpServer.get().ReadInt("VD310", 3, ints -> { -// FructoseTemperature1=ints[0]; -// FructoseTemperature2=ints[1]; -// WashTheTankTemperature=ints[2]; -// }); -// -// -// //获取清洗参数 -// ModbusTcpServer.get().ReadShort("VW140", 5, shorts -> { -// DrainageTime = shorts[0]; -// AddCleaningAgentTime = shorts[1]; -// InletTime = shorts[2]; -// CyclicCleaningTime = shorts[3]; -// CleaningAndHeatingTime = shorts[4]; -// }); -// -// //获取清洗参数 -// ModbusTcpServer.get().ReadBool("M6.5", 1, booleans -> { -// WeightCalibrationMode = booleans[0]; -// }); -// -// ModbusTcpServer.get().ReadBool("M6.5", 1, booleans -> { -// WeightCalibrationMode = booleans[0]; -// }); -// //IoStatus -// -// -// //读取当前扫码信息 -// ModbusTcpServer.get().ReadString("VW342", 20, (data) -> { -// -// if(!Code.equals(data)) -// { -// if(!data.isEmpty() && OnScanTheCodeInformationT!=null) -// { -// MessageLog.ShowInfo("当前扫码信息:"+data); -// OnScanTheCodeInformationT.Run(data); -// } -// Code=data; -// } -// //1.查询订单信息 -// //2.展示订单界面 -// //3.制作订单信息 -// //4.回馈订单信息 -// }); -// -// //读取实时状态 -// ModbusTcpServer.get().ReadStatus("VW382", 3, data -> { -// for (int i = 0; i < data.length; i++) { -// byte status=data[i];//0x92 -// IoStatus.put(i*8+0, ByteHelper.getBit(status,0)==1); -// IoStatus.put(i*8+1, ByteHelper.getBit(status,1)==1); -// IoStatus.put(i*8+2, ByteHelper.getBit(status,2)==1); -// IoStatus.put(i*8+3, ByteHelper.getBit(status,3)==1); -// IoStatus.put(i*8+4, ByteHelper.getBit(status,4)==1); -// IoStatus.put(i*8+5, ByteHelper.getBit(status,5)==1); -// IoStatus.put(i*8+6, ByteHelper.getBit(status,6)==1); -// IoStatus.put(i*8+7, ByteHelper.getBit(status,7)==1); -// } -// }); -// -// //配料完成 M0.3 -// CompleteListen("M0.3", "配料完成", OnChargeMixtureCompleteNotify); -// -// //清洗完成 M0.6 -// CompleteListen("M0.6", "清洗完成", OnCleaningCompleteNotify); -// -// //去皮完成 M1.3 -// CompleteListen("M1.3", "去皮完成", OnPeelingCompleteNotify); - - Thread.sleep(10); - } - - @Override - public void RunComplete() throws InterruptedException { - - } - }); - } - //endregion - /** - * 扫码信息 - */ - public String Code=""; - //region 完成信号监听 - - /** - * 完成信号监听 - * - * @param add 监听地址 - * @param name 监听 KEY - * @param callback 执行委托 - */ - private void CompleteListen(String add, String name, IRun callback) { - ModbusTcpServer.get().ReadBool(add, 1, booleans -> { - RTrig.get(name).Start(booleans[0], () -> { - if (callback != null) - callback.Run(); - }); - }); - } - //endregion - - // region 通知接口 - /** - * 配料完成通知 - */ - public IRun OnChargeMixtureCompleteNotify; - - /** - * 通道配料完成通知 - */ - public IRunT OnChargeMixtureComNotPar; - - /** - * 清洗完成通知 - */ - public IRun OnCleaningCompleteNotify; - - /** - * 去皮完成 - */ - public IRun OnPeelingCompleteNotify; - - /** - * 接收到扫码信息 - */ - public IRun OnScanTheCodeInformation; - /** - * 接收到扫码信息,返回 - */ - public IRunT OnScanTheCodeInformationT; - //endregion - - /** - * 校准值写入 - * PLC 地址VW100--VW118 - * - * @param value 需要写入的值 - * @param ch 需要写入的通道编号,1--10 - */ - public void setCalibrationValue(short value, int ch, IWriteCallBack callback) { - if (ch >= 1 && ch <= 12) { - String add = "VW" + (98 + ch * 2); - ModbusTcpServer.get().WriteShort(add, value, callback); - } - } - - /** - * 校准值 - */ - ConcurrentHashMap CalibrationValue = new ConcurrentHashMap<>(); - - /** - * 获取校准值 - * - * @param ch 要获取的通道号 - * @return - */ - public short getCalibrationValue(int ch) { - if (!CalibrationValue.containsKey(ch)) - return 0; - return CalibrationValue.get(ch); - } - - /** - * 需求值写入 - * ,PLC 地址 VW200--VW218 - * - * @param value 需要写入的值 - * @param ch 需要写入的通道编号,1--10 - */ - public void setDemandValue(short value, int ch, IWriteCallBack callback) { - if (ch >= 1 && ch <= 10) { - String add = "VW" + (198 + ch * 2); - ModbusTcpServer.get().WriteShort(add, value, callback); - }else if(ch>=11 && ch<=12)//果糖需求 - { - String add = "VW" + (198 +20+ ch * 2); - ModbusTcpServer.get().WriteShort(add, value, callback); - } - } - - /** - * 设置通道校准开关 - * ,PLC 地址 M2.0--M3.1 - * - * @param value 需要写入的值 - * @param ch 需要写入的通道编号,1--10 - */ - public void setChCalibrationSwitch(boolean value, int ch, IWriteCallBack callback) { - if (ch >= 1 && ch <= 12) { - String add=""; - if(ch==9) - { - add="M03.0"; - }else if(ch==10) - { - add="M03.1"; - }else if(ch==11)//果糖1 - { - add="M03.2"; - }else if(ch==12)//果糖2 - { - add="M03.3"; - }else - { - add = ModbusTcpServer.get().getBitSingleAdd("M", 2, ch); - } - - if (add.length() > 0) - ModbusTcpServer.get().WriteBool(add, value, callback); - } - } - - //region 手动控制 - /** - * 手动控制设备 - * @param value - * @param ch - * @param callback - */ - public void setSwitch(boolean value, String ch, IWriteCallBack callback) { - if(ch.isEmpty()) - { - return; - } - String add=ch; - if (add.length() > 0) - ModbusTcpServer.get().WriteBool(add, value, callback); - } - //endregion - - - /** - * 称去皮校准 - * - * @param value - * @param ch 设置称的通道号,ch1-ch8 - */ - public void setRemovePeelCalibration(boolean value, int ch, IWriteCallBack callback) { - if (ch >= 1 && ch <= 8) { - String add = ModbusTcpServer.get().getBitSingleAdd("M", 5, ch); - if (add.length() > 0) - ModbusTcpServer.get().WriteBool(add, value, callback); - } - } - - /** - * 砝码值写入 - * - * @param value - * @param ch 设置称的砝码通道号,ch1-ch8 - */ - public void setWeightValue(boolean value, int ch, IWriteCallBack callback) { - if (ch >= 1 && ch <= 8) { - String add = ModbusTcpServer.get().getBitSingleAdd("M", 15, ch); - if (add.length() > 0) - ModbusTcpServer.get().WriteBool(add, value, callback); - } - } - - /** - * 重量清零 - */ - public void setWeightClear(IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M6.0", true, callback); - } - - /** - * 关闭写保护 - */ - public void setCloseWriteProtect(IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M6.1", true, callback); - } - - /** - * 打开写保护 - */ - public void setOpenWriteProtect(IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M6.4", true, callback); - } - - /** - * 零点校准 - */ - public void setZeroPointCalibration(IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M6.2", true, callback); - } - - /** - * 砝码值写入 - */ - public void setWeightValueWrite(IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M6.3", true, callback); - } - - /** - * 砝码校准模式 - */ - boolean WeightCalibrationMode; - - /** - * 砝码校准模式 - */ - public void setWeightCalibrationMode(Boolean value, IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M6.5", value, callback); - } - - /** - * 获取砝码校准模式 - * - * @return - */ - public boolean getWeightCalibrationMode() { - return WeightCalibrationMode; - } - - /** - * 启动通道校准 - */ - public void setChStartCalibration(IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M0.0", true, callback); - } - - /** - * 启动配料 - */ - public void setChargeMixtureStart(IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M0.1", true, callback); - } - - /** - * 手自动切换 - * - * @param value true:自动模式,flase:手动模式 - */ - public void setHandOrAutoSwitch(boolean value, IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M0.2", value, callback); - } - - /** - * 手自动模式 - */ - boolean HandOrAutoMode; - - /** - * 获取手自动模式的状态 - * - * @return true:自动模式,flase:手动模式 - */ - public boolean getHandOrAutoSwitch() { - return HandOrAutoMode; - } - - /** - * 设置清洗模式 - * - * @param value true:清洗模式,false:配料模式 - */ - public void setCleaningMode(boolean value, IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M0.4", value, callback); - } - - /** - * 清洗模式 - */ - boolean CleaningMode; - - /** - * 获取清洗模式 - * - * @return true:清洗模式,false:配料模式 - */ - public boolean getCleaningMode() { - return CleaningMode; - } - - /** - * 设置开始清洗 - */ - public void setStartCleaning(IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M0.5", true, callback); - } - - /** - * 设置一键去皮 - */ - public void setOneClickPeeling(IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M1.2", true, callback); - } - - /** - * 一键去皮完成状态 - */ - boolean OneClickPeelingComplete; - - /** - * 设置一键去皮完成状态 - * - * @param value - */ - public void setOneClickPeelingComplete(boolean value) { - OneClickPeelingComplete = value; - } - - /** - * 清洗完成 - */ - boolean CleaningComplete; - - /** - * 获取清洗完成的状态 - * - * @return - */ - public boolean getCleaningComplete() { - return CleaningComplete; - } - - //region 获取或设置-校准模式 - - /** - * 设置校准模式 - * - * @param value true:零点校准模式,false:清零去皮模式 - */ - public void setCalibrationMode(boolean value, IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M1.4", value, callback); - } - - /** - * 校准模式 - */ - boolean CalibrationMode; - - /** - * 获取校准模式 - * - * @return true:零点校准模式,false:清零去皮模式 - */ - public boolean getCalibrationMode() { - return CalibrationMode; - } - - //endregion - - - - /** - * 称当前重量 - */ - ConcurrentHashMap CallCurrentWeight = new ConcurrentHashMap(); - - /** - * 获取指定称的当前重量 - * - * @param ch 需要获取的通道号,称1--称9 - * @return - */ - public int getCallCurrentWeight(int ch) { - if (!CallCurrentWeight.containsKey(ch)) { - return 0; - } - return CallCurrentWeight.get(ch); - } - - //region 获取或设置-校准基准时间 - - /** - * 设置校准基准时间 - * - * @param value 需要写入的值 - */ - public void setCalibrationReferenceTime(int value, IWriteCallBack callback) { - ModbusTcpServer.get().WriteInt("VD124", value, callback); - } - - /** - * 校准基准时间 - */ - int CalibrationReferenceTime=0; - - /** - * 获取校准基准时间 - * - * @return - */ - public int getCalibrationReferenceTime() { - return CalibrationReferenceTime; - } - - //endregion - - //region 获取或设置-排水时间 - - /** - * 设置排水时间 - * - * @param value - */ - public void setDrainageTime(short value, IWriteCallBack callback) { - ModbusTcpServer.get().WriteShort("VW140", value, callback); - } - - /** - * 排水时间 - */ - short DrainageTime; - - /** - * 获取排水时间 - * - * @return - */ - public short getDrainageTime() { - return DrainageTime; - } - - //endregion - - //region 获取或设置-清洗剂添加时间 - - /** - * 设置清洗剂添加时间 - * - * @param value - */ - public void setAddCleaningAgentTime(short value, IWriteCallBack callback) { - ModbusTcpServer.get().WriteShort("VW142", value, callback); - } - - /** - * 清洗剂添加时间 - */ - short AddCleaningAgentTime; - - /** - * 获取清洗剂添加时间 - * - * @return - */ - public short getAddCleaningAgentTime() { - return AddCleaningAgentTime; - } - - //endregion - - //region 获取或设置-进水时间 - - /** - * 设置进水时间 - * - * @param value - */ - public void setInletTime(short value, IWriteCallBack callback) { - ModbusTcpServer.get().WriteShort("VW144", value, callback); - } - - /** - * 进水时间 - */ - short InletTime; - - /** - * 获取进水时间 - * - * @return - */ - public short getInletTime() { - return InletTime; - } - - //endregion - - //region 获取或设置-循环清洗时间 - - /** - * 设置循环清洗时间 - * - * @param value - */ - public void setCyclicCleaningTime(short value, IWriteCallBack callback) { - ModbusTcpServer.get().WriteShort("VW146", value, callback); - } - - /** - * 循环清洗时间 - */ - short CyclicCleaningTime; - - /** - * 获取循环清洗时间 - * - * @return - */ - public short getCyclicCleaningTime() { - return CyclicCleaningTime; - } - //endregion - - //region 获取或设置-清洗加热时间 - - /** - * 设置清洗加热时间 - * - * @param value - */ - public void setCleaningAndHeatingTime(short value, IWriteCallBack callback) { - ModbusTcpServer.get().WriteShort("VW148", value, callback); - } - - /** - * 清洗加热时间 - */ - short CleaningAndHeatingTime; - - /** - * 获取清洗加热时间 - * - * @return - */ - public short getCleaningAndHeatingTime() { - return CleaningAndHeatingTime; - } - //endregion - - //region 获取温度信息 - /** - * 果糖1实际温度 - */ - Boolean ReheatSwitch1=false; - int FructoseTemperature1=0; - int FructoseTemperature1_up=0; - int FructoseTemperature1_down=0; - /** - * 设置果糖1号加热启动停止 - * - * @param value true:启动,flase:停止 - */ - public void setReheatSwitch1(boolean value, IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M51.7", value, callback); - } - public boolean getReheatSwitch1() { - return ReheatSwitch1; - } - /** - * 设置获取果糖1上下线 - * @param value_up 上限 - * @param value_down 下限 - * @param callback - */ - public void setFructoseTemperature1(int value_up,int value_down, IWriteCallBack callback) { - ModbusTcpServer.get().WriteInt("VD388", value_up, callback); - ModbusTcpServer.get().WriteInt("VD392", value_down, callback); - } - /** - * 获取果糖1实际温度 - * - * @return - */ - public int getFructoseTemperature1() { - return FructoseTemperature1; - } - /** - * 获取果糖1上限 - * - * @return - */ - public int getFructoseTemperature1_up() { - return FructoseTemperature1_up; - } - /** - * 获取果糖1下限 - * - * @return - */ - public int getFructoseTemperature1_down() { - return FructoseTemperature1_down; - } - /** - * 果糖2实际温度 - */ - Boolean ReheatSwitch2=false; - int FructoseTemperature2=0; - int FructoseTemperature2_up=0; - int FructoseTemperature2_down=0; - /** - * 设置果糖2号加热启动停止 - * - * @param value true:启动,flase:停止 - */ - public void setReheatSwitch2(boolean value, IWriteCallBack callback) { - ModbusTcpServer.get().WriteBool("M52.0", value, callback); - } - public boolean getReheatSwitch2() { - return ReheatSwitch2; - } - /** - * 设置获取果糖2上下线 - * @param value_up 上限 - * @param value_down 下限 - * @param callback - */ - public void setFructoseTemperature2(int value_up,int value_down, IWriteCallBack callback) { - ModbusTcpServer.get().WriteInt("VD396", value_up, callback); - ModbusTcpServer.get().WriteInt("VD400", value_down, callback); - } - /** - * 获取果糖2实际温度 - * - * @return - */ - public int getFructoseTemperature2() { - return FructoseTemperature2; - } - /** - * 获取果糖2上限 - * - * @return - */ - public int getFructoseTemperature2_up() { - return FructoseTemperature2_up; - } - /** - * 获取果糖2下限 - * - * @return - */ - public int getFructoseTemperature2_down() { - return FructoseTemperature2_down; - } - /** - * 清洗池实际温度 - */ - int WashTheTankTemperature=0; - int WashTheTankTemperature_up=0; - int WashTheTankTemperature_down=0; - /** - * 设置清洗池实际温度上下线 - * @param value_up 上限 - * @param value_down 下限 - * @param callback - */ - public void setWashTheTankTemperature(int value_up,int value_down, IWriteCallBack callback) { - ModbusTcpServer.get().WriteInt("VD404", value_up, callback); - ModbusTcpServer.get().WriteInt("VD408", value_down, callback); - } - /** - * 清洗池实际温度 - * - * @return - */ - public int getWashTheTankTemperature() { - return WashTheTankTemperature; - } - /** - * 获取清洗池实际温度上限 - * - * @return - */ - public int getWashTheTankTemperature_up() { - return WashTheTankTemperature_up; - } - /** - * 获取清洗池实际温度下限 - * - * @return - */ - public int getWashTheTankTemperature_down() { - return WashTheTankTemperature_down; - } - //endregion - - //region 实时状态 - /** - * 实时状态 - */ - public ConcurrentHashMap IoStatus = new ConcurrentHashMap(); - /** - * 获取实时状态 - * @param ch - * @return - */ - public boolean getConcurrentHash(int ch) { - if (!IoStatus.containsKey(ch)) { - return false; - } - return IoStatus.get(ch); - } - //endregion - /** - * 设置8路称校准砝码重量 - * - * @param value - */ - public void setCalibrationWeight(short value, IWriteCallBack callback) { - ModbusTcpServer.get().WriteShort("VW250", value, callback); - } - - /** - * 设置称重9校准砝码重量 - * - * @param value - */ - public void setCalibrationWeight9(short value, IWriteCallBack callback) { - ModbusTcpServer.get().WriteShort("VW254", value, callback); - } - - /** - * 扫码清零 - */ - public void setCodeClear(IWriteCallBack callback) { - ModbusTcpServer.get().WriteString("VW342", 20, callback); - } -} 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 69d38460..294f0515 100644 --- a/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java +++ b/app/src/main/java/com/bonait/bnframework/business/ExecuteTheRecipe.java @@ -12,6 +12,7 @@ import com.bonait.bnframework.common.db.mode.BPA_GOODSRECIPE; import com.bonait.bnframework.common.db.mode.BPA_MATERIAL; import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; import com.bonait.bnframework.common.db.mode.BPA_SILOS; +import com.bonait.bnframework.common.helper.ByteHelper; import com.bonait.bnframework.common.helper.I.IThread; import com.bonait.bnframework.common.helper.I.IWriteCallBack; import com.bonait.bnframework.common.helper.ThreadManager; @@ -556,10 +557,12 @@ public class ExecuteTheRecipe { ListeningValue.put(key, val); } } + + ReadPLCStatus(); } catch (Exception ex) { ToastUtils.error("异常信息:" + ex.getMessage()); } - Thread.sleep(10); + Thread.sleep(100); } @Override @@ -638,6 +641,68 @@ public class ExecuteTheRecipe { return ReturnsVariable[0]; } } + + /** + * 实时状态 + */ + public static ConcurrentHashMap IoStatus = new ConcurrentHashMap(); + /** + * 获取实时状态 + * @param ch + * @return + */ + public static boolean getConcurrentHash(int ch) { + if (!IoStatus.containsKey(ch)) { + return false; + } + return IoStatus.get(ch); + } + + /** + * 获取搅拌电机 + * @param + * @return + */ + public static int getConcurrentHash_dj(String name) { + if (!ListeningValue.containsKey(name)) { + return 0; + } + Object obj= ListeningValue.get(name); + if(obj==null) + { + return 0; + }else + { + return (int)obj; + } + } + + /** + * 读取状态 + */ + public static void ReadPLCStatus() + { + try { + if (ConfigName.getInstance().PlcIsConnect) { + ModbusTcpServer.get().ReadStatus("VW354", 1, data -> { + for (int i = 0; i < data.length; i++) { + byte status=data[i];//0x92 + IoStatus.put(i*8+0, ByteHelper.getBit(status,0)==1); + IoStatus.put(i*8+1, ByteHelper.getBit(status,1)==1); + IoStatus.put(i*8+2, ByteHelper.getBit(status,2)==1); + IoStatus.put(i*8+3, ByteHelper.getBit(status,3)==1); + IoStatus.put(i*8+4, ByteHelper.getBit(status,4)==1); + IoStatus.put(i*8+5, ByteHelper.getBit(status,5)==1); + IoStatus.put(i*8+6, ByteHelper.getBit(status,6)==1); + IoStatus.put(i*8+7, ByteHelper.getBit(status,7)==1); + } + }); + } + } catch (Exception ex) { + ToastUtils.error("异常信息:" + ex.getMessage()); + } finally { + } + } //endregion //region 获取基础挡位变量 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 c0f240ad..08fe7683 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 @@ -2,9 +2,11 @@ package com.bonait.bnframework.common.constant; import android.content.Context; +import com.bonait.bnframework.R; import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; import com.bonait.bnframework.common.db.mode.BPA_USER; import com.bonait.bnframework.common.db.mode.Res_PLCADDRESS; +import com.bonait.bnframework.common.db.res.StatusMode; import com.bonait.bnframework.common.model.AddrType; import com.bonait.bnframework.common.model.mode.DeviceInformation; import com.bonait.bnframework.common.model.mode.OrganizeMode; @@ -372,6 +374,55 @@ public class ConfigName { put("四档",8); put("五档",10); }}; + /** + * 状态上报信息 + */ + public List statusModes=new ArrayList(){{ + + //硬件设备 初始化 + add(new StatusMode("急停",false,R.mipmap.jiting,R.mipmap.jiting,0)); + add(new StatusMode("炒锅正限位报警",false,R.mipmap.cg_sxw,R.mipmap.cg_sxw,2)); + add(new StatusMode("炒锅负限位报警",false,R.mipmap.cgxxw,R.mipmap.cgxxw,3)); + add(new StatusMode("编码器通讯异常",false,R.mipmap.bmq,R.mipmap.bmq,4)); + add(new StatusMode("搅拌电机变频器通讯异常",false,R.mipmap.bpq,R.mipmap.bpq,6)); + add(new StatusMode("翻转电机变频器通讯异常",false,R.mipmap.bpq,R.mipmap.bpq,7)); + }}; + + /** + * 状态上报信息 + */ + public ConcurrentHashMap statusModes_电机=new ConcurrentHashMap() + {{ + put(0 ,"无故障"); + put(1 ,"过电流"); + put(2 ,"过电压"); + put(3 ,"IGBT过热"); + put(4 ,""); + put(5 ,"变频器过负载"); + put(6 ,"电机过负载"); + put(7 ,"过转矩"); + put(8 ,"外部异常"); + put(9 ,"加速中过电流"); + put(10,"减速中过电流"); + put(11,"恒速中过电流"); + put(12,""); + put(13,"电压不足"); + put(14,"输入电压缺相"); + put(15,""); + put(16,"不适用自动加减速设定"); + put(17,"软件参数密码保护"); + put(18,"CPU写入异常"); + put(19,"CPU读取异常"); + put(20,"端子保护线路异常"); + put(21,"0V保护线路异常"); + put(22,""); + put(23,""); + put(24,"U相硬件异常"); + put(25,"V相硬件异常"); + put(26,"W相硬件异常"); + put(27,"DC,bus 硬件异常"); + + }}; //endregion } 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 e958052a..cdeefe87 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 @@ -268,10 +268,6 @@ public class DataBus { * 订单操作日志 */ public List bpa_alertlogs = new ArrayList(); - /** - * 设备状态列表 - */ - public List statusModes = new ArrayList(); /** * 扫码订单 */ diff --git a/app/src/main/java/com/bonait/bnframework/common/db/res/StatusMode.java b/app/src/main/java/com/bonait/bnframework/common/db/res/StatusMode.java index 3f049cf4..bf6187d0 100644 --- a/app/src/main/java/com/bonait/bnframework/common/db/res/StatusMode.java +++ b/app/src/main/java/com/bonait/bnframework/common/db/res/StatusMode.java @@ -9,11 +9,15 @@ public class StatusMode { public int Url_open; public int Url_close; - public StatusMode(String name,int Url_open,int Url_close,Boolean Status) + public int sort; + + public StatusMode(String name,Boolean Status,int Url_open,int + Url_close,int sort) { this.Name=name; this.Status=Status; this.Url_open=Url_open; this.Url_close=Url_close; + this.sort=sort; } } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/adapter/monitor_adapter.java b/app/src/main/java/com/bonait/bnframework/modules/home/adapter/monitor_adapter.java new file mode 100644 index 00000000..32d9e6a1 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/adapter/monitor_adapter.java @@ -0,0 +1,125 @@ +package com.bonait.bnframework.modules.home.adapter; + +import android.app.Activity; +import android.content.Context; +import android.content.ContextWrapper; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.bonait.bnframework.R; +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.db.res.lcMode; +import com.bonait.bnframework.common.utils.AlertDialogUtils; +import com.qmuiteam.qmui.widget.dialog.QMUIDialog; +import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; +import com.qmuiteam.qmui.widget.textview.QMUILinkTextView; + +import java.util.List; + +public class monitor_adapter extends RecyclerView.Adapter { + + private final LayoutInflater mLayoutInflater; + + private Context context; + + List statusModes = ConfigName.getInstance().statusModes; + + public monitor_adapter(Context context) { + this.context = context; + mLayoutInflater = LayoutInflater.from(context); + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View inflate = mLayoutInflater.inflate(R.layout.devstatus, parent, false); + return new MyLCViewHolder(inflate); + + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + try { + if (holder instanceof MyLCViewHolder) { + MyLCViewHolder myViewHolder = (MyLCViewHolder) holder; + StatusMode statusMode= statusModes.get(position); + myViewHolder.title.setText(statusMode.Name); + if(statusMode.Status) + { + myViewHolder.image.setImageResource(statusMode.Url_open); + myViewHolder.text.setText("打开"); + myViewHolder.text.setTextColor(context.getResources().getColor(R.color.black)); + }else + { + myViewHolder.image.setImageResource(statusMode.Url_close); + myViewHolder.text.setText("关闭"); + myViewHolder.text.setTextColor(context.getResources().getColor(R.color.red_primary)); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private Activity findActivity(@NonNull Context context) { + if (context instanceof Activity) { + return (Activity) context; + } else if (context instanceof ContextWrapper) { + return findActivity(((ContextWrapper) context).getBaseContext()); + } else { + return null; + } + } + + /** + * 刷新 + * + * @param + */ + public void refresh() { + Activity activity = findActivity(context); + if (activity != null) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + try { + notifyDataSetChanged(); + } catch (Exception e) { + + } + } + }); + } + } + + @Override + public int getItemCount() { + return statusModes.size(); + } + + public static class MyLCViewHolder extends RecyclerView.ViewHolder { + /** + * 标题 + */ + TextView title; + ImageView image; + /** + * 描述 + */ + TextView text; + public MyLCViewHolder(View view) { + super(view); + title = (TextView) view.findViewById(R.id.title); + text=(TextView) view.findViewById(R.id.text); + image= view.findViewById(R.id.image); + } + } +} diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/WhActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/WhActivity.java index 82e2c767..32dce487 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/WhActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/WhActivity.java @@ -4,9 +4,9 @@ import androidx.annotation.NonNull; import com.bonait.bnframework.modules.home.fragment.from.fragment.SystemCsPLCFragment; import com.google.android.material.bottomnavigation.BottomNavigationView; -import androidx.core.content.ContextCompat; + import androidx.viewpager.widget.ViewPager; -import androidx.appcompat.app.AppCompatActivity; + import android.os.Bundle; import android.view.MenuItem; import android.view.View; @@ -15,8 +15,8 @@ import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseActivity; import com.bonait.bnframework.modules.home.adapter.FragmentAdapter; import com.bonait.bnframework.modules.home.fragment.from.fragment.SystemCsFltlFragment; -import com.bonait.bnframework.modules.home.fragment.from.fragment.SystemCsJrFragment; -import com.bonait.bnframework.modules.home.fragment.from.fragment.SystemCsTlFragment; +import com.bonait.bnframework.modules.home.fragment.from.fragment.SystemCsControlFragment; +import com.bonait.bnframework.modules.home.fragment.from.fragment.SystemCsMonitorFragment; import com.qmuiteam.qmui.widget.QMUITopBar; import com.qmuiteam.qmui.widget.QMUIViewPager; @@ -67,8 +67,8 @@ public class WhActivity extends BaseActivity { fragmentAdapter = new FragmentAdapter(getSupportFragmentManager()); fragmentAdapter.addFragment(new SystemCsPLCFragment()); - fragmentAdapter.addFragment(new SystemCsJrFragment()); - fragmentAdapter.addFragment(new SystemCsTlFragment()); + fragmentAdapter.addFragment(new SystemCsControlFragment()); + fragmentAdapter.addFragment(new SystemCsMonitorFragment()); fragmentAdapter.addFragment(new SystemCsFltlFragment()); viewPager.setAdapter(fragmentAdapter); } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsControlFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsControlFragment.java new file mode 100644 index 00000000..2090ae8b --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsControlFragment.java @@ -0,0 +1,110 @@ +package com.bonait.bnframework.modules.home.fragment.from.fragment; + +import android.app.Activity; +import android.content.Context; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import android.content.ContextWrapper; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.LinearLayout; + +import com.bonait.bnframework.R; +import com.bonait.bnframework.common.base.BaseFragment; +import com.bonait.bnframework.common.db.QueryDB; +import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; +import com.bonait.bnframework.modules.home.fragment.mode.fragment_plc; +import com.bonait.bnframework.modules.home.fragment.mode.fragment_plc_control; +import com.orhanobut.logger.Logger; + +import java.util.ArrayList; + +import butterknife.BindView; +import butterknife.ButterKnife; + +/** + * PLC控制 + */ +public class SystemCsControlFragment extends BaseFragment { + private Context context; + @BindView(R.id.plcview) + LinearLayout plcview;//工序子集 + @Override + protected View onCreateView() { + View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_system_cs_control, null); + ButterKnife.bind(this, root); + return root; + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + Logger.d("我的fragment创建"); + context = getContext(); + Init(); + } + /** + * 初始化 + */ + public void Init() { + plcview.removeAllViews(); + ArrayList arrayList = QueryDB.GetPlcaddressALL(); + new Thread(new Runnable() { + @Override + public void run() { + try { + Activity activity = findActivity(context); + if (activity != null) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + try { + for (BPA_PLCADDRESS item : arrayList) { + fragment_plc_control gongxu = new fragment_plc_control(context, null, item); + plcview.addView(gongxu); + } + } catch (Exception e) { + + } + } + }); + } + } catch (Exception e) { + + } + } + }).start(); + + } + + private Activity findActivity(@NonNull Context context) { + if (context instanceof Activity) { + return (Activity) context; + } else if (context instanceof ContextWrapper) { + return findActivity(((ContextWrapper) context).getBaseContext()); + } else { + return null; + } + } + @Override + public void onDestroy() { + super.onDestroy(); + Logger.d("我的fragment销毁"); + } + + /** + * 当在activity设置viewPager + BottomNavigation + fragment时, + * 为防止viewPager左滑动切换界面,与fragment左滑返回上一界面冲突引起闪退问题, + * 必须加上此方法,禁止fragment左滑返回上一界面。 + * + * 切记!切记!切记!否则会闪退! + * + * 当在fragment设置viewPager + BottomNavigation + fragment时,则不会出现这个问题。 + */ + @Override + protected boolean canDragBack() { + return false; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsFltlFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsFltlFragment.java index 42e3f30d..821afc05 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsFltlFragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsFltlFragment.java @@ -1,22 +1,35 @@ package com.bonait.bnframework.modules.home.fragment.from.fragment; +import android.app.Activity; import android.content.Context; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; + +import android.content.ContextWrapper; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; +import android.widget.LinearLayout; import com.bonait.bnframework.R; import com.bonait.bnframework.common.base.BaseFragment; +import com.bonait.bnframework.common.db.QueryDB; +import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; +import com.bonait.bnframework.common.db.mode.BPA_SILOS; +import com.bonait.bnframework.modules.home.fragment.mode.fragment_plc_control; +import com.bonait.bnframework.modules.home.fragment.mode.fragment_silos_cl; import com.orhanobut.logger.Logger; +import java.util.ArrayList; + +import butterknife.BindView; import butterknife.ButterKnife; public class SystemCsFltlFragment extends BaseFragment { - + @BindView(R.id.plcview) + LinearLayout plcview;//工序子集 private Context context; @Override protected View onCreateView() { @@ -30,8 +43,51 @@ public class SystemCsFltlFragment extends BaseFragment { super.onViewCreated(view, savedInstanceState); Logger.d("我的fragment创建"); context = getContext(); + Init(); + } + /** + * 初始化 + */ + public void Init() { + plcview.removeAllViews(); + ArrayList arrayList = QueryDB.GetSilosALL(); + new Thread(new Runnable() { + @Override + public void run() { + try { + Activity activity = findActivity(context); + if (activity != null) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + try { + for (BPA_SILOS item : arrayList) { + fragment_silos_cl gongxu = new fragment_silos_cl(context, null, item); + plcview.addView(gongxu); + } + } catch (Exception e) { + + } + } + }); + } + } catch (Exception e) { + + } + } + }).start(); + } + private Activity findActivity(@NonNull Context context) { + if (context instanceof Activity) { + return (Activity) context; + } else if (context instanceof ContextWrapper) { + return findActivity(((ContextWrapper) context).getBaseContext()); + } else { + return null; + } + } @Override public void onDestroy() { super.onDestroy(); diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsJrFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsJrFragment.java deleted file mode 100644 index feda0c6e..00000000 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsJrFragment.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.bonait.bnframework.modules.home.fragment.from.fragment; - -import android.content.Context; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; - -import com.bonait.bnframework.R; -import com.bonait.bnframework.common.base.BaseFragment; -import com.orhanobut.logger.Logger; - -import butterknife.ButterKnife; - -public class SystemCsJrFragment extends BaseFragment { - - - private Context context; - @Override - protected View onCreateView() { - View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_system_cs_jr, null); - ButterKnife.bind(this, root); - return root; - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - Logger.d("我的fragment创建"); - context = getContext(); - } - - @Override - public void onDestroy() { - super.onDestroy(); - Logger.d("我的fragment销毁"); - } - - /** - * 当在activity设置viewPager + BottomNavigation + fragment时, - * 为防止viewPager左滑动切换界面,与fragment左滑返回上一界面冲突引起闪退问题, - * 必须加上此方法,禁止fragment左滑返回上一界面。 - * - * 切记!切记!切记!否则会闪退! - * - * 当在fragment设置viewPager + BottomNavigation + fragment时,则不会出现这个问题。 - */ - @Override - protected boolean canDragBack() { - return false; - } -} \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsMonitorFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsMonitorFragment.java new file mode 100644 index 00000000..30e3af0d --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsMonitorFragment.java @@ -0,0 +1,130 @@ +package com.bonait.bnframework.modules.home.fragment.from.fragment; + +import android.content.Context; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.LinearLayout; +import android.widget.TextView; + +import com.bonait.bnframework.R; +import com.bonait.bnframework.business.ExecuteTheRecipe; +import com.bonait.bnframework.common.base.BaseFragment; +import com.bonait.bnframework.common.constant.ConfigName; +import com.bonait.bnframework.common.constant.DataBus; +import com.bonait.bnframework.common.db.res.StatusMode; +import com.bonait.bnframework.common.utils.ToastUtils; +import com.bonait.bnframework.common.view.MyLayoutManager; +import com.bonait.bnframework.modules.home.adapter.lc_adapter; +import com.bonait.bnframework.modules.home.adapter.monitor_adapter; +import com.orhanobut.logger.Logger; + +import butterknife.BindView; +import butterknife.ButterKnife; + +/** + * plc 监控 + */ +public class SystemCsMonitorFragment extends BaseFragment { + + @BindView(R.id.recycler_view) + RecyclerView recyclerView;//工序子集 + + @BindView(R.id.jiaobandianji) + TextView jiaobandianji;//工序子集 + + @BindView(R.id.fanzhuandianji) + TextView fanzhuandianji;//工序子集 + private Context context; + + monitor_adapter adapter; + @Override + protected View onCreateView() { + View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_system_cs_monitor, null); + ButterKnife.bind(this, root); + return root; + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + Logger.d("我的fragment创建"); + context = getContext(); + initData(); + } + + /** + * 初始化显示数据 + */ + private void initData() { + try { + MyLayoutManager layout = new MyLayoutManager(); + layout.setAutoMeasureEnabled(true); + recyclerView.setLayoutManager(layout); + + adapter = new monitor_adapter(getContext()); + recyclerView.setAdapter(adapter); + + Run(); + } catch (Exception e) { + ToastUtils.info("异常信息:" + e.getMessage()); + } + } + /** + * 实时显示线程 + */ + public void Run() { + new Thread(new Runnable() { + @Override + public void run() { + while (true) { + try { + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + try { + for (StatusMode item:ConfigName.getInstance().statusModes) + { + item.Status= ExecuteTheRecipe.getConcurrentHash(item.sort); + } + + jiaobandianji.setText( ConfigName.getInstance().statusModes_电机.get(ExecuteTheRecipe.getConcurrentHash_dj("搅拌电机"))); + fanzhuandianji.setText( ConfigName.getInstance().statusModes_电机.get(ExecuteTheRecipe.getConcurrentHash_dj("翻转电机"))); + adapter.refresh(); + } catch (Exception e) { + + } + } + }); + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + } + }).start(); + } + @Override + public void onDestroy() { + super.onDestroy(); + Logger.d("我的fragment销毁"); + } + + /** + * 当在activity设置viewPager + BottomNavigation + fragment时, + * 为防止viewPager左滑动切换界面,与fragment左滑返回上一界面冲突引起闪退问题, + * 必须加上此方法,禁止fragment左滑返回上一界面。 + * + * 切记!切记!切记!否则会闪退! + * + * 当在fragment设置viewPager + BottomNavigation + fragment时,则不会出现这个问题。 + */ + @Override + protected boolean canDragBack() { + return false; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsTlFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsTlFragment.java deleted file mode 100644 index 3b837769..00000000 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/from/fragment/SystemCsTlFragment.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.bonait.bnframework.modules.home.fragment.from.fragment; - -import android.content.Context; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.appcompat.app.AppCompatActivity; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; - -import com.bonait.bnframework.R; -import com.bonait.bnframework.common.base.BaseFragment; -import com.orhanobut.logger.Logger; - -import butterknife.ButterKnife; - -public class SystemCsTlFragment extends BaseFragment { - - - private Context context; - @Override - protected View onCreateView() { - View root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_system_cs_tl, null); - ButterKnife.bind(this, root); - return root; - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - Logger.d("我的fragment创建"); - context = getContext(); - } - - @Override - public void onDestroy() { - super.onDestroy(); - Logger.d("我的fragment销毁"); - } - - /** - * 当在activity设置viewPager + BottomNavigation + fragment时, - * 为防止viewPager左滑动切换界面,与fragment左滑返回上一界面冲突引起闪退问题, - * 必须加上此方法,禁止fragment左滑返回上一界面。 - * - * 切记!切记!切记!否则会闪退! - * - * 当在fragment设置viewPager + BottomNavigation + fragment时,则不会出现这个问题。 - */ - @Override - protected boolean canDragBack() { - return false; - } -} \ No newline at end of file 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 new file mode 100644 index 00000000..c88b4b7a --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_plc_control.java @@ -0,0 +1,176 @@ +package com.bonait.bnframework.modules.home.fragment.mode; + +import android.content.Context; +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.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 butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; + +/** + * PLC控制 + */ +public class fragment_plc_control extends LinearLayout { + @BindView(R.id.name) + TextView name; + @BindView(R.id.name_PLC) + TextView name_PLC;//分组 + + @BindView(R.id.edittext_plc) + EditText edittext_plc;//输入文本 + @BindView(R.id.wenben) + LinearLayout wenben; + @BindView(R.id.kaiguan) + RelativeLayout kaiguan; + + @BindView(R.id.zhidu) + RelativeLayout zhidu; + + @BindView(R.id.update_plc) + Button update_plc;//下发按钮 + + @BindView(R.id.control_switch) + Switch control_switch;//下发按钮 + + @BindView(R.id.text_wb) + TextView text_wb;//分组 + private View root; + public fragment_plc_control(Context context, @Nullable AttributeSet attrs, BPA_PLCADDRESS _model) { + super(context, attrs); + root= LayoutInflater.from(context).inflate(R.layout.fragment_item_plc_control, this); + ButterKnife.bind(this, root); + model=_model; + Init(); + } + public void Init() + { + if (model.address.equals("-------------")) + { + name.setText("\n"+model.name+":"); + wenben.setVisibility(View.GONE); + kaiguan.setVisibility(View.GONE); + zhidu.setVisibility(View.GONE); + }else + { + name_PLC.setText(model.name); + if(model.iswrite==1) + { + zhidu.setVisibility(View.GONE); + if(model.address.startsWith("M"))//开关 + { + wenben.setVisibility(View.GONE); + kaiguan.setVisibility(View.VISIBLE); + if(model.isread==1) + { + Object val= ExecuteTheRecipe.ListeningValue.get(model.name); + if(val!=null) + { + control_switch.setChecked((boolean)val); + if ((boolean)val) + { + control_switch.setText("打开"); + }else + { + control_switch.setText("关闭"); + } + } + } + } else //文本 + { + wenben.setVisibility(View.VISIBLE); + kaiguan.setVisibility(View.GONE); + if(model.isread==1) + { + Object val= ExecuteTheRecipe.ListeningValue.get(model.name); + if(val!=null) + { + String str=String.valueOf(val); + edittext_plc.setText(str.toCharArray(), 0, str.length()); + } + } + } + }else //只读 + { + zhidu.setVisibility(View.VISIBLE); + wenben.setVisibility(View.GONE); + kaiguan.setVisibility(View.GONE); + Object val= ExecuteTheRecipe.ListeningValue.get(model.name); + if(val!=null) + { + text_wb.setText(val+""); + } + } + } + + + control_switch.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + boolean ischick= control_switch.isChecked(); + if (ischick) + { + control_switch.setText("打开"); + }else + { + control_switch.setText("关闭"); + } + + ExecuteTheRecipe.WritePLC(model.name,ischick,null); + ToastUtils.info("写入地址:"+model.address+"成功!状态:"+(ischick?"打开":"关闭")); + + } + }); + } + public BPA_PLCADDRESS model=null; + + @OnClick({R.id.update_plc}) + public void onViewClicked(View view) { + switch (view.getId()) { + case R.id.update_plc: + String text=edittext_plc.getText().toString(); + if(text.isEmpty()) + { + ToastUtils.warning("输入信息不能为空!"); + return; + } + + if(model.address.startsWith("VW")) + { + Short val=Short.parseShort(text); + ExecuteTheRecipe.WritePLC(model.name,val,null); + }else if(model.address.startsWith("VD")) + { + int val=Integer.parseInt(text); + ExecuteTheRecipe.WritePLC(model.name,val,null); + }else + { + Short val=Short.parseShort(text); + ExecuteTheRecipe.WritePLC(model.name,val,null); + } + ToastUtils.info("写入地址:"+model.address+"成功!"); + break; + + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_silos_cl.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_silos_cl.java new file mode 100644 index 00000000..b8e5669d --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/fragment_silos_cl.java @@ -0,0 +1,72 @@ +package com.bonait.bnframework.modules.home.fragment.mode; + +import android.content.Context; +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.TextView; + +import androidx.annotation.Nullable; + +import com.bonait.bnframework.R; +import com.bonait.bnframework.business.ExecuteTheRecipe; +import com.bonait.bnframework.common.db.QueryDB; +import com.bonait.bnframework.common.db.mode.BPA_PLCADDRESS; +import com.bonait.bnframework.common.db.mode.BPA_SILOS; +import com.bonait.bnframework.common.helper.I.IWriteCallBack; +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 butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; + +public class fragment_silos_cl extends LinearLayout { + @BindView(R.id.name) + TextView name; + @BindView(R.id.update_lc) + Button update_lc; + @BindView(R.id.edittext_lc) + EditText edittext_lc; + private View root; + public fragment_silos_cl(Context context, @Nullable AttributeSet attrs, BPA_SILOS _model) { + super(context, attrs); + root= LayoutInflater.from(context).inflate(R.layout.fragment_item_silos_cl, this); + ButterKnife.bind(this, root); + model=_model; + name.setText("料仓" + model.num+"号"); + } + public BPA_SILOS model=null; + + @OnClick({R.id.update_lc}) + public void onViewClicked(View view) { + switch (view.getId()) { + case R.id.update_lc: + String text=edittext_lc.getText().toString(); + if(text.isEmpty()) + { + ToastUtils.warning("需求值为空!"); + return; + } + Short val=Short.parseShort(text); + ExecuteTheRecipe.WritePLC("料仓" + model.num + "需求值", val, new IWriteCallBack() { + @Override + public void onSuccess() { + ExecuteTheRecipe.WritePLC("料仓" + model.num + "下料",true,null); + } + @Override + public void onFailure(String ErrorMsg) { + } + }); + ToastUtils.info("料仓" + model.num+"出料:"+text+"g"); + break; + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/qs_switch.xml b/app/src/main/res/drawable/qs_switch.xml new file mode 100644 index 00000000..42f77751 --- /dev/null +++ b/app/src/main/res/drawable/qs_switch.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/qs_textcolor.xml b/app/src/main/res/drawable/qs_textcolor.xml new file mode 100644 index 00000000..1cebad72 --- /dev/null +++ b/app/src/main/res/drawable/qs_textcolor.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_system_cs_tl.xml b/app/src/main/res/layout/fragment_system_cs_control.xml similarity index 53% rename from app/src/main/res/layout/fragment_system_cs_tl.xml rename to app/src/main/res/layout/fragment_system_cs_control.xml index 9fafbde6..626711e7 100644 --- a/app/src/main/res/layout/fragment_system_cs_tl.xml +++ b/app/src/main/res/layout/fragment_system_cs_control.xml @@ -4,16 +4,24 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".modules.home.fragment.from.fragment.SystemCsTlFragment"> + tools:context=".modules.home.fragment.from.fragment.SystemCsControlFragment"> - + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_system_cs_fltl.xml b/app/src/main/res/layout/fragment_system_cs_fltl.xml index 4c2727cc..65b31663 100644 --- a/app/src/main/res/layout/fragment_system_cs_fltl.xml +++ b/app/src/main/res/layout/fragment_system_cs_fltl.xml @@ -10,10 +10,18 @@ android:layout_height="match_parent" android:orientation="vertical" android:background="@color/main_background"> - + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_system_cs_jr.xml b/app/src/main/res/layout/fragment_system_cs_jr.xml deleted file mode 100644 index 1f3ab921..00000000 --- a/app/src/main/res/layout/fragment_system_cs_jr.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_system_cs_monitor.xml b/app/src/main/res/layout/fragment_system_cs_monitor.xml new file mode 100644 index 00000000..b12bbdd9 --- /dev/null +++ b/app/src/main/res/layout/fragment_system_cs_monitor.xml @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item/layout/devstatus.xml b/app/src/main/res/layout/item/layout/devstatus.xml new file mode 100644 index 00000000..f82c78df --- /dev/null +++ b/app/src/main/res/layout/item/layout/devstatus.xml @@ -0,0 +1,39 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item/layout/fragment_item_plc_control.xml b/app/src/main/res/layout/item/layout/fragment_item_plc_control.xml new file mode 100644 index 00000000..0c40e0b8 --- /dev/null +++ b/app/src/main/res/layout/item/layout/fragment_item_plc_control.xml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + +