| | |
| | | package com.electrical.FourKW; |
| | | |
| | | import java.util.Date; |
| | | |
| | | import com.base.Com; |
| | | 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 Electric_Rt { |
| | | public int electric_id; //电源id |
| | | public float upsetcurr; //上位机设定电流 |
| | |
| | | // TODO Auto-generated constructor stub |
| | | } |
| | | |
| | | /** |
| | | * 创建读取数据集合 |
| | | * @param master |
| | | * @return |
| | | */ |
| | | public BatchRead<Integer> createBatchRead(MyModbusMaster master){ |
| | | BatchRead<Integer> batch = new BatchRead<Integer>(); |
| | | batch.addLocator(0,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "upsetcurr"), DataType.TWO_BYTE_INT_SIGNED, master)); |
| | | batch.addLocator(1,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "upsetvol"), DataType.TWO_BYTE_INT_SIGNED, master)); |
| | | batch.addLocator(2,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "convolcontrol"), master)); |
| | | batch.addLocator(3,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "concurrcontrol"), master)); //恒流控制 |
| | | batch.addLocator(4,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "othermodes"), master)); //其他模式运行 |
| | | batch.addLocator(5,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "parallelmodes"), master)); //并联稳压运行 |
| | | batch.addLocator(6,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "startposition"), master)); //启动位 |
| | | batch.addLocator(7,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "stopposition"), master)); //ֹͣλ |
| | | batch.addLocator(8,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "resetposition"), master)); //复位 |
| | | batch.addLocator(9,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "fanstart"), master)); //风机启动 |
| | | batch.addLocator(10,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "fanstop"), master)); //风机停止 |
| | | |
| | | batch.addLocator(11,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "dcvol"), DataType.TWO_BYTE_INT_SIGNED, master)); //直流电压 |
| | | batch.addLocator(12,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "dccurr"), DataType.TWO_BYTE_INT_SIGNED, master)); //直流电压 |
| | | batch.addLocator(13,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "controlangle"), DataType.TWO_BYTE_INT_SIGNED, master));//控制角 |
| | | |
| | | |
| | | batch.addLocator(14,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "loopflag"), master)); //开闭环标志位【0开环;1闭环】 |
| | | batch.addLocator(15,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "remoteflag"), master)); //就地远程标志位【0远程;1就地】 |
| | | batch.addLocator(16,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "orderflag"), master)); //正序逆序标志位【0正序;1逆序】 |
| | | batch.addLocator(17,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "consvolcurrflag"), master)); //恒压横流标志位【0恒压;1恒流】 |
| | | batch.addLocator(18,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "powerstartflag"), master)); //电源启动标志位【0停止;1启动】 |
| | | batch.addLocator(19,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "workmodelflag"), master)); //工作模式标志位【0其他模式;1并联稳压】 |
| | | batch.addLocator(20,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "switchon_1"), master)); //1号开关 |
| | | batch.addLocator(21,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "switchon_2"), master)); //2号开关 |
| | | batch.addLocator(22,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "switchoff_1"), master)); //1号开关 |
| | | batch.addLocator(23,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "switchoff_2"), master)); //2号开关 |
| | | |
| | | batch.addLocator(24,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "comm_state"), master)); //ͨѶ״̬ |
| | | batch.addLocator(25,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "screen_reset"), master)); //触摸屏状态 |
| | | batch.addLocator(26,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "fan_control"), master)); //风机控制 |
| | | batch.addLocator(27,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "emergency_trip"), master)); //总控柜紧急跳闸 |
| | | |
| | | return batch; |
| | | } |
| | | |
| | | /** |
| | | * 解析返回请求 |
| | | * @param res |
| | | */ |
| | | public void putBatchResult(BatchResults<Integer> res) { |
| | | if(res != null) { |
| | | this.upsetcurr = MyModbusUtils.readShortToFloat(res.getValue(0)); //上位机设定电流 58 |
| | | this.upsetvol = MyModbusUtils.readShortToFloat(res.getValue(1)); //上位机设定电压 |
| | | this.convolcontrol = MyModbusUtils.readBooleanToInt(res.getValue(2)); //恒压控制 |
| | | this.concurrcontrol = MyModbusUtils.readBooleanToInt(res.getValue(3)); //恒流控制 |
| | | this.othermodes = MyModbusUtils.readBooleanToInt(res.getValue(4)); //其他模式运行 |
| | | this.parallelmodes = MyModbusUtils.readBooleanToInt(res.getValue(5)); //并联稳压运行 |
| | | this.startposition = MyModbusUtils.readBooleanToInt(res.getValue(6)); //启动位 |
| | | this.stopposition = MyModbusUtils.readBooleanToInt(res.getValue(7)); //ֹͣλ |
| | | this.resetposition = MyModbusUtils.readBooleanToInt(res.getValue(8)); //复位 |
| | | this.fanstart = MyModbusUtils.readBooleanToInt(res.getValue(9)); //风机启动 |
| | | this.fanstop = MyModbusUtils.readBooleanToInt(res.getValue(10)); //风机停止 |
| | | |
| | | |
| | | this.dcvol = MyModbusUtils.readShortToFloat(res.getValue(11));//直流电压 |
| | | this.dccurr = MyModbusUtils.readShortToFloat(res.getValue(12));//直流电流 |
| | | this.controlangle = MyModbusUtils.readShortToInt(res.getValue(13));//控制角 |
| | | |
| | | this.loopflag = MyModbusUtils.readBooleanToInt(res.getValue(14)); //开闭环标志位【0开环;1闭环】 |
| | | this.remoteflag = MyModbusUtils.readBooleanToInt(res.getValue(15));//就地远程标志位【0远程;1就地】 |
| | | this.orderflag = MyModbusUtils.readBooleanToInt(res.getValue(16));//正序逆序标志位【0正序;1逆序】 |
| | | this.consvolcurrflag = MyModbusUtils.readBooleanToInt(res.getValue(17));//恒压横流标志位【0恒压;1恒流】 |
| | | this.powerstartflag = MyModbusUtils.readBooleanToInt(res.getValue(18));//电源启动标志位【0停止;1启动】 |
| | | this.workmodelflag = MyModbusUtils.readBooleanToInt(res.getValue(19)); //工作模式标志位【0其他模式;1并联稳压】 |
| | | this.switchon_1 = MyModbusUtils.readBooleanToInt(res.getValue(20)); //1号开关 |
| | | this.switchon_2 = MyModbusUtils.readBooleanToInt(res.getValue(21)); //2号开关 |
| | | this.switchoff_1 = MyModbusUtils.readBooleanToInt(res.getValue(22)); //1号开关 |
| | | this.switchoff_2 = MyModbusUtils.readBooleanToInt(res.getValue(23)); //2号开关 |
| | | |
| | | this.comm_state=MyModbusUtils.readBooleanToInt(res.getValue(24)); //ͨѶ״̬ |
| | | this.screen_reset=MyModbusUtils.readBooleanToInt(res.getValue(25)); //触摸屏状态 |
| | | this.fan_control=MyModbusUtils.readBooleanToInt(res.getValue(26)); //风机控制 |
| | | this.emergency_trip=MyModbusUtils.readBooleanToInt(res.getValue(27)); //总控柜紧急跳闸 |
| | | } |
| | | } |
| | | |
| | | public Electric_Rt(int electric_id) { |
| | | this.electric_id = electric_id; |
| | | } |
| | |
| | | package com.electrical.FourKW; |
| | | |
| | | 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 Electric_State { |
| | | |
| | | public int electric_id; //电源id |
| | |
| | | this.conn_flag = conn_flag; |
| | | } |
| | | |
| | | /** |
| | | * 构造State读取集合 |
| | | * @param master |
| | | * @return |
| | | */ |
| | | public BatchRead<Integer> createBatchRead(MyModbusMaster master) { |
| | | BatchRead<Integer> batch = new BatchRead<Integer>(); |
| | | batch.addLocator(0,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "case_trip_output"), master)); //机箱跳闸输出 |
| | | batch.addLocator(1,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "fault_reset_signal"), master)); //故障复位信号 |
| | | batch.addLocator(2,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "high_vol_switch_status"), master)); //高压开关状态 |
| | | batch.addLocator(3,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "stop_button"), master)); //急停按钮 |
| | | batch.addLocator(4,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "main_cabinet_fan_status"), master)); //主柜风机状态 |
| | | batch.addLocator(5,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "trans_cabinet_door_lock"), master)); //变压器柜门连锁 |
| | | batch.addLocator(6,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "trans_cabinet_overtem_alarm"), master)); //变压器超温报警 |
| | | batch.addLocator(7,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "trans_cabinet_overtem_trip"), master)); //变压器超温跳闸 |
| | | batch.addLocator(8,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "qs1_state"), master)); //QS1״̬ |
| | | batch.addLocator(9,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "qs2_state"), master)); //QS2״̬ |
| | | batch.addLocator(10,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "switch_cabinet_door_status"), master)); //转换开关柜门状态 |
| | | |
| | | if(this.electric_id == 4001||this.electric_id == 4003) { |
| | | batch.addLocator(11,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "conn_flag"), master)); //串/并联状态 |
| | | batch.addLocator(12,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "alldcvol"), DataType.TWO_BYTE_INT_SIGNED, master)); //总直流电压 |
| | | batch.addLocator(13,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getAddress(this.electric_id, "alldccurr"), DataType.TWO_BYTE_INT_SIGNED, master)); //总直流电流 |
| | | } |
| | | return batch; |
| | | } |
| | | |
| | | /** |
| | | * 解析State读取集合 |
| | | * @param res |
| | | */ |
| | | public void putBatchResult(BatchResults<Integer> res) { |
| | | if(res != null) { |
| | | this.case_trip_output = MyModbusUtils.readBooleanToInt(res.getValue(0)); //机箱跳闸输出 |
| | | this.fault_reset_signal = MyModbusUtils.readBooleanToInt(res.getValue(1)); //故障复位信号 |
| | | this.high_vol_switch_status = MyModbusUtils.readBooleanToInt(res.getValue(2)); //高压开关状态 |
| | | this.stop_button = MyModbusUtils.readBooleanToInt(res.getValue(3)); //急停按钮 |
| | | this.main_cabinet_fan_status = MyModbusUtils.readBooleanToInt(res.getValue(4)); //主柜风机状态 |
| | | this.trans_cabinet_door_lock = MyModbusUtils.readBooleanToInt(res.getValue(5)); //变压器柜门连锁 |
| | | this.trans_cabinet_overtem_alarm = MyModbusUtils.readBooleanToInt(res.getValue(6)); //变压器超温报警 |
| | | this.trans_cabinet_overtem_trip = MyModbusUtils.readBooleanToInt(res.getValue(7)); //变压器超温跳闸 |
| | | this.qs1_state = MyModbusUtils.readBooleanToInt(res.getValue(8)); //QS1״̬ |
| | | this.qs2_state = MyModbusUtils.readBooleanToInt(res.getValue(9)); //QS2״̬ |
| | | this.switch_cabinet_door_status = MyModbusUtils.readBooleanToInt(res.getValue(10)); //转换开关柜门状态 |
| | | if(this.getElectric_id()==4001||this.getElectric_id()==4003) { |
| | | this.conn_flag= MyModbusUtils.readBooleanToInt(res.getValue(11)); //串/并联状态 ; |
| | | this.alldcvol = MyModbusUtils.readShortToFloat(res.getValue(12)); //总直流电压 |
| | | this.alldccurr = MyModbusUtils.readShortToFloat(res.getValue(13)); //总直流电流 |
| | | }else { |
| | | this.alldcvol = 0; |
| | | this.alldccurr = 0; |
| | | this.conn_flag = 0; //串/并联状态 |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | import java.util.Date; |
| | | |
| | | import com.base.Com; |
| | | 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 Electric_alarm { |
| | | public int num ;//'主键', |
| | | public int electric_id;// '设备id', |
| | |
| | | + ", alarm_starttime=" + alarm_starttime + ", alarm_endtime=" + alarm_endtime + ", alarm_confirm=" |
| | | + alarm_confirm + ", alarm_confirmtime=" + alarm_confirmtime + ", note=" + note + "]"; |
| | | } |
| | | |
| | | /** |
| | | * 创建读取集合 |
| | | * @param master |
| | | * @return |
| | | */ |
| | | public BatchRead<Integer> createBatchRead(MyModbusMaster master) { |
| | | BatchRead<Integer> batch = new BatchRead<Integer>(); |
| | | batch.addLocator(0,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getFaultAdd(this.electric_id, "dcover_curr"), master)); //直流过流 |
| | | batch.addLocator(1,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getFaultAdd(this.electric_id, "synchro_lose"), master)); //同步丢失 |
| | | batch.addLocator(2,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getFaultAdd(this.electric_id, "dcover_vol"), master)); //直流过压 |
| | | batch.addLocator(3,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getFaultAdd(this.electric_id, "case_pulse_block"), master)); //机箱脉冲封锁 |
| | | batch.addLocator(4,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getFaultAdd(this.electric_id, "case_transA_overcurr"), master)); //机箱变压器A相过流 |
| | | batch.addLocator(5,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getFaultAdd(this.electric_id, "case_transB_overcurr"), master)); //机箱变压器B相过流 |
| | | batch.addLocator(6,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getFaultAdd(this.electric_id, "case_transC_overcurr"), master)); //机箱变压器C相过流 |
| | | batch.addLocator(7,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getFaultAdd(this.electric_id, "case_cuurfeedback_lose"), master)); //机箱直流反馈丢失 |
| | | batch.addLocator(8,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getFaultAdd(this.electric_id, "case_synchro_cycle_fault"), master)); //机箱同步周期故障 |
| | | batch.addLocator(9,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getFaultAdd(this.electric_id, "main_cabinet_fault_one"), master)); //1号主柜快熔故障 |
| | | batch.addLocator(10,MyModbusUtils.createBaseLocator(Electric_4KW_ModbusAddress.getFaultAdd(this.electric_id, "main_cabinet_fault_two"), master)); //2号主柜快熔故障 |
| | | |
| | | return batch; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 解析返回请求 |
| | | * @param res |
| | | */ |
| | | public void putBatchResult(BatchResults<Integer> res) { |
| | | if(res != null) { |
| | | this.dcover_curr = MyModbusUtils.readBooleanToInt(res.getValue(0)); //直流过流 |
| | | this.synchro_lose = MyModbusUtils.readBooleanToInt(res.getValue(1)); //同步丢失 |
| | | this.dcover_vol = MyModbusUtils.readBooleanToInt(res.getValue(2)); //直流过压 |
| | | this.case_pulse_block = MyModbusUtils.readBooleanToInt(res.getValue(3)); //机箱脉冲封锁 |
| | | this.case_transA_overcurr = MyModbusUtils.readBooleanToInt(res.getValue(4)); //机箱变压器A相过流 |
| | | this.case_transB_overcurr = MyModbusUtils.readBooleanToInt(res.getValue(5)); //机箱变压器B相过流 |
| | | this.case_transC_overcurr = MyModbusUtils.readBooleanToInt(res.getValue(6)); //机箱变压器C相过流 |
| | | this.case_cuurfeedback_lose = MyModbusUtils.readBooleanToInt(res.getValue(7)); //机箱直流反馈丢失 |
| | | this.case_synchro_cycle_fault = MyModbusUtils.readBooleanToInt(res.getValue(8)); //机箱同步周期故障 |
| | | this.main_cabinet_fault_one = MyModbusUtils.readBooleanToInt(res.getValue(9)); //1号主柜快熔故障 |
| | | this.main_cabinet_fault_two = MyModbusUtils.readBooleanToInt(res.getValue(10)); //2号主柜快熔故障 |
| | | } |
| | | } |
| | | } |
| | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | |
| | | import com.base.Com; |
| | | import com.base.ComBase; |
| | | 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; |
| | | import com.serotonin.modbus4j.locator.BaseLocator; |
| | | import com.sql.MysqlConnPool; |
| | | |
| | | public class Electrical_4KW_SocketClient_Thread implements Runnable{ |
| | |
| | | if(ecs.isControl_en()) { |
| | | //************************** 单点控制输出 *******************************//* |
| | | writeElectricalControlSignal(master,ecs); |
| | | Electrical_Task_SQL.replace_Electric_Control_Single(conn_pool, ecs); |
| | | Electrical_Task_SQL.update_Electric_Control_Single(conn_pool, ecs); |
| | | } |
| | | |
| | | if(econn.electric_id==4001||econn.electric_id==4003) { |
| | | Electrical_Task_SQL.queryElectric_Control_Conn(conn_pool, econn); |
| | | if(econn.isControl_en()) { |
| | | //************************** 组合控制输出 *******************************//* |
| | | writeElectricalControlConn(master, econn); |
| | | Electrical_Task_SQL.replace_Electric_Control_Conn(conn_pool, econn); |
| | | Electrical_Task_SQL.update_Electric_Control_Conn(conn_pool, econn); |
| | | } |
| | | } |
| | | |
| | | |
| | | if(runCount %2 == 0) { |
| | | //*************************** 更新电源实时信息******************************//* |
| | | readElectrical_rt(master,ert); |
| | | Electrical_Task_SQL.replace_Electric_Rt(conn_pool, ert); |
| | | |
| | | //Date t1 = new Date(); |
| | | //readElectrical_rt(master,ert); |
| | | readMutilElectrical_rt(master,ert); |
| | | Electrical_Task_SQL.update_Electric_Rt(conn_pool, ert); |
| | | //System.out.println("RT:"+(new Date().getTime() - t1.getTime())); |
| | | |
| | | |
| | | //Date t2 = new Date(); |
| | | //**************************** 更新电源状态信息 *****************************//* |
| | | readElectrical_state(master,estate); |
| | | Electrical_Task_SQL.replace_Electric_State(conn_pool, estate); |
| | | |
| | | //readElectrical_state(master,estate); |
| | | readMutilElectrical_state(master,estate); |
| | | Electrical_Task_SQL.update_Electric_State(conn_pool, estate); |
| | | //System.out.println("State:"+(new Date().getTime() - t2.getTime())); |
| | | } |
| | | |
| | | if(runCount %4 == 0) { |
| | | //*************************** 读取故障状态信息 ******************************//* |
| | | //Date start = new Date(); |
| | | readElectricalAlarmData(master,eAlarm); |
| | | readMutilElectricalAlarmData(master,eAlarm); |
| | | Electrical_Task_SQL.insertOrUpdateElectrical_alarmTable(conn_pool, listAlarm); |
| | | //Date end = new Date(); |
| | | //System.out.println((end.getTime()-start.getTime())/1000); |
| | | } |
| | | |
| | | //System.out.println(einf.electric_id+"====="+((new Date()).getTime()-last.getTime())/1000); |
| | | System.err.println(einf.electric_id+"====="+((new Date()).getTime()-last.getTime())); |
| | | last = new Date(); |
| | | |
| | | //判断当前设备是否断开连接 |
| | |
| | | runCount = 0; |
| | | } |
| | | runCount ++; |
| | | Thread.sleep(200); |
| | | Thread.sleep(50); |
| | | } catch (Exception e) { |
| | | try { |
| | | Thread.sleep(1000); |
| | |
| | | ert.dcvol = (float)master.checkNullData(MyModbusUtils.readHoldingRegister(Electric_4KW_ModbusAddress.getAddress(ert.getElectric_id(), "dcvol"), DataType.TWO_BYTE_INT_SIGNED, master), ert.dcvol);//直流电压 |
| | | ert.dccurr = (float)master.checkNullData(MyModbusUtils.readHoldingRegister(Electric_4KW_ModbusAddress.getAddress(ert.getElectric_id(), "dccurr"), DataType.TWO_BYTE_INT_SIGNED, master), ert.dccurr);//直流电流 |
| | | ert.controlangle = (int)master.checkNullData(MyModbusUtils.readHoldingRegister(Electric_4KW_ModbusAddress.getAddress(ert.getElectric_id(), "controlangle"), DataType.TWO_BYTE_INT_SIGNED, master), ert.controlangle);//控制角 |
| | | if(ert.electric_id%4003 == 0) { |
| | | System.out.println("dcvol:"+ert.dcvol+"dccurr:"+ert.dccurr+"\t"+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)); |
| | | } |
| | | |
| | | ert.loopflag = (int)master.checkNullData(MyModbusUtils.readCoilStatus(Electric_4KW_ModbusAddress.getAddress(ert.getElectric_id(), "loopflag"), master), ert.loopflag); //开闭环标志位【0开环;1闭环】 |
| | | ert.remoteflag = (int)master.checkNullData(MyModbusUtils.readCoilStatus(Electric_4KW_ModbusAddress.getAddress(ert.getElectric_id(), "remoteflag"), master), ert.remoteflag);//就地远程标志位【0远程;1就地】 |
| | | ert.orderflag = (int)master.checkNullData(MyModbusUtils.readCoilStatus(Electric_4KW_ModbusAddress.getAddress(ert.getElectric_id(), "orderflag"),master), ert.orderflag);//正序逆序标志位【0正序;1逆序】 |
| | |
| | | |
| | | //System.out.println(ert.electric_id+"&&&&&&&&&&&&&&"+ert.getDcvol()); |
| | | } |
| | | |
| | | /** |
| | | * 多点读取Rt状态 |
| | | * @param master |
| | | * @param ert |
| | | */ |
| | | public void readMutilElectrical_rt(MyModbusMaster master, Electric_Rt ert) { |
| | | //Date t1 = new Date(); |
| | | |
| | | BatchRead<Integer> batch = ert.createBatchRead(master); |
| | | BatchResults<Integer> res = MyModbusUtils.readMutilRegisters(batch, master); |
| | | ert.putBatchResult(res); |
| | | |
| | | //System.err.println("NeW:"+(new Date().getTime()-t1.getTime())); |
| | | } |
| | | |
| | | /** |
| | | * 更新电源状态信息 |
| | | * @param master |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 多点读取State状态 |
| | | * @param master |
| | | * @param estate |
| | | */ |
| | | public void readMutilElectrical_state(MyModbusMaster master, Electric_State estate) { |
| | | |
| | | BatchRead<Integer> batch = estate.createBatchRead(master); |
| | | BatchResults<Integer> res = MyModbusUtils.readMutilRegisters(batch, master); |
| | | estate.putBatchResult(res); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 更新电源故障信息 |
| | | * @param master |
| | |
| | | listAlarm.add(alarm); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 多点读取告警状态 |
| | | * @param master |
| | | * @param eAlarm |
| | | */ |
| | | private void readMutilElectricalAlarmData(MyModbusMaster master, Electric_alarm eAlarm) { |
| | | |
| | | BatchRead<Integer> batch = eAlarm.createBatchRead(master); |
| | | BatchResults<Integer> res = MyModbusUtils.readMutilRegisters(batch, master); |
| | | eAlarm.putBatchResult(res); |
| | | |
| | | //筛选告警信息 |
| | | if(res != null) { |
| | | if(eAlarm.dcover_curr>0) { |
| | | Electric_alarm alarm=new Electric_alarm(eAlarm.electric_id); |
| | | alarm.setAlarm_id(119001); |
| | | alarm.setAlarm_starttime(new Date()); |
| | | alarm.setAlarm_endtime(new Date()); |
| | | alarm.setAlarm_confirm(0); |
| | | listAlarm.add(alarm); |
| | | } |
| | | |
| | | if(eAlarm.synchro_lose>0) { |
| | | Electric_alarm alarm=new Electric_alarm(eAlarm.electric_id); |
| | | alarm.setAlarm_id(119002); |
| | | alarm.setAlarm_starttime(new Date()); |
| | | alarm.setAlarm_endtime(new Date()); |
| | | alarm.setAlarm_confirm(0); |
| | | listAlarm.add(alarm); |
| | | } |
| | | |
| | | if(eAlarm.dcover_vol>0) { |
| | | Electric_alarm alarm=new Electric_alarm(eAlarm.electric_id); |
| | | alarm.setAlarm_id(119003); |
| | | alarm.setAlarm_starttime(new Date()); |
| | | alarm.setAlarm_endtime(new Date()); |
| | | alarm.setAlarm_confirm(0); |
| | | listAlarm.add(alarm); |
| | | } |
| | | if(eAlarm.case_pulse_block>0) { |
| | | Electric_alarm alarm=new Electric_alarm(eAlarm.electric_id); |
| | | alarm.setAlarm_id(119004); |
| | | alarm.setAlarm_starttime(new Date()); |
| | | alarm.setAlarm_endtime(new Date()); |
| | | alarm.setAlarm_confirm(0); |
| | | listAlarm.add(alarm); |
| | | } |
| | | if(eAlarm.case_transA_overcurr>0) { |
| | | Electric_alarm alarm=new Electric_alarm(eAlarm.electric_id); |
| | | alarm.setAlarm_id(119005); |
| | | alarm.setAlarm_starttime(new Date()); |
| | | alarm.setAlarm_endtime(new Date()); |
| | | alarm.setAlarm_confirm(0); |
| | | listAlarm.add(alarm); |
| | | } |
| | | if(eAlarm.case_transB_overcurr>0) { |
| | | Electric_alarm alarm=new Electric_alarm(eAlarm.electric_id); |
| | | alarm.setAlarm_id(119006); |
| | | alarm.setAlarm_starttime(new Date()); |
| | | alarm.setAlarm_endtime(new Date()); |
| | | alarm.setAlarm_confirm(0); |
| | | listAlarm.add(alarm); |
| | | } |
| | | if(eAlarm.case_transC_overcurr>0) { |
| | | Electric_alarm alarm=new Electric_alarm(eAlarm.electric_id); |
| | | alarm.setAlarm_id(119007); |
| | | alarm.setAlarm_starttime(new Date()); |
| | | alarm.setAlarm_endtime(new Date()); |
| | | alarm.setAlarm_confirm(0); |
| | | listAlarm.add(alarm); |
| | | } |
| | | if(eAlarm.case_cuurfeedback_lose>0) { |
| | | Electric_alarm alarm=new Electric_alarm(eAlarm.electric_id); |
| | | alarm.setAlarm_id(119008); |
| | | alarm.setAlarm_starttime(new Date()); |
| | | alarm.setAlarm_endtime(new Date()); |
| | | alarm.setAlarm_confirm(0); |
| | | listAlarm.add(alarm); |
| | | } |
| | | if(eAlarm.case_synchro_cycle_fault>0) { |
| | | Electric_alarm alarm=new Electric_alarm(eAlarm.electric_id); |
| | | alarm.setAlarm_id(119009); |
| | | alarm.setAlarm_starttime(new Date()); |
| | | alarm.setAlarm_endtime(new Date()); |
| | | alarm.setAlarm_confirm(0); |
| | | listAlarm.add(alarm); |
| | | } |
| | | if(eAlarm.main_cabinet_fault_one>0) { |
| | | Electric_alarm alarm=new Electric_alarm(eAlarm.electric_id); |
| | | alarm.setAlarm_id(119010); |
| | | alarm.setAlarm_starttime(new Date()); |
| | | alarm.setAlarm_endtime(new Date()); |
| | | alarm.setAlarm_confirm(0); |
| | | listAlarm.add(alarm); |
| | | } |
| | | if(eAlarm.main_cabinet_fault_two>0) { |
| | | Electric_alarm alarm=new Electric_alarm(eAlarm.electric_id); |
| | | alarm.setAlarm_id(119011); |
| | | alarm.setAlarm_starttime(new Date()); |
| | | alarm.setAlarm_endtime(new Date()); |
| | | alarm.setAlarm_confirm(0); |
| | | listAlarm.add(alarm); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 组合控制输出 |
| | |
| | | } |
| | | //并联模式(按钮按下):\\本站点\AB并串联标志位=0; |
| | | if(econn.conn_flag >0) { |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getConnAddress(econn.getElectric_id(), "conn_flag"), true, master); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getConnAddress(econn.getElectric_id(), "conn_flag"), false, master); |
| | | } |
| | | //串联模式(按钮按下):\\本站点\AB并串联标志位=1; |
| | | if(econn.divide_flag >0) { |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getConnAddress(econn.getElectric_id(), "conn_flag"), false, master); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getConnAddress(econn.getElectric_id(), "conn_flag"), true, master); |
| | | } |
| | | //电流电压给定确认(按钮按下): |
| | | /* |
| | |
| | | if(econn.switchon1 >0) { |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id(), "switchon_1"),true, master); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id(), "switchon_2"),true, master); |
| | | try { |
| | | //300毫秒后复原 |
| | | Thread.sleep(300); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id(), "switchon_1"),false, master); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id(), "switchon_2"),false, master); |
| | | } catch (InterruptedException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | //第二套合闸 |
| | | if(econn.switchon2 >0) { |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id()+1, "switchon_1"),true, master); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id()+1, "switchon_2"),true, master); |
| | | |
| | | try { |
| | | //300毫秒后复原 |
| | | Thread.sleep(300); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id()+1, "switchon_1"),false, master); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id()+1, "switchon_2"),false, master); |
| | | } catch (InterruptedException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | //第一套分闸 |
| | | if(econn.switchoff1 >0) { |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id(), "switchon_1"),false, master); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id(), "switchon_2"),false, master); |
| | | |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id(), "switchoff_1"),true, master); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id(), "switchoff_2"),true, master); |
| | | try { |
| | | //300毫秒后复原 |
| | | Thread.sleep(300); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id(), "switchoff_1"),false, master); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id(), "switchoff_2"),false, master); |
| | | } catch (InterruptedException e) { |
| | | // TODO Auto-generated catch block |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | //第二套分闸 |
| | | if(econn.switchoff2 >0) { |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id()+1, "switchon_1"),false, master); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id()+1, "switchon_2"),false, master); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id()+1, "switchoff_1"),true, master); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id()+1, "switchoff_2"),true, master); |
| | | try { |
| | | //300毫秒后复原 |
| | | Thread.sleep(300); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id()+1, "switchoff_1"),false, master); |
| | | MyModbusUtils.writeCoil(Electric_4KW_ModbusAddress.getAddress(econn.getElectric_id()+1, "switchoff_2"),false, master); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | econn.clear(); |
| | | } |
| | | } |
| | |
| | | sql.close_con(); |
| | | } |
| | | } |
| | | //插入或更新电源单点控制表 |
| | | //插入或更新电源单点控制表 |
| | | public static void replace_Electric_Control_Conn(MysqlConnPool pool,Electric_control_conn econn) { |
| | | if(econn.electric_id==4001) { |
| | | econn.conn_name="AB组合"; |
| | |
| | | sql.close_con(); |
| | | } |
| | | } |
| | | |
| | | //更新电源单点控制表 |
| | | public static void update_Electric_Control_Conn(MysqlConnPool pool,Electric_control_conn econn) { |
| | | if(econn.electric_id==4001) { |
| | | econn.conn_name="AB组合"; |
| | | }else { |
| | | econn.conn_name="CD组合"; |
| | | } |
| | | String sql_str = " UPDATE "+ Sql_Mysql.Tb_Electric_Control_Conn+" " |
| | | + " Set conn_name = "+econn.conn_name+"," |
| | | + " convolcontrol = "+econn.convolcontrol+"," |
| | | + " concurrcontrol = "+econn.concurrcontrol+"," |
| | | + " conn_flag = "+econn.conn_flag+"," |
| | | + " volset= "+econn.volset+"," |
| | | + " currset = "+econn.currset+"," |
| | | + " givevol = "+econn.givevol+"," |
| | | + " givecurr = "+econn.givecurr+"," |
| | | + " switchon1 = "+econn.switchon1+"," |
| | | + " switchon2 = "+econn.switchon2+"," |
| | | + " switchoff1 = "+econn.switchoff1+"," |
| | | + " switchoff2 = "+econn.switchoff2+"," |
| | | + " conn_start = "+econn.conn_start+"," |
| | | + " conn_stop = "+econn.conn_stop |
| | | + " WHERE electric_id = " + econn.electric_id; |
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn()); |
| | | try { |
| | | sql.sqlMysqlExecute(sql_str); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | sql.close_con(); |
| | | } |
| | | } |
| | | |
| | | //插入或更新电源实时信息表 |
| | | public static void replace_Electric_Rt(MysqlConnPool pool,Electric_Rt ert) { |
| | | String sql_str = " replace into "+ Sql_Mysql.Tb_Electric_Rt +"(electric_id,upsetcurr,upsetvol,convolcontrol,concurrcontrol,othermodes,parallelmodes,startposition,stopposition,resetposition,fanstart,fanstop,dcvol,dccurr,controlangle,loopflag,remoteflag,orderflag,consvolcurrflag,powerstartflag,workmodelflag,switchon_1,switchoff_1,switchon_2,switchoff_2,comm_state,screen_reset,fan_control,emergency_trip) " |
| | |
| | | sql.close_con(); |
| | | } |
| | | } |
| | | //更新电源实时信息表 |
| | | public static void update_Electric_Rt(MysqlConnPool pool,Electric_Rt ert) { |
| | | String sql_str = " UPDATE "+ Sql_Mysql.Tb_Electric_Rt +"" |
| | | + " SET upsetcurr = "+ert.upsetcurr+"," |
| | | + " upsetvol = "+ert.upsetvol+"," |
| | | + " convolcontrol = "+ert.convolcontrol+"," |
| | | + " concurrcontrol = "+ert.concurrcontrol+"," |
| | | + " othermodes = "+ert.othermodes+"," |
| | | + " parallelmodes = "+ert.parallelmodes+"," |
| | | + " startposition = "+ert.startposition+"," |
| | | + " stopposition = "+ert.stopposition+"," |
| | | + " resetposition = "+ert.resetposition+"," |
| | | + " fanstart = "+ert.fanstart+"," |
| | | + " fanstop = "+ert.fanstop+"," |
| | | + " dcvol = "+ert.dcvol+"," |
| | | + " dccurr = "+ert.dccurr+"," |
| | | + " controlangle = "+ert.controlangle+"," |
| | | + " loopflag = "+ert.loopflag+"," |
| | | + " remoteflag = "+ert.remoteflag+"," |
| | | + " orderflag = "+ert.orderflag+"," |
| | | + " consvolcurrflag = "+ert.consvolcurrflag+"," |
| | | + " powerstartflag = "+ert.powerstartflag+"," |
| | | + " workmodelflag = "+ert.workmodelflag+"," |
| | | + " switchon_1 = "+ert.switchon_1+"," |
| | | + " switchoff_1 = "+ert.switchoff_1+"," |
| | | + " switchon_2 = "+ert.switchon_2+"," |
| | | + " switchoff_2 = "+ert.switchoff_2+"," |
| | | + " comm_state = "+ert.comm_state+"," |
| | | + " screen_reset = "+ert.screen_reset+"," |
| | | + " fan_control = "+ert.fan_control+"," |
| | | + " emergency_trip="+ert.emergency_trip+" " |
| | | + " WHERE electric_id = " + ert.electric_id; |
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn()); |
| | | try { |
| | | sql.sqlMysqlExecute(sql_str); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | sql.close_con(); |
| | | } |
| | | } |
| | | |
| | | //插入或更新电源实时状态表 |
| | | public static void replace_Electric_State(MysqlConnPool pool,Electric_State estate) { |
| | | String sql_str = " replace into "+ Sql_Mysql.Tb_Electric_State +"(electric_id,case_trip_output,fault_reset_signal,high_vol_switch_status,stop_button,main_cabinet_fan_status,trans_cabinet_door_lock,trans_cabinet_overtem_alarm,trans_cabinet_overtem_trip,qs1_state,qs2_state,switch_cabinet_door_status,alldcvol,alldccurr,conn_flag) " |
| | |
| | | sql.close_con(); |
| | | } |
| | | } |
| | | //更新电源实时状态表 |
| | | public static void update_Electric_State(MysqlConnPool pool,Electric_State estate) { |
| | | String sql_str = " update "+ Sql_Mysql.Tb_Electric_State +" " |
| | | + " SET case_trip_output = "+estate.case_trip_output+"," |
| | | + " fault_reset_signal = "+estate.fault_reset_signal+"," |
| | | + " high_vol_switch_status = "+estate.high_vol_switch_status+"," |
| | | + " stop_button = "+estate.stop_button+"," |
| | | + " main_cabinet_fan_status = "+estate.main_cabinet_fan_status+"," |
| | | + " trans_cabinet_door_lock = "+estate.trans_cabinet_door_lock+"," |
| | | + " trans_cabinet_overtem_alarm = "+estate.trans_cabinet_overtem_alarm+"," |
| | | + " trans_cabinet_overtem_trip = "+estate.trans_cabinet_overtem_trip+"," |
| | | + " qs1_state = "+estate.qs1_state+"," |
| | | + " qs2_state = "+estate.qs2_state+"," |
| | | + " switch_cabinet_door_status = "+estate.switch_cabinet_door_status+"," |
| | | + " alldcvol = "+estate.alldcvol+"," |
| | | + " alldccurr = "+estate.alldccurr+"," |
| | | + " conn_flag = "+estate.conn_flag+" " |
| | | + " WHERE electric_id ="+estate.electric_id; |
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn()); |
| | | try { |
| | | sql.sqlMysqlExecute(sql_str); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | sql.close_con(); |
| | | } |
| | | } |
| | | //插入或更新电源总开关状态表 |
| | | public static void replace_Electric_Switch(MysqlConnPool pool,Electric_Switch eswitch) { |
| | | String sql_str = " replace into "+ Sql_Mysql.Tb_Electric_Switch +"(PLC_ip,km1_switchon_one,km1_switchoff_one,km2_switchon_one,km2_switchoff_one,km3_switchon_one,km3_switchoff_one,km4_switchon_one,km4_switchoff_one,km1_switchon_two,km1_switchoff_two,km2_switchon_two,km2_switchoff_two,km3_switchon_two,km3_switchoff_two,km4_switchon_two,km4_switchoff_two) " |
| | |
| | | sql.close_con(); |
| | | } |
| | | } |
| | | |
| | | |
| | | //插入或更新4套电源状态表 |
| | | public static void replace_Electric_Power(MysqlConnPool pool,Electric_Power epower) { |
| | | String sql_str = " replace into "+ Sql_Mysql.Tb_Electric_Power +"(PLC_ip,start_a,stop_a,start_b,stop_b,start_c,stop_c,start_d,stop_d,abconn_start,abconn_stop,cdconn_start,cdconn_stop,allconn_start,allconn_stop,abconn_flag,cdconn_flag,abconn_volset,abconn_currset,cdconn_volset,cdconn_currset) " |
| | |
| | | econn.setConvolcontrol(res.getInt("convolcontrol")); |
| | | econn.setConcurrcontrol(res.getInt("concurrcontrol")); |
| | | econn.setConn_flag(res.getInt("conn_flag")); |
| | | econn.setDivide_flag(res.getInt("divide_flag")); |
| | | econn.setVolset(res.getInt("volset")); |
| | | econn.setCurrset(res.getInt("currset")); |
| | | econn.setGivecurr(res.getFloat("givecurr")); |
| | |
| | | } |
| | | } |
| | | |
| | | //更新电源单点控制表 |
| | | public static void update_Electric_Control_Single(MysqlConnPool pool,Electric_Control_Single ecs) { |
| | | String sql_str = " UPDATE "+ Sql_Mysql.Tb_Electric_Control_Single |
| | | + " upsetcurr = "+ecs.upsetcurr+"," |
| | | + " upsetvol = "+ecs.upsetvol+"," |
| | | + " convolcontrol = "+ecs.convolcontrol+"," |
| | | + " concurrcontrol= "+ecs.concurrcontrol+"," |
| | | + " othermodes = "+ecs.othermodes+"," |
| | | + " parallelmodes ="+ecs.parallelmodes+"," |
| | | + " startposition ="+ecs.startposition+"," |
| | | + " stopposition ="+ecs.stopposition+"," |
| | | + " resetposition ="+ecs.resetposition+"," |
| | | + " fanstart = "+ecs.fanstart+"," |
| | | + " fanstop = "+ecs.fanstop+"," |
| | | + " dcvol = "+ecs.dcvol+"," |
| | | + " dccurr = "+ecs.dccurr+"," |
| | | + " controlangle="+ecs.controlangle+" " |
| | | + " WHERE electric_id = " + ecs.electric_id; |
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn()); |
| | | try { |
| | | sql.sqlMysqlExecute(sql_str); |
| | | } catch (SQLException e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | sql.close_con(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创建历史实时数据表 |
| | | * @param pool |
| | |
| | | // modbusFactory.createUdpMaster(params); //UDP 协议
|
| | | // modbusFactory.createAsciiMaster(wrapper); //ASCII 协议
|
| | | params.setPort(SERVER_PORT);
|
| | | //false:短连接 true:长连接
|
| | | ModbusMaster master = modbusFactory.createTcpMaster(params, true);// TCP 协议
|
| | | try {
|
| | | //设置超时时间
|
| | | master.setTimeout(1000);
|
| | | master.setTimeout(100);
|
| | | //设置重连次数
|
| | | master.setRetries(3);
|
| | | //初始化
|
| | |
| | | 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;
|
| | |
| | | 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
|
| | | *
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | 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);
|
| | | }
|
| | | |
| | | /**
|
| | | * 读取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);
|
| | | }
|
| | | }
|
| | |
| | | //记录历史实时数据线程 |
| | | { |
| | | Electric_4KW_HistoryData_Thread record_thread = new Electric_4KW_HistoryData_Thread(GB_MysqlConnPool, m_AppConfig, einfs); |
| | | new Thread(record_thread).start();; |
| | | new Thread(record_thread).start(); |
| | | } |
| | | |
| | | |