From 8eef58973585492ba315d22a0b03eb6e84ccd578 Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq,com> Date: 星期六, 29 八月 2020 09:41:44 +0800 Subject: [PATCH] 水冷修改 --- WaterSystem_MonitorServer/src/com/watersystem/monitor/Water_brach.java | 82 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 81 insertions(+), 1 deletions(-) diff --git a/WaterSystem_MonitorServer/src/com/watersystem/monitor/Water_brach.java b/WaterSystem_MonitorServer/src/com/watersystem/monitor/Water_brach.java index d4f4a05..e7f2be2 100644 --- a/WaterSystem_MonitorServer/src/com/watersystem/monitor/Water_brach.java +++ b/WaterSystem_MonitorServer/src/com/watersystem/monitor/Water_brach.java @@ -2,6 +2,11 @@ import java.io.Serializable; +import com.modbus.data.MyModbusMaster; +import com.modbus.data.MyModbusUtils; +import com.serotonin.modbus4j.BatchRead; +import com.serotonin.modbus4j.BatchResults; + public class Water_brach implements Serializable{ public int num;//'主键', public int water_id;//'水冷系统id', @@ -299,5 +304,80 @@ + ", Branch_pre_9=" + Branch_pre_9 + ", note=" + note + "]"; } - + /** + * 创建读取数据集合 + * @param master + * @return + */ + public BatchRead<Integer> createBatchRead(MyModbusMaster master){ + BatchRead<Integer> batch = new BatchRead<Integer>(); + batch.addLocator(0,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_1 ,master));//'1#支路流量', + batch.addLocator(1,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_2,master)); + batch.addLocator(2,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_3, master)); + batch.addLocator(3,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_4, master)); + batch.addLocator(4,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_5, master)); + batch.addLocator(5,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_6, master)); + batch.addLocator(6,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_7, master)); + batch.addLocator(7,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_8, master)); + batch.addLocator(8,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_9, master));//'9#支路流量', + + batch.addLocator(9,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_1, master));//'1#支路温度', + batch.addLocator(10,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_2 ,master)); + batch.addLocator(11,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_3 ,master)); + batch.addLocator(12,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_4, master)); + batch.addLocator(13,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_5, master)); + batch.addLocator(14,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_6, master)); + batch.addLocator(15,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_7, master)); + batch.addLocator(16,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_8, master)); + batch.addLocator(17,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_9, master));//'9#支路温度', + + batch.addLocator(18,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_1, master));//'1#支路压力', + batch.addLocator(19,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_2, master)); + batch.addLocator(20,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_3, master)); + batch.addLocator(21,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_4, master)); + batch.addLocator(22,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_5, master)); + batch.addLocator(23,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_6, master)); + batch.addLocator(24,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_7, master)); + batch.addLocator(25,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_8, master)); + batch.addLocator(26,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_9, master));//'9#支路压力', + return batch; + } + /** + * 解析返回请求 + * @param res + */ + public void putBatchResult(BatchResults<Integer> res) { + if(res != null) { + this.Branch_flow_1 = MyModbusUtils.readShortToFloat(res.getValue(0)); + this.Branch_flow_2 = MyModbusUtils.readShortToFloat(res.getValue(1)); + this.Branch_flow_3 = MyModbusUtils.readShortToFloat(res.getValue(2)); + this.Branch_flow_4 = MyModbusUtils.readShortToFloat(res.getValue(3)); + this.Branch_flow_5 = MyModbusUtils.readShortToFloat(res.getValue(4)); + this.Branch_flow_6 = MyModbusUtils.readShortToFloat(res.getValue(5)); + this.Branch_flow_7 = MyModbusUtils.readShortToFloat(res.getValue(6)); + this.Branch_flow_8 = MyModbusUtils.readShortToFloat(res.getValue(7)); + this.Branch_flow_9 = MyModbusUtils.readShortToFloat(res.getValue(8)); + + this.Branch_tmp_1 = MyModbusUtils.readShortToFloat(res.getValue(9)); + this.Branch_tmp_2 = MyModbusUtils.readShortToFloat(res.getValue(10)); + this.Branch_tmp_3 = MyModbusUtils.readShortToFloat(res.getValue(11)); + this.Branch_tmp_4 = MyModbusUtils.readShortToFloat(res.getValue(12)); + this.Branch_tmp_5 = MyModbusUtils.readShortToFloat(res.getValue(13)); + this.Branch_tmp_6 = MyModbusUtils.readShortToFloat(res.getValue(14)); + this.Branch_tmp_7 = MyModbusUtils.readShortToFloat(res.getValue(15)); + this.Branch_tmp_8 = MyModbusUtils.readShortToFloat(res.getValue(16)); + this.Branch_tmp_9 = MyModbusUtils.readShortToFloat(res.getValue(17)); + + this.Branch_pre_1 = MyModbusUtils.readShortToFloat(res.getValue(18)); + this.Branch_pre_2 = MyModbusUtils.readShortToFloat(res.getValue(19)); + this.Branch_pre_3 = MyModbusUtils.readShortToFloat(res.getValue(20)); + this.Branch_pre_4 = MyModbusUtils.readShortToFloat(res.getValue(21)); + this.Branch_pre_5 = MyModbusUtils.readShortToFloat(res.getValue(22)); + this.Branch_pre_6 = MyModbusUtils.readShortToFloat(res.getValue(23)); + this.Branch_pre_7 = MyModbusUtils.readShortToFloat(res.getValue(24)); + this.Branch_pre_8 = MyModbusUtils.readShortToFloat(res.getValue(25)); + this.Branch_pre_9 = MyModbusUtils.readShortToFloat(res.getValue(26)); + + } + } } -- Gitblit v1.9.1