| | |
| | | // modbusFactory.createUdpMaster(params); //UDP 协议
|
| | | // modbusFactory.createAsciiMaster(wrapper); //ASCII 协议
|
| | | params.setPort(SERVER_PORT);
|
| | | ModbusMaster master = modbusFactory.createTcpMaster(params, false);// TCP 协议
|
| | | //true:长连接 false:短连接
|
| | | ModbusMaster master = modbusFactory.createTcpMaster(params, true);// TCP 协议
|
| | | try {
|
| | | master.setTimeout(2000);
|
| | | master.setTimeout(500);
|
| | | //设置重连次数
|
| | | master.setRetries(3);
|
| | | master.init();
|
| | | } catch (ModbusInitException e) {
|
| | | e.printStackTrace();
|
| | |
| | | package com.modbus.data;
|
| | |
|
| | | import java.text.NumberFormat;
|
| | |
|
| | | import com.base.ComBase;
|
| | | import com.serotonin.modbus4j.ModbusMaster;
|
| | | import com.serotonin.modbus4j.ip.IpParameters;
|
| | |
|
| | |
| | | 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
|
| | |
|
| | |
| | | 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() {
|
| | | System.out.println(target_ip);
|
| | | IpParameters params = new IpParameters();
|
| | | params.setHost(target_ip);
|
| | | if(this.master != null) {
|
| | |
| | |
|
| | | }
|
| | |
|
| | | public int getTotalerr() {
|
| | | return totalerr;
|
| | | }
|
| | |
|
| | | public void setTotalerr(int totalerr) {
|
| | | this.totalerr = totalerr;
|
| | | }
|
| | |
|
| | | public ModbusMaster getMaster() {
|
| | | return master;
|
| | | }
|
| | |
| | | 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 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 {
|
| | | results = master.send(batch);
|
| | | } catch (ModbusTransportException | ErrorResponseException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | System.out.println(results.getValue(0));
|
| | | //System.out.println(results.getValue(1));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 读取float类型数据
|
| | | * @param obj Short类型
|
| | | * @return
|
| | | */
|
| | | public static float readShortToFloat(Object obj) {
|
| | | return (float)ComBase.changeShortToInt((Short)obj);
|
| | | }
|
| | | |
| | | /**
|
| | | * 读取float类型数据
|
| | | * @param obj Integer类型
|
| | | * @return
|
| | | */
|
| | | public static float readIntegerToFloat(Object obj) {
|
| | | return (float)((int)obj);
|
| | | }
|
| | | |
| | | /**
|
| | | * 读取int类型数据
|
| | | * @param obj Short类型
|
| | | * @return
|
| | | */
|
| | | public static int readShortToInt(Object obj) {
|
| | | return ComBase.changeShortToInt((Short)obj);
|
| | | }
|
| | | |
| | | /**
|
| | | * 读取Boolean类型数据
|
| | | * @param obj Boolean类型
|
| | | * @return
|
| | | */
|
| | | public static int readBooleanToInt(Object obj) {
|
| | | return ((Boolean)obj?1:0);
|
| | | }
|
| | | }
|
| | |
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | import com.base.Com;
|
| | | import com.modbus.data.MyModbusMaster;
|
| | | import com.modbus.data.MyModbusUtils;
|
| | | import com.motor.data.Load_motor_state;
|
| | | import com.motor.data.Motor_control;
|
| | | import com.motor.data.Motor_inf;
|
| | | import com.motor.data.Subject_motor_state;
|
| | | import com.serotonin.modbus4j.BatchRead;
|
| | | import com.serotonin.modbus4j.BatchResults;
|
| | | import com.serotonin.modbus4j.code.DataType;
|
| | | import com.sql.MysqlConnPool;
|
| | |
|
| | |
| | | Motor_Task_SQL.updateMotor_Control(conn_pool, control);
|
| | | }
|
| | |
|
| | | Date t1 = new Date();
|
| | | Date t2 = new Date();
|
| | | if(runCount %2 == 0) {
|
| | | /*************************** 更新加载电机数据 ******************************/
|
| | | readLoadMotorSingnal(master,load_state);
|
| | | //readLoadMotorSingnal(master,load_state);
|
| | | readMutilLoadMotorSingnal(master,load_state);
|
| | | Motor_Task_SQL.updateLoadMotor_State(conn_pool, load_state);
|
| | |
|
| | |
|
| | | /**************************** 读取受试电机数据 *****************************/
|
| | | readSubjectMotorSingnal(master,subject_state);
|
| | | Motor_Task_SQL.updateSubjectMotor_State(conn_pool, subject_state);
|
| | | }
|
| | | |
| | | if(runCount %4 == 0) {
|
| | | if(runCount %3 == 0) {
|
| | | /**************************** 读取受试电机数据 *****************************/
|
| | | //readSubjectMotorSingnal(master,subject_state);
|
| | | readMutilSubjectMotorSingnal(master,subject_state);
|
| | | //t2 = new Date();
|
| | | Motor_Task_SQL.updateSubjectMotor_State(conn_pool, subject_state);
|
| | | //System.out.println((new Date().getTime()-t2.getTime()));
|
| | | }
|
| | | //System.out.println((new Date().getTime()-t1.getTime())+"==="+(t2.getTime()-t1.getTime()));
|
| | | if(runCount %5 == 0) {
|
| | | /*************************** 读取故障状态信息 ******************************/
|
| | | //Date start = new Date();
|
| | | readMotorAlarmData(master,motor);
|
| | | //readMotorAlarmData(master,motor);
|
| | | readMutilMotorAlarmData(master,motor);
|
| | | //Date end = new Date();
|
| | | //System.out.println((end.getTime()-start.getTime())/1000);
|
| | | //System.err.println((end.getTime()-start.getTime()));
|
| | | }
|
| | | |
| | | //System.err.println(Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
| | | if(runCount%10 == 0) {
|
| | | //更新当前设备ip
|
| | | master.setTarget_ip(motor.motor_ip);
|
| | |
| | | runCount = 0;
|
| | | }
|
| | | runCount ++;
|
| | | Thread.sleep(200); |
| | | Thread.sleep(50); |
| | | } catch (Exception e) {
|
| | | try {
|
| | | Thread.sleep(1000);
|
| | |
| | | if(read_alarm_index >= motor2.alarms.size()) {
|
| | | read_alarm_index = 0;
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 批量设备报警信息
|
| | | * @param master2
|
| | | * @param motor2
|
| | | */
|
| | | private void readMutilMotorAlarmData(MyModbusMaster master2, Motor_inf motor2) {
|
| | | BatchRead<Integer> batch = motor2.createBatchRead(master); |
| | | BatchResults<Integer> res = MyModbusUtils.readMutilRegisters(batch, master);
|
| | | motor2.putBatchResult(res);
|
| | | |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | subject_state2.lubrication_alarm = (int)master2.checkNullData(MyModbusUtils.readCoilStatus(17349, master2), subject_state2.lubrication_alarm); //润滑报警 17349
|
| | | subject_state2.record_time = new Date();
|
| | | }
|
| | | |
| | | /**
|
| | | * 批量读取受试电机信息
|
| | | * @param master2
|
| | | * @param subject_state2
|
| | | */
|
| | | private void readMutilSubjectMotorSingnal(MyModbusMaster master2, Subject_motor_state subject_state2) {
|
| | | BatchRead<Integer> batch = subject_state2.createBatchRead(master); |
| | | BatchResults<Integer> res = MyModbusUtils.readMutilRegisters(batch, master);
|
| | | subject_state2.putBatchResult(res);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 读取加载电机信息
|
| | |
| | | load_state2.load_motor_fan_state = (int)master2.checkNullData(MyModbusUtils.readCoilStatus(17082, master2), load_state2.load_motor_fan_state); //加载电机风机状态 17082
|
| | | load_state2.record_time = new Date();
|
| | | }
|
| | | |
| | | /**
|
| | | * 批量读取加载电机信息
|
| | | * @param master2
|
| | | * @param load_state2
|
| | | */
|
| | | private void readMutilLoadMotorSingnal(MyModbusMaster master2, Load_motor_state load_state2) {
|
| | | BatchRead<Integer> batch = load_state2.createBatchRead(master); |
| | | BatchResults<Integer> res = MyModbusUtils.readMutilRegisters(batch, master);
|
| | | load_state2.putBatchResult(res);
|
| | | |
| | | |
| | | |
| | | }
|
| | | |
| | | /**
|
| | | * 写入控制量信号
|
| | | * @param master2
|
| | |
| | | "subject_motor_stop = " + state.subject_motor_stop +"," +
|
| | | "lubrication_falut = " + state.lubrication_falut +"," +
|
| | | "lubrication_alarm = " + state.lubrication_alarm +
|
| | | " WHERE motor_id = "+state.motor_id; |
| | | " WHERE motor_id = "+state.motor_id;
|
| | | Sql_Mysql sql = new Sql_Mysql(conn_pool.getConn());
|
| | | try {
|
| | | //System.out.println(sql_str);
|
| | | //Date t1 = new Date();
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | | //System.err.println((new Date().getTime()-t1.getTime()));
|
| | | } catch (SQLException e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | |
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | 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 Load_motor_state {
|
| | | public int motor_id;
|
| | | public Date record_time; //记录时间
|
| | |
| | | public void setLoad_motor_fan_state(int load_motor_fan_state) {
|
| | | this.load_motor_fan_state = load_motor_fan_state;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 创建读取集合
|
| | | * @param master
|
| | | * @return
|
| | | */
|
| | | public BatchRead<Integer> createBatchRead(MyModbusMaster master) {
|
| | | BatchRead<Integer> batch = new BatchRead<Integer>();
|
| | | batch.addLocator(0,MyModbusUtils.createBaseLocator(58, DataType.TWO_BYTE_INT_SIGNED, master)); //加载功率给定 58 |
| | | batch.addLocator(1,MyModbusUtils.createBaseLocator(364, DataType.TWO_BYTE_INT_SIGNED, master)); //加载转矩给定 364
|
| | | batch.addLocator(2,MyModbusUtils.createBaseLocator(366, DataType.TWO_BYTE_INT_UNSIGNED_SWAPPED, master)); //加载电机转速限制 366
|
| | | batch.addLocator(3,MyModbusUtils.createBaseLocator(367, DataType.TWO_BYTE_INT_SIGNED, master)); //加载电机转矩限制 367
|
| | | batch.addLocator(4,MyModbusUtils.createBaseLocator(505, DataType.TWO_BYTE_INT_UNSIGNED, master)); //加载步长 505
|
| | | batch.addLocator(5,MyModbusUtils.createBaseLocator(1006, DataType.TWO_BYTE_INT_UNSIGNED, master)); //加载电机水冷进水风温1006
|
| | | batch.addLocator(6,MyModbusUtils.createBaseLocator(1008, DataType.TWO_BYTE_INT_UNSIGNED, master)); //加载电机水冷出水风温1008
|
| | | batch.addLocator(7,MyModbusUtils.createBaseLocator(1096, DataType.TWO_BYTE_INT_SIGNED, master)); //加载电机电流 1096
|
| | | batch.addLocator(8,MyModbusUtils.createBaseLocator(1099, DataType.TWO_BYTE_INT_SIGNED, master)); //加载电机功率 1099
|
| | | batch.addLocator(9,MyModbusUtils.createBaseLocator(1101, DataType.TWO_BYTE_INT_SIGNED, master)); //加载电机转速 1101
|
| | | batch.addLocator(10,MyModbusUtils.createBaseLocator(1103, DataType.TWO_BYTE_INT_SIGNED, master)); //加载电机电压 1103
|
| | | batch.addLocator(11,MyModbusUtils.createBaseLocator(1119, DataType.TWO_BYTE_INT_SIGNED, master)); //加载电机绕组温度1 1119
|
| | | batch.addLocator(12,MyModbusUtils.createBaseLocator(1120, DataType.TWO_BYTE_INT_SIGNED, master)); //加载电机绕组温度2 1120
|
| | | batch.addLocator(13,MyModbusUtils.createBaseLocator(1121, DataType.TWO_BYTE_INT_SIGNED, master)); //加载电机绕组温度3 1121
|
| | | batch.addLocator(14,MyModbusUtils.createBaseLocator(1122, DataType.TWO_BYTE_INT_SIGNED, master)); //加载电机轴承温度1 1122
|
| | | batch.addLocator(15,MyModbusUtils.createBaseLocator(1123, DataType.TWO_BYTE_INT_SIGNED, master)); //加载电机轴承温度2 1123
|
| | | batch.addLocator(16,MyModbusUtils.createBaseLocator(1250, DataType.TWO_BYTE_INT_SIGNED, master)); //加载电机出口温度 1250
|
| | | batch.addLocator(17,MyModbusUtils.createBaseLocator(1124, DataType.TWO_BYTE_INT_SIGNED, master)); //加载电机进口温度 1124
|
| | | batch.addLocator(18,MyModbusUtils.createBaseLocator(1251, DataType.TWO_BYTE_INT_SIGNED, master)); //加载电机转矩 1251
|
| | | batch.addLocator(19,MyModbusUtils.createBaseLocator(5680, master)); //加载电机启动 5680
|
| | | batch.addLocator(20,MyModbusUtils.createBaseLocator(5681, master)); //加载电机停机 5681
|
| | | batch.addLocator(21,MyModbusUtils.createBaseLocator(8000, master)); //加载 8000
|
| | | batch.addLocator(22,MyModbusUtils.createBaseLocator(8001, master)); //减载 8001
|
| | | batch.addLocator(23,MyModbusUtils.createBaseLocator(8040, master)); //手动加载 8040
|
| | | batch.addLocator(24,MyModbusUtils.createBaseLocator(16005, master)); //加载电机紧停 16005
|
| | | batch.addLocator(25,MyModbusUtils.createBaseLocator(17082, master)); //加载电机风机状态 17082
|
| | | |
| | | return batch;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 解析State读取集合
|
| | | * @param res
|
| | | */
|
| | | public void putBatchResult(BatchResults<Integer> res) {
|
| | | if(res != null) {
|
| | | this.load_power = MyModbusUtils.readShortToFloat(res.getValue(0)); //加载功率给定 58 |
| | | this.load_torque = MyModbusUtils.readShortToFloat(res.getValue(1)); //加载转矩给定 364 |
| | | this.load_motor_speed_limit = MyModbusUtils.readIntegerToFloat(res.getValue(2)); //加载电机转速限制 366
|
| | | this.load_motor_torque_limit = MyModbusUtils.readShortToFloat(res.getValue(3)); //加载电机转矩限制 367
|
| | | this.load_step_length = MyModbusUtils.readIntegerToFloat(res.getValue(4)); //加载步长 505 |
| | | this.load_motor_inwater_tmp = MyModbusUtils.readIntegerToFloat(res.getValue(5)); //加载电机水冷进水风温 1006
|
| | | this.load_motor_outwater_tmp = MyModbusUtils.readIntegerToFloat(res.getValue(6)); //加载电机水冷出水风温 1008
|
| | | this.load_motor_curr = MyModbusUtils.readShortToFloat(res.getValue(7)); //加载电机电流 1096
|
| | | this.load_motor_power = MyModbusUtils.readShortToFloat(res.getValue(8)); //加载电机功率 1099
|
| | | this.load_motor_speed = MyModbusUtils.readShortToFloat(res.getValue(9)); //加载电机转速 1101
|
| | | this.load_motor_vol = MyModbusUtils.readShortToFloat(res.getValue(10)); //加载电机电压 1103
|
| | | this.load_motor_wind_tmp1 = MyModbusUtils.readShortToFloat(res.getValue(11)); //加载电机绕组温度1 1119
|
| | | this.load_motor_wind_tmp2 = MyModbusUtils.readShortToFloat(res.getValue(12)); //加载电机绕组温度2 1120
|
| | | this.load_motor_wind_tmp3 = MyModbusUtils.readShortToFloat(res.getValue(13)); //加载电机绕组温度3 1121
|
| | | this.load_motor_bear_tmp1 = MyModbusUtils.readShortToFloat(res.getValue(14)); //加载电机轴承温度1 1122
|
| | | this.load_motor_bear_tmp2 = MyModbusUtils.readShortToFloat(res.getValue(15)); //加载电机轴承温度2 1123
|
| | | this.load_motor_out_tmp = MyModbusUtils.readShortToFloat(res.getValue(16)); //加载电机出口温度 1250
|
| | | this.load_motor_into_tmp = MyModbusUtils.readShortToFloat(res.getValue(17)); //加载电机进口温度 1124
|
| | | this.load_motor_torque = MyModbusUtils.readShortToFloat(res.getValue(18)); //加载电机转矩 1251
|
| | | this.load_motor_start = MyModbusUtils.readBooleanToInt(res.getValue(19)); //加载电机启动 5680
|
| | | this.load_motor_downtime = MyModbusUtils.readBooleanToInt(res.getValue(20)); //加载电机停机 5681
|
| | | this.load_add = MyModbusUtils.readBooleanToInt(res.getValue(21)); //加载 8000
|
| | | this.load_reduct = MyModbusUtils.readBooleanToInt(res.getValue(22)); //减载 8001
|
| | | this.load_manual = MyModbusUtils.readBooleanToInt(res.getValue(23)); //手动加载 8040
|
| | | this.load_motor_stop = MyModbusUtils.readBooleanToInt(res.getValue(24)); //加载电机紧停 16005
|
| | | this.load_motor_fan_state = MyModbusUtils.readBooleanToInt(res.getValue(25)); //加载电机风机状态 17082 |
| | | this.record_time = new Date();
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | package com.motor.data;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import com.mchange.v1.util.Sublist;
|
| | | import com.modbus.data.MyModbusMaster;
|
| | | import com.modbus.data.MyModbusUtils;
|
| | | import com.motor.alarm.Motor_Alarm;
|
| | | import com.serotonin.modbus4j.BatchRead;
|
| | | import com.serotonin.modbus4j.BatchResults;
|
| | | import com.serotonin.modbus4j.code.DataType;
|
| | |
|
| | | public class Motor_inf {
|
| | |
|
| | |
| | | return "Motor_inf [motor_id=" + motor_id + ", motor_name=" + motor_name + ", motor_type=" + motor_type
|
| | | + ", motor_ip=" + motor_ip + ", note=" + note + "]";
|
| | | }
|
| | |
|
| | | /**
|
| | | * 创建读取集合
|
| | | * @param master
|
| | | * @return
|
| | | */
|
| | | public BatchRead<Integer> createBatchRead(MyModbusMaster master) {
|
| | | BatchRead<Integer> batch = new BatchRead<Integer>();
|
| | | for(int i=0;i<this.alarms.size();i++) {
|
| | | batch.addLocator(i,MyModbusUtils.createBaseLocator(12000+i*4, master)); |
| | | }
|
| | | return batch;
|
| | | }
|
| | | |
| | | /**
|
| | | * 解析读取集合
|
| | | * @param res
|
| | | */
|
| | | public void putBatchResult(BatchResults<Integer> res) {
|
| | | if(res != null) {
|
| | | for(int i=0;i<this.alarms.size();i++) {
|
| | | alarms.get(i).checkAlarm(MyModbusUtils.readBooleanToInt(res.getValue(i)));
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | package com.motor.data;
|
| | |
|
| | | import java.util.Date;
|
| | | 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 Subject_motor_state {
|
| | | public int motor_id; //电机id
|
| | |
| | | + subject_motor_stop + ", lubrication_falut=" + lubrication_falut + ", lubrication_alarm="
|
| | | + lubrication_alarm + "]";
|
| | | }
|
| | | |
| | | /**
|
| | | * 创建读取集合
|
| | | * @param master
|
| | | * @return
|
| | | */
|
| | | public BatchRead<Integer> createBatchRead(MyModbusMaster master) {
|
| | | BatchRead<Integer> batch = new BatchRead<Integer>();
|
| | | batch.addLocator(0,MyModbusUtils.createBaseLocator(330, DataType.TWO_BYTE_INT_SIGNED, master)); //传感器转矩 330
|
| | | batch.addLocator(1,MyModbusUtils.createBaseLocator(514, DataType.TWO_BYTE_INT_SIGNED, master)); //传感器功率 514
|
| | | batch.addLocator(2,MyModbusUtils.createBaseLocator(801, master)); //故障确认 801
|
| | | batch.addLocator(3,MyModbusUtils.createBaseLocator(853, DataType.TWO_BYTE_INT_SIGNED, master)); //齿轮箱轴功率 853
|
| | | batch.addLocator(4,MyModbusUtils.createBaseLocator(854, DataType.TWO_BYTE_INT_SIGNED, master)); //推进轴功率 854
|
| | | batch.addLocator(5,MyModbusUtils.createBaseLocator(1010, DataType.TWO_BYTE_INT_UNSIGNED, master)); //齿轮箱轴承温度1 1010
|
| | | batch.addLocator(6,MyModbusUtils.createBaseLocator(1011, DataType.TWO_BYTE_INT_UNSIGNED, master)); //齿轮箱轴承温度2 1011
|
| | | batch.addLocator(7,MyModbusUtils.createBaseLocator(1012, DataType.TWO_BYTE_INT_UNSIGNED, master)); //齿轮箱轴承温度3 1012
|
| | | batch.addLocator(8,MyModbusUtils.createBaseLocator(1013, DataType.TWO_BYTE_INT_UNSIGNED, master)); //齿轮箱轴承温度4 1013
|
| | | batch.addLocator(9,MyModbusUtils.createBaseLocator(1014, DataType.TWO_BYTE_INT_UNSIGNED, master)); //齿轮箱轴承温度5 1014
|
| | | batch.addLocator(10,MyModbusUtils.createBaseLocator(1015, DataType.TWO_BYTE_INT_UNSIGNED, master)); //齿轮箱轴承温度6 1015
|
| | | batch.addLocator(11,MyModbusUtils.createBaseLocator(4480, master)); //油站启动 4480
|
| | | batch.addLocator(12,MyModbusUtils.createBaseLocator(4481, master)); //油站停机 4481
|
| | | batch.addLocator(13,MyModbusUtils.createBaseLocator(5683, master)); //功率控制 5683
|
| | | batch.addLocator(14,MyModbusUtils.createBaseLocator(5684, master)); //转矩控制 5684
|
| | | batch.addLocator(15,MyModbusUtils.createBaseLocator(16000, master)); //变压器高温报警 16000
|
| | | batch.addLocator(16,MyModbusUtils.createBaseLocator(16001, master)); //变压器高温故障 16001
|
| | | batch.addLocator(17,MyModbusUtils.createBaseLocator(16007, master)); //变压器缺相报警 16007
|
| | | batch.addLocator(18,MyModbusUtils.createBaseLocator(16008, master)); //润滑泵1运行 16008
|
| | | batch.addLocator(19,MyModbusUtils.createBaseLocator(16009, master)); //润滑泵2运行 16009
|
| | | batch.addLocator(20,MyModbusUtils.createBaseLocator(16011, master)); //润滑允许远程启动 16011
|
| | | batch.addLocator(21,MyModbusUtils.createBaseLocator(17056, master)); //遥控/就地 17056
|
| | | batch.addLocator(22,MyModbusUtils.createBaseLocator(17065, master)); //变频器就绪 17065
|
| | | batch.addLocator(23,MyModbusUtils.createBaseLocator(17066, master)); //变频器运行 17066
|
| | | batch.addLocator(24,MyModbusUtils.createBaseLocator(17067, master)); //变频器报警 17067
|
| | | batch.addLocator(25,MyModbusUtils.createBaseLocator(17068, master)); //变频器故障 17068
|
| | | batch.addLocator(26,MyModbusUtils.createBaseLocator(17069, master)); //润滑允许主机运行 17069
|
| | | batch.addLocator(27,MyModbusUtils.createBaseLocator(17084, master)); //主开关状态 17084
|
| | | batch.addLocator(28,MyModbusUtils.createBaseLocator(17091, master)); //受试电机运行 17091
|
| | | batch.addLocator(29,MyModbusUtils.createBaseLocator(17136, master)); //受试电机报警 17136
|
| | | batch.addLocator(30,MyModbusUtils.createBaseLocator(17346, master)); //受试电机故障 17346
|
| | | batch.addLocator(31,MyModbusUtils.createBaseLocator(17347, master)); //受试电机紧停 17347
|
| | | batch.addLocator(32,MyModbusUtils.createBaseLocator(17348, master)); //润滑故障 17348
|
| | | batch.addLocator(33,MyModbusUtils.createBaseLocator(17349, master)); //润滑报警 17349
|
| | | |
| | | return batch;
|
| | | }
|
| | | |
| | | /**
|
| | | * 解析读取集合
|
| | | * @param res
|
| | | */
|
| | | public void putBatchResult(BatchResults<Integer> res) {
|
| | | if(res != null) {
|
| | | int index = 0;
|
| | | this.sensor_torque = MyModbusUtils.readShortToFloat(res.getValue(index++)); //传感器转矩 330
|
| | | this.sensor_power = MyModbusUtils.readShortToFloat(res.getValue(index++)); //传感器功率 514
|
| | | this.fault_confirm = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //故障确认 801
|
| | | this.gear_box_power = MyModbusUtils.readShortToFloat(res.getValue(index++)); //齿轮箱轴功率 853
|
| | | this.advance_power = MyModbusUtils.readShortToFloat(res.getValue(index++)); //推进轴功率 854
|
| | | this.gear_box_tmp1 = MyModbusUtils.readIntegerToFloat(res.getValue(index++)); //齿轮箱轴承温度1 1010
|
| | | this.gear_box_tmp2 = MyModbusUtils.readIntegerToFloat(res.getValue(index++)); //齿轮箱轴承温度2 1011
|
| | | this.gear_box_tmp3 = MyModbusUtils.readIntegerToFloat(res.getValue(index++)); //齿轮箱轴承温度3 1012
|
| | | this.gear_box_tmp4 = MyModbusUtils.readIntegerToFloat(res.getValue(index++)); //齿轮箱轴承温度4 1013
|
| | | this.gear_box_tmp5 = MyModbusUtils.readIntegerToFloat(res.getValue(index++)); //齿轮箱轴承温度5 1014
|
| | | this.gear_box_tmp6 = MyModbusUtils.readIntegerToFloat(res.getValue(index++)); //齿轮箱轴承温度6 1015
|
| | | this.gas_station_start = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //油站启动 4480
|
| | | this.gas_station_stop = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //油站停机 4481
|
| | | this.pow_control = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //功率控制 5683
|
| | | this.torque_control = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //转矩控制 5684
|
| | | this.transformer_hightmp_alarm = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //变压器高温报警 16000
|
| | | this.transformer_hightmp_fault = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //变压器高温故障 16001
|
| | | this.transformer_lackphase_alarm = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //变压器缺相报警 16007
|
| | | this.lubrication_pump1_start = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //润滑泵1运行 16008
|
| | | this.lubrication_pump2_start = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //润滑泵2运行 16009
|
| | | this.lubrication_remote_start_allow = MyModbusUtils.readBooleanToInt(res.getValue(index++));//润滑允许远程启动 16011 |
| | | this.remote_control = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //遥控/就地 17056
|
| | | this.inverter_ready = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //变频器就绪 17065
|
| | | this.inverter_running = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //变频器运行 17066
|
| | | this.inverter_alarm = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //变频器报警 17067
|
| | | this.inverter_fault = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //变频器故障 17068
|
| | | this.lubrication_host_running_allow = MyModbusUtils.readBooleanToInt(res.getValue(index++));//润滑允许主机运行 17069
|
| | | this.main_switch_state = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //主开关状态 17084
|
| | | this.subject_motor_running = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //受试电机运行 17091
|
| | | this.subject_motor_alarm = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //受试电机报警 17136
|
| | | this.subject_motor_fault = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //受试电机故障 17346
|
| | | this.subject_motor_stop = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //受试电机紧停 17347
|
| | | this.lubrication_falut = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //润滑故障 17348
|
| | | this.lubrication_alarm = MyModbusUtils.readBooleanToInt(res.getValue(index++)); //润滑报警 17349
|
| | | this.record_time = new Date(); |
| | | }
|
| | | }
|
| | | }
|