| | |
| | | |
| | | <root> |
| | | <mysql_ramdb_recreate_en>false</mysql_ramdb_recreate_en> |
| | | <mysql_server_ip>118.89.139.230</mysql_server_ip> |
| | | <mysql_server_ip>127.0.0.1</mysql_server_ip> |
| | | <!--SOURCE_BATTDATA_TYPE_FBSDEV = 0--> |
| | | <!--SOURCE_BATTDATA_TYPE_SQLSERVER = 1--> |
| | | <!--SOURCE_BATTDATA_TYPE_C_INTERFACE = 2--> |
| | |
| | | package com.modbus.data;
|
| | |
|
| | | import com.serotonin.modbus4j.ModbusFactory;
|
| | | import com.serotonin.modbus4j.ModbusMaster;
|
| | | import com.serotonin.modbus4j.exception.ModbusInitException;
|
| | | import com.serotonin.modbus4j.ip.IpParameters;
|
| | |
|
| | | public class MyModbusFactory {
|
| | | private static final int SERVER_PORT = 502; //服务端口
|
| | | |
| | | static ModbusFactory modbusFactory;
|
| | | |
| | | static {
|
| | | if (modbusFactory == null) {
|
| | | modbusFactory = new ModbusFactory();
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 获取master
|
| | | * |
| | | * @return
|
| | | * @throws ModbusInitException
|
| | | */
|
| | | public static ModbusMaster getMaster(IpParameters params){
|
| | | // modbusFactory.createRtuMaster(wapper); //RTU 协议
|
| | | // modbusFactory.createUdpMaster(params); //UDP 协议
|
| | | // modbusFactory.createAsciiMaster(wrapper); //ASCII 协议
|
| | | params.setPort(SERVER_PORT);
|
| | | ModbusMaster master = modbusFactory.createTcpMaster(params, false);// TCP 协议
|
| | | try {
|
| | | master.setTimeout(2000);
|
| | | master.init();
|
| | | } catch (ModbusInitException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return master;
|
| | | }
|
| | | }
|
| | | package com.modbus.data; |
| | | |
| | | import com.serotonin.modbus4j.ModbusFactory; |
| | | import com.serotonin.modbus4j.ModbusMaster; |
| | | import com.serotonin.modbus4j.exception.ModbusInitException; |
| | | import com.serotonin.modbus4j.ip.IpParameters; |
| | | |
| | | public class MyModbusFactory { |
| | | private static final int SERVER_PORT = 502; //服务端口 |
| | | |
| | | static ModbusFactory modbusFactory; |
| | | |
| | | static { |
| | | if (modbusFactory == null) { |
| | | modbusFactory = new ModbusFactory(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取master |
| | | * |
| | | * @return |
| | | * @throws ModbusInitException |
| | | */ |
| | | public static ModbusMaster getMaster(IpParameters params){ |
| | | // modbusFactory.createRtuMaster(wapper); //RTU 协议 |
| | | // modbusFactory.createUdpMaster(params); //UDP 协议 |
| | | // modbusFactory.createAsciiMaster(wrapper); //ASCII 协议 |
| | | params.setPort(SERVER_PORT); |
| | | //false:短连接 true:长连接 |
| | | ModbusMaster master = modbusFactory.createTcpMaster(params, true);// TCP 协议 |
| | | try { |
| | | //设置超时时间 |
| | | master.setTimeout(2000); |
| | | //设置重连次数 |
| | | master.setRetries(3); |
| | | //初始化 |
| | | master.init(); |
| | | } catch (ModbusInitException e) { |
| | | //e.printStackTrace(); |
| | | } |
| | | return master; |
| | | } |
| | | } |
| | |
| | | package com.modbus.data;
|
| | |
|
| | | import java.text.NumberFormat;
|
| | |
|
| | | import com.base.ComBase;
|
| | | import com.serotonin.modbus4j.ModbusMaster;
|
| | | import com.serotonin.modbus4j.ip.IpParameters;
|
| | |
|
| | | public class MyModbusMaster {
|
| | | public final static int SLAVEID_DEFAULT = 2;
|
| | | |
| | | public final static int MAX_ERROR_COUNT = 2; //最大连续错误计数
|
| | | private ModbusMaster master;
|
| | | private int errcount; //错误计数 错误连续超过三个时重新获取master
|
| | | private String target_ip; //目标ip
|
| | | private int slaveId; //设备ID
|
| | | |
| | | public MyModbusMaster(String target_ip,int slaveId) {
|
| | | this.target_ip = target_ip;
|
| | | this.slaveId = slaveId;
|
| | | IpParameters params = new IpParameters();
|
| | | params.setHost(target_ip);
|
| | | this.master = MyModbusFactory.getMaster(params);
|
| | | }
|
| | | |
| | | public void addErrorCount() {
|
| | | this.errcount++;
|
| | | if(this.errcount > MAX_ERROR_COUNT) {
|
| | | reConnect();
|
| | | }
|
| | | }
|
| | | |
| | | public void reConnect() {
|
| | | IpParameters params = new IpParameters();
|
| | | params.setHost(target_ip);
|
| | | if(this.master != null) {
|
| | | //清空上一个master
|
| | | this.master.destroy();
|
| | | }
|
| | | this.errcount = 0;
|
| | | this.master = MyModbusFactory.getMaster(params);
|
| | | }
|
| | | |
| | | /**
|
| | | * 判断获取到的值是否为空
|
| | | * @param target
|
| | | * @param source
|
| | | * @return
|
| | | */
|
| | | public static Object checkNullData(Object target,Object source) {
|
| | | if(null == target) {
|
| | | return source;
|
| | | }
|
| | | try {
|
| | | if(target instanceof Number) {
|
| | | if(source instanceof Integer) {
|
| | | return ((Number) target).intValue();
|
| | | }else if(source instanceof Float) {
|
| | | return ((Number) target).floatValue();
|
| | | }
|
| | | }
|
| | | if(target instanceof Boolean) {
|
| | | //判断Boolean类型数据
|
| | | if((Boolean)target) {
|
| | | target = 1;
|
| | | }else {
|
| | | target = 0;
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return target;
|
| | | |
| | | }
|
| | | |
| | | public ModbusMaster getMaster() {
|
| | | return master;
|
| | | }
|
| | | public int getErrcount() {
|
| | | return errcount;
|
| | | }
|
| | | public void setMaster(ModbusMaster master) {
|
| | | this.master = master;
|
| | | }
|
| | | public void setErrcount(int errcount) {
|
| | | this.errcount = errcount;
|
| | | }
|
| | |
|
| | | public String getTarget_ip() {
|
| | | return target_ip;
|
| | | }
|
| | |
|
| | | public void setTarget_ip(String target_ip) {
|
| | | this.target_ip = target_ip;
|
| | | }
|
| | |
|
| | | public int getSlaveId() {
|
| | | return slaveId;
|
| | | }
|
| | |
|
| | | public void setSlaveId(int slaveId) {
|
| | | this.slaveId = slaveId;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public String toString() {
|
| | | return "MyModbusMaster [SLAVEID_DEFAULT=" + SLAVEID_DEFAULT + ", master=" + master + ", errcount=" + errcount
|
| | | + ", target_ip=" + target_ip + ", slaveId=" + slaveId + "]";
|
| | | }
|
| | | }
|
| | | package com.modbus.data; |
| | | |
| | | import java.text.NumberFormat; |
| | | |
| | | import com.base.ComBase; |
| | | import com.serotonin.modbus4j.ModbusMaster; |
| | | import com.serotonin.modbus4j.ip.IpParameters; |
| | | |
| | | public class MyModbusMaster { |
| | | public final static int SLAVEID_DEFAULT = 2; |
| | | |
| | | public final static int MAX_ERROR_COUNT = 2; //最大连续错误计数 |
| | | private ModbusMaster master; |
| | | private int errcount; //错误计数 错误连续超过三个时重新获取master |
| | | private int totalerr; //总的错误计数 //用于判别设备是否掉线 |
| | | private String target_ip; //目标ip |
| | | private int slaveId; //设备ID |
| | | |
| | | public MyModbusMaster(String target_ip,int slaveId) { |
| | | this.target_ip = target_ip; |
| | | this.slaveId = slaveId; |
| | | IpParameters params = new IpParameters(); |
| | | params.setHost(target_ip); |
| | | this.master = MyModbusFactory.getMaster(params); |
| | | } |
| | | |
| | | public void addErrorCount() { |
| | | this.errcount++; |
| | | if(this.errcount > MAX_ERROR_COUNT) { |
| | | reConnect(); |
| | | } |
| | | if(this.totalerr > 99999999) { |
| | | this.totalerr = 5; |
| | | } |
| | | this.totalerr ++; |
| | | } |
| | | |
| | | //清空错误计数 |
| | | public void clearError() { |
| | | errcount = 0; |
| | | totalerr = 0; |
| | | } |
| | | |
| | | public void reConnect() { |
| | | IpParameters params = new IpParameters(); |
| | | params.setHost(target_ip); |
| | | if(this.master != null) { |
| | | //清空上一个master |
| | | this.master.destroy(); |
| | | } |
| | | this.errcount = 0; |
| | | this.master = MyModbusFactory.getMaster(params); |
| | | } |
| | | |
| | | /** |
| | | * 判断获取到的值是否为空 |
| | | * @param target |
| | | * @param source |
| | | * @return |
| | | */ |
| | | public static Object checkNullData(Object target,Object source) { |
| | | if(null == target) { |
| | | return source; |
| | | } |
| | | try { |
| | | if(target instanceof Number) { |
| | | if(source instanceof Integer) { |
| | | return ((Number) target).intValue(); |
| | | }else if(source instanceof Float) { |
| | | return ((Number) target).floatValue(); |
| | | } |
| | | } |
| | | if(target instanceof Boolean) { |
| | | //判断Boolean类型数据 |
| | | if((Boolean)target) { |
| | | target = 1; |
| | | }else { |
| | | target = 0; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return target; |
| | | |
| | | } |
| | | |
| | | public int getTotalerr() { |
| | | return totalerr; |
| | | } |
| | | |
| | | public void setTotalerr(int totalerr) { |
| | | this.totalerr = totalerr; |
| | | } |
| | | |
| | | public ModbusMaster getMaster() { |
| | | return master; |
| | | } |
| | | public int getErrcount() { |
| | | return errcount; |
| | | } |
| | | public void setMaster(ModbusMaster master) { |
| | | this.master = master; |
| | | } |
| | | public void setErrcount(int errcount) { |
| | | this.errcount = errcount; |
| | | } |
| | | |
| | | public String getTarget_ip() { |
| | | return target_ip; |
| | | } |
| | | |
| | | public void setTarget_ip(String target_ip) { |
| | | this.target_ip = target_ip; |
| | | } |
| | | |
| | | public int getSlaveId() { |
| | | return slaveId; |
| | | } |
| | | |
| | | public void setSlaveId(int slaveId) { |
| | | this.slaveId = slaveId; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return "MyModbusMaster [SLAVEID_DEFAULT=" + SLAVEID_DEFAULT + ", master=" + master + ", errcount=" + errcount |
| | | + ", target_ip=" + target_ip + ", slaveId=" + slaveId + "]"; |
| | | } |
| | | } |
| | |
| | | package com.modbus.data; |
| | | |
| | | import java.util.Date; |
| | | |
| | | import com.base.ComBase; |
| | | import com.serotonin.modbus4j.BatchRead; |
| | | import com.serotonin.modbus4j.BatchResults; |
| | | import com.serotonin.modbus4j.ModbusMaster; |
| | | import com.serotonin.modbus4j.code.DataType; |
| | | import com.serotonin.modbus4j.exception.ErrorResponseException; |
| | | import com.serotonin.modbus4j.exception.ModbusTransportException; |
| | | import com.serotonin.modbus4j.locator.BaseLocator; |
| | |
| | | public static Boolean readCoilStatus(int offset,MyModbusMaster master){ |
| | | // 01 Coil Status |
| | | BaseLocator<Boolean> loc = BaseLocator.coilStatus(master.getSlaveId(), offset); |
| | | Boolean value = null;; |
| | | Boolean value = null; |
| | | boolean isSuccess = true; |
| | | try { |
| | | value = master.getMaster().getValue(loc); |
| | | } catch (ModbusTransportException | ErrorResponseException e) { |
| | | master.addErrorCount(); |
| | | //e.printStackTrace(); |
| | | isSuccess = false; |
| | | } finally { |
| | | if(isSuccess) { |
| | | master.clearError(); |
| | | }else { |
| | | master.addErrorCount(); |
| | | } |
| | | } |
| | | return value; |
| | | } |
| | |
| | | // 02 Input Status |
| | | BaseLocator<Boolean> loc = BaseLocator.inputStatus(master.getSlaveId(), offset); |
| | | Boolean value = null;; |
| | | boolean isSuccess = true; |
| | | try { |
| | | value = master.getMaster().getValue(loc); |
| | | } catch (ModbusTransportException | ErrorResponseException e) { |
| | | master.addErrorCount(); |
| | | //e.printStackTrace(); |
| | | isSuccess = false; |
| | | } finally { |
| | | if(isSuccess) { |
| | | master.clearError(); |
| | | }else { |
| | | master.addErrorCount(); |
| | | } |
| | | } |
| | | return value; |
| | | } |
| | |
| | | // 03 Holding Register类型数据读取 |
| | | BaseLocator<Number> loc = BaseLocator.holdingRegister(master.getSlaveId(), offset, dataType); |
| | | Number value = null; |
| | | boolean isSuccess = true; |
| | | try { |
| | | value = master.getMaster().getValue(loc); |
| | | } catch (ModbusTransportException | ErrorResponseException e) { |
| | | //e.printStackTrace(); |
| | | master.addErrorCount(); |
| | | isSuccess = false; |
| | | } finally { |
| | | if(isSuccess) { |
| | | master.clearError(); |
| | | }else { |
| | | master.addErrorCount(); |
| | | } |
| | | } |
| | | return value; |
| | | } |
| | |
| | | // 04 Input Registers类型数据读取 |
| | | BaseLocator<Number> loc = BaseLocator.inputRegister(master.getSlaveId(), offset, dataType); |
| | | Number value = null; |
| | | boolean isSuccess = true; |
| | | try { |
| | | value = master.getMaster().getValue(loc); |
| | | } catch (ModbusTransportException | ErrorResponseException e) { |
| | | //e.printStackTrace(); |
| | | master.addErrorCount(); |
| | | isSuccess = false; |
| | | } finally { |
| | | if(isSuccess) { |
| | | master.clearError(); |
| | | }else { |
| | | master.addErrorCount(); |
| | | } |
| | | } |
| | | return value; |
| | | } |
| | | |
| | | public static BatchResults<Integer> readMutilRegisters(BatchRead<Integer> batch,MyModbusMaster master){ |
| | | batch.setContiguousRequests(false); |
| | | try { |
| | | return master.getMaster().send(batch); |
| | | } catch (ModbusTransportException | ErrorResponseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 批量读取使用方法 |
| | | * |
| | |
| | | // System.out.println(results.getValue(0)); |
| | | // System.out.println(results.getValue(1)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 构造线圈读取节点 |
| | | * @param offset |
| | | * @param master |
| | | * @return |
| | | */ |
| | | public static BaseLocator<?> createBaseLocator(int offset,MyModbusMaster master) { |
| | | return BaseLocator.coilStatus(master.getSlaveId(), offset); |
| | | } |
| | | |
| | | /** |
| | | * 构造读取节点 |
| | | * @param offset |
| | | * @param master |
| | | * @return |
| | | */ |
| | | public static BaseLocator<?> createBaseLocator(int offset,int datatype,MyModbusMaster master) { |
| | | return BaseLocator.holdingRegister(master.getSlaveId(), offset, datatype); |
| | | } |
| | | |
| | | /** |
| | | * 写 [01 Coil Status(0x)]写一个 function ID = 5 |
| | | * |
| | |
| | | master.addErrorCount(); |
| | | return false; |
| | | } else { |
| | | master.clearError(); |
| | | return true; |
| | | } |
| | | } |
| | |
| | | master.addErrorCount(); |
| | | return false; |
| | | } else { |
| | | master.clearError(); |
| | | return true; |
| | | } |
| | | |
| | |
| | | master.addErrorCount(); |
| | | return false; |
| | | } else { |
| | | master.clearError(); |
| | | return true; |
| | | } |
| | | |
| | |
| | | master.addErrorCount(); |
| | | return false; |
| | | } else { |
| | | master.clearError(); |
| | | return true; |
| | | } |
| | | } |
| | |
| | | ModbusMaster tcpMaster = master.getMaster(); |
| | | // 类型 |
| | | BaseLocator<Number> locator = BaseLocator.holdingRegister(master.getSlaveId(), offset, dataType); |
| | | boolean isSuccess = true; |
| | | try { |
| | | tcpMaster.setValue(locator, value); |
| | | } catch (ModbusTransportException | ErrorResponseException e) { |
| | | e.printStackTrace(); |
| | | //e.printStackTrace(); |
| | | isSuccess = true; |
| | | } finally { |
| | | if(isSuccess) { |
| | | master.clearError(); |
| | | }else { |
| | | master.addErrorCount(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static BatchResults<Integer> readMutilRegisters(BatchRead<Integer> batch,MyModbusMaster master){ |
| | | batch.setContiguousRequests(false); |
| | | |
| | | public static void main(String[] args) { |
| | | BatchRead<Integer> batch = new BatchRead<Integer>(); |
| | | |
| | | batch.addLocator(0, BaseLocator.holdingRegister(1, 1, DataType.TWO_BYTE_INT_SIGNED)); |
| | | batch.addLocator(1, BaseLocator.coilStatus(1, 1)); |
| | | batch.setContiguousRequests(true); |
| | | |
| | | MyModbusMaster m = new MyModbusMaster("192.168.10.221", 2); |
| | | |
| | | ModbusMaster master = m.getMaster(); |
| | | |
| | | BatchResults<Integer> results = new BatchResults<>(); |
| | | try { |
| | | return master.getMaster().send(batch); |
| | | results = master.send(batch); |
| | | } catch (ModbusTransportException | ErrorResponseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | /** |
| | | * 构造线圈读取节点 |
| | | * @param offset |
| | | * @param master |
| | | * @return |
| | | */ |
| | | public static BaseLocator<?> createBaseLocator(int offset,MyModbusMaster master) { |
| | | return BaseLocator.coilStatus(master.getSlaveId(), offset); |
| | | System.out.println(results.getValue(0)); |
| | | //System.out.println(results.getValue(1)); |
| | | } |
| | | |
| | | /** |
| | | * 构造读取节点 |
| | | * @param offset |
| | | * @param master |
| | | * @return |
| | | */ |
| | | public static BaseLocator<?> createBaseLocator(int offset,int datatype,MyModbusMaster master) { |
| | | return BaseLocator.holdingRegister(master.getSlaveId(), offset, datatype); |
| | | } |
| | | |
| | | /** |
| | | * 读取float类型数据 |
| | | * @param obj Short类型 |
| | |
| | | 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 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(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, 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(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, 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#支路压力', |
| | | 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; |
| | | } |
| | | /** |
| | |
| | | import com.modbus.data.MyModbusUtils; |
| | | import com.serotonin.modbus4j.BatchRead; |
| | | import com.serotonin.modbus4j.BatchResults; |
| | | import com.serotonin.modbus4j.code.DataType; |
| | | |
| | | public class Water_rt implements Serializable{ |
| | | public int num;//'主键', |
| | |
| | | */ |
| | | public BatchRead<Integer> createBatchRead(MyModbusMaster master){ |
| | | BatchRead<Integer> batch = new BatchRead<Integer>(); |
| | | batch.addLocator(0,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Cooling_flow ,master));//'冷却水流量', |
| | | batch.addLocator(1,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Supply_tmp ,master));//'供水温度', |
| | | batch.addLocator(2,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Supply_pre , master));//'供水压力', |
| | | batch.addLocator(3,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.back_tem, master));//'回水温度', |
| | | batch.addLocator(4,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.back_pre, master));//'回水压力', |
| | | batch.addLocator(5,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Cooling_ser, master));//'冷却水电导率', |
| | | batch.addLocator(6,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Buffer_tank_level, master));//'缓冲罐液位' |
| | | batch.addLocator(7,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Buffer_tank_pre, master)); //'缓冲罐压力', |
| | | batch.addLocator(8,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Humidity_chamber, master));//'阀厅湿度', |
| | | batch.addLocator(9,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Tem_chamber, master)); //'阀厅温度', |
| | | batch.addLocator(10,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.External_tmp, master));//'外水温度', |
| | | batch.addLocator(11,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.External_pre,master));//'外水压力', |
| | | batch.addLocator(0,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Cooling_flow , DataType.TWO_BYTE_INT_SIGNED,master));//'冷却水流量', |
| | | batch.addLocator(1,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Supply_tmp ,DataType.TWO_BYTE_INT_SIGNED,master));//'供水温度', |
| | | batch.addLocator(2,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Supply_pre ,DataType.TWO_BYTE_INT_SIGNED, master));//'供水压力', |
| | | batch.addLocator(3,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.back_tem, DataType.TWO_BYTE_INT_SIGNED,master));//'回水温度', |
| | | batch.addLocator(4,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.back_pre, DataType.TWO_BYTE_INT_SIGNED,master));//'回水压力', |
| | | batch.addLocator(5,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Cooling_ser, DataType.TWO_BYTE_INT_SIGNED,master));//'冷却水电导率', |
| | | batch.addLocator(6,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Buffer_tank_level, DataType.TWO_BYTE_INT_SIGNED,master));//'缓冲罐液位' |
| | | batch.addLocator(7,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Buffer_tank_pre,DataType.TWO_BYTE_INT_SIGNED, master)); //'缓冲罐压力', |
| | | batch.addLocator(8,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Humidity_chamber,DataType.TWO_BYTE_INT_SIGNED, master));//'阀厅湿度', |
| | | batch.addLocator(9,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Tem_chamber, DataType.TWO_BYTE_INT_SIGNED,master)); //'阀厅温度', |
| | | batch.addLocator(10,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.External_tmp, DataType.TWO_BYTE_INT_SIGNED,master));//'外水温度', |
| | | batch.addLocator(11,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.External_pre,DataType.TWO_BYTE_INT_SIGNED,master));//'外水压力', |
| | | return batch; |
| | | } |
| | | /** |
| | |
| | | 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 BatchRead<Integer> createBatchRead(MyModbusMaster master){ |
| | | BatchRead<Integer> batch = new BatchRead<Integer>(); |
| | | batch.addLocator(0,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Watersystem_All_Operation ,master));//水冷系统各部件运行情况 |
| | | batch.addLocator(1,MyModbusUtils.createBaseLocator(Watersystem_ModbusAddress.Watersystem_All_State ,master));//故障复位信号 |
| | | 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; |
| | | } |
| | | /** |
| | |
| | | wbrach = new Water_brach(winf.getWater_id()); |
| | | walarm =new Water_alarm(winf.water_id); |
| | | master = new MyModbusMaster(winf.getWater_ip(), MyModbusMaster.SLAVEID_DEFAULT); |
| | | //System.out.println(master); |
| | | } |
| | | |
| | | |
| | |
| | | if(runCount %4 == 0) { |
| | | //*************************** 读取水冷信息故障 ******************************//* |
| | | //readWaterAlarmData(master,walarm); |
| | | readMutilWaterAlarmData(master, walarm); |
| | | Water_Task_SQL.insertOrUpdateWater_alarmTable(conn_pool, listAlarm); |
| | | //readMutilWaterAlarmData(master, walarm); |
| | | //Water_Task_SQL.insertOrUpdateWater_alarmTable(conn_pool, listAlarm); |
| | | } |
| | | |
| | | if(runCount%10 == 0) { |
| | |
| | | * @param dbutton |
| | | */ |
| | | public void readMutilWater_rt(MyModbusMaster master, Water_rt wrt) { |
| | | BatchRead<Integer> batch = wrt.createBatchRead(master); |
| | | BatchRead<Integer> batch = wrt.createBatchRead(master); |
| | | BatchResults<Integer> res = MyModbusUtils.readMutilRegisters(batch, master); |
| | | wrt.putBatchResult(res); |
| | | } |
| | |
| | | |
| | | //获取所有的水冷系统 |
| | | Water_Task_SQL.queryAllWater(GB_MysqlConnPool, winfs); |
| | | |
| | | //System.out.println(winfs); |
| | | //读取每套水冷系统的信息 |
| | | Watersystem_ServerSocket_Thread server = new Watersystem_ServerSocket_Thread(GB_MysqlConnPool,winfs); |
| | | new Thread(server).start(); |