whyclj
2020-10-17 e163b7b3e4d5acc63cfda2fec2dd9034864ccf7a
WaterSystem_MonitorServer/src/com/watersystem/monitor/Water_state.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_state implements Serializable{
     public int num;//'主键',
     public int water_id;//'水冷系统id',
@@ -164,5 +170,42 @@
            + ", Water_system_function=" + Water_system_function + ", note=" + note + "]";
   }
   
   /**
    * 创建读取数据集合
    * @param master
    * @return
    */
   public BatchRead<Integer> createBatchRead(MyModbusMaster master){
      BatchRead<Integer> batch = new BatchRead<Integer>();
      batch.addLocator(0,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Watersystem_All_Operation ,DataType.TWO_BYTE_INT_SIGNED,master));//水冷系统各部件运行情况
      batch.addLocator(1,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Watersystem_All_State ,DataType.TWO_BYTE_INT_SIGNED,master));//故障复位信号
      return batch;
   }
   /**
    * 解析返回请求
    * @param res
    */
   public void putBatchResult(BatchResults<Integer> res) {
      if(res != null) {
         int Watersystem_All_Operation= MyModbusUtils.readShortToInt(res.getValue(0));
         this.P01_main_pump=(Watersystem_All_Operation>>8&1);
         this.P11_replenish_pump=(Watersystem_All_Operation>>9&1);
         this.P12_pretest_pump=(Watersystem_All_Operation>>10&1);
         this.P13_replenish_pump=(Watersystem_All_Operation>>11&1);
         this.H01_electric_heater=(Watersystem_All_Operation>>12&1);
         this.H02_electric_heater=(Watersystem_All_Operation>>13&1);
         this.Solenoid_openflag=(Watersystem_All_Operation>>14&1);
         this.Solenoid_shutflag=(Watersystem_All_Operation>>15&1);
         this.valve_start=(Watersystem_All_Operation>>0&1);
         this.Exhaust_start=(Watersystem_All_Operation>>8&1);
         this.remote_start=(Watersystem_All_Operation>>8&5);
         this.remote_stop=(Watersystem_All_Operation>>8&6);
         this.Operation_ooled_devices=(Watersystem_All_Operation>>8&7);
         int Watersystem_All_State = MyModbusUtils.readShortToInt(res.getValue(1));
         this.Auto_control_state=(Watersystem_All_State>>8&1);
         this.Manual_control_state=(Watersystem_All_State>>9&1);
         this.remote_control_state=(Watersystem_All_State>>10&1);
         this.Water_system_function=(Watersystem_All_State>>11&1);
      }
   }
}