whyclj
2020-10-17 e163b7b3e4d5acc63cfda2fec2dd9034864ccf7a
WaterSystem_MonitorServer/src/com/watersystem/monitor/Water_brach.java
@@ -2,6 +2,12 @@
import java.io.Serializable;
import com.modbus.data.MyModbusMaster;
import com.modbus.data.MyModbusUtils;
import com.serotonin.modbus4j.BatchRead;
import com.serotonin.modbus4j.BatchResults;
import com.serotonin.modbus4j.code.DataType;
public class Water_brach implements Serializable{
     public int num;//'主键',
     public int water_id;//'水冷系统id',
@@ -299,5 +305,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 ,DataType.TWO_BYTE_INT_SIGNED,master));//'1#支路流量',
      batch.addLocator(1,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_2,DataType.TWO_BYTE_INT_SIGNED,master));
      batch.addLocator(2,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_3, DataType.TWO_BYTE_INT_SIGNED,master));
      batch.addLocator(3,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_4,DataType.TWO_BYTE_INT_SIGNED, master));
      batch.addLocator(4,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_5, DataType.TWO_BYTE_INT_SIGNED,master));
      batch.addLocator(5,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_6,DataType.TWO_BYTE_INT_SIGNED, master));
      batch.addLocator(6,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_7, DataType.TWO_BYTE_INT_SIGNED,master));
      batch.addLocator(7,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_8,DataType.TWO_BYTE_INT_SIGNED,master));
      batch.addLocator(8,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_flow_9,DataType.TWO_BYTE_INT_SIGNED, master));//'9#支路流量',
      batch.addLocator(9,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_1,DataType.TWO_BYTE_INT_SIGNED, master));//'1#支路温度',
      batch.addLocator(10,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_2 ,DataType.TWO_BYTE_INT_SIGNED,master));
      batch.addLocator(11,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_3 ,DataType.TWO_BYTE_INT_SIGNED,master));
      batch.addLocator(12,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_4,DataType.TWO_BYTE_INT_SIGNED, master));
      batch.addLocator(13,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_5,DataType.TWO_BYTE_INT_SIGNED, master));
      batch.addLocator(14,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_6, DataType.TWO_BYTE_INT_SIGNED,master));
      batch.addLocator(15,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_7, DataType.TWO_BYTE_INT_SIGNED,master));
      batch.addLocator(16,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_8,DataType.TWO_BYTE_INT_SIGNED, master));
      batch.addLocator(17,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_tmp_9,DataType.TWO_BYTE_INT_SIGNED, master));//'9#支路温度',
      batch.addLocator(18,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_1,DataType.TWO_BYTE_INT_SIGNED, master));//'1#支路压力',
      batch.addLocator(19,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_2, DataType.TWO_BYTE_INT_SIGNED,master));
      batch.addLocator(20,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_3,DataType.TWO_BYTE_INT_SIGNED, master));
      batch.addLocator(21,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_4,DataType.TWO_BYTE_INT_SIGNED, master));
      batch.addLocator(22,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_5,DataType.TWO_BYTE_INT_SIGNED, master));
      batch.addLocator(23,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_6,DataType.TWO_BYTE_INT_SIGNED, master));
      batch.addLocator(24,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_7,DataType.TWO_BYTE_INT_SIGNED, master));
      batch.addLocator(25,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_8,DataType.TWO_BYTE_INT_SIGNED, master));
      batch.addLocator(26,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Branch_pre_9,DataType.TWO_BYTE_INT_SIGNED, master));//'9#支路压力',
      return batch;
   }
   /**
    * 解析返回请求
    * @param res
    */
   public void putBatchResult(BatchResults<Integer> res) {
      if(res != null) {
         this.Branch_flow_1 = MyModbusUtils.readShortToFloat(res.getValue(0))/100;
         this.Branch_flow_2 = MyModbusUtils.readShortToFloat(res.getValue(1))/100;
         this.Branch_flow_3 = MyModbusUtils.readShortToFloat(res.getValue(2))/100;
         this.Branch_flow_4 = MyModbusUtils.readShortToFloat(res.getValue(3))/100;
         this.Branch_flow_5 = MyModbusUtils.readShortToFloat(res.getValue(4))/100;
         this.Branch_flow_6 = MyModbusUtils.readShortToFloat(res.getValue(5))/100;
         this.Branch_flow_7 = MyModbusUtils.readShortToFloat(res.getValue(6))/100;
         this.Branch_flow_8 = MyModbusUtils.readShortToFloat(res.getValue(7))/100;
         this.Branch_flow_9 = MyModbusUtils.readShortToFloat(res.getValue(8))/100;
         this.Branch_tmp_1 = MyModbusUtils.readShortToFloat(res.getValue(9),true)/10;
         this.Branch_tmp_2 = MyModbusUtils.readShortToFloat(res.getValue(10),true)/10;
         this.Branch_tmp_3 = MyModbusUtils.readShortToFloat(res.getValue(11),true)/10;
         this.Branch_tmp_4 = MyModbusUtils.readShortToFloat(res.getValue(12),true)/10;
         this.Branch_tmp_5 = MyModbusUtils.readShortToFloat(res.getValue(13),true)/10;
         this.Branch_tmp_6 = MyModbusUtils.readShortToFloat(res.getValue(14),true)/10;
         this.Branch_tmp_7 = MyModbusUtils.readShortToFloat(res.getValue(15),true)/10;
         this.Branch_tmp_8 = MyModbusUtils.readShortToFloat(res.getValue(16),true)/10;
         this.Branch_tmp_9 = MyModbusUtils.readShortToFloat(res.getValue(17),true)/10;
         this.Branch_pre_1 = MyModbusUtils.readShortToFloat(res.getValue(18),true)/100;
         this.Branch_pre_2 = MyModbusUtils.readShortToFloat(res.getValue(19),true)/100;
         this.Branch_pre_3 = MyModbusUtils.readShortToFloat(res.getValue(20),true)/100;
         this.Branch_pre_4 = MyModbusUtils.readShortToFloat(res.getValue(21),true)/100;
         this.Branch_pre_5 = MyModbusUtils.readShortToFloat(res.getValue(22),true)/100;
         this.Branch_pre_6 = MyModbusUtils.readShortToFloat(res.getValue(23),true)/100;
         this.Branch_pre_7 = MyModbusUtils.readShortToFloat(res.getValue(24),true)/100;
         this.Branch_pre_8 = MyModbusUtils.readShortToFloat(res.getValue(25),true)/100;
         this.Branch_pre_9 = MyModbusUtils.readShortToFloat(res.getValue(26),true)/100;
         //System.out.println(this.Branch_pre_9+"*****");
      }
   }
}