| | |
| | | 2020-12-05 10:45:27.128 [main] [ERROR] main.main_Central_Monitor - java.lang.ArithmeticException: / by zero
|
| | | 2020-12-05 10:45:27.130 [main] [ERROR] main.main_Central_Monitor - java.lang.ArithmeticException: / by zero
|
| | | java.lang.ArithmeticException: / by zero
|
| | | at main.main_Central_Monitor.main(main_Central_Monitor.java:53) [bin/:?]
|
| | | 2020-12-05 10:49:35.378 [main] [ERROR] main.main_Central_Monitor - java.lang.ArithmeticException: / by zero
|
| | | 2020-12-05 10:49:35.378 [main] [ERROR] main.main_Central_Monitor - java.lang.ArithmeticException: / by zero
|
| | | java.lang.ArithmeticException: / by zero
|
| | | at main.main_Central_Monitor.main(main_Central_Monitor.java:53) [bin/:?]
|
| | | 2020-12-05 10:49:43.166 [main] [ERROR] main.main_Central_Monitor - java.lang.ArithmeticException: / by zero
|
| | |
| | |
|
| | | 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 Central_RT_Data {
|
| | |
|
| | | private int dev_id; // '设备id',
|
| | | private Date record_time; //'更新时间',
|
| | | |
| | | private int switch_close; // '开关合闸状态',
|
| | | private int switch_open; // '开关分闸状态',
|
| | | private int switch_fault; // '开关故障状态',
|
| | | private float panel_vol ; // '进线屏电压',
|
| | | private float panel_curr ; // '进线屏电流',
|
| | | |
| | | private String note; //'备用',
|
| | |
|
| | | public BatchRead<Integer> createBatchRead(MyModbusMaster master) {
|
| | | BatchRead<Integer> batch = new BatchRead<Integer>(); |
| | | batch.addLocator(0,MyModbusUtils.createInputLocator(1,master)); //'1号2500A进线屏开关合闸状态',
|
| | | batch.addLocator(1,MyModbusUtils.createInputLocator(2,master)); //'1号2500A进线屏开关分闸状态'
|
| | | batch.addLocator(2,MyModbusUtils.createInputLocator(3, master)); //'1号2500A进线屏开关故障状态',
|
| | | |
| | | batch.addLocator(3,MyModbusUtils.createBaseLocator(1,DataType.TWO_BYTE_INT_SIGNED,master)); //'A排电流',
|
| | | if(10001 == dev_id) { |
| | | batch.addLocator(4,MyModbusUtils.createBaseLocator(2,DataType.TWO_BYTE_INT_SIGNED,master)); //'A排电压',
|
| | | }
|
| | |
|
| | | |
| | | return batch;
|
| | | }
|
| | |
|
| | | public void putBatchResult(BatchResults<Integer> res) {
|
| | | if(null != res) {
|
| | | switch_close = (int)res.getValue(0); // '开关合闸状态',
|
| | | switch_open = (int)res.getValue(1); // '开关分闸状态',
|
| | | switch_fault = (int)res.getValue(2); // '开关故障状态',
|
| | | if(10001 == dev_id) {
|
| | | panel_vol = (int)res.getValue(3); // '进线屏电压',
|
| | | panel_curr = (int)res.getValue(4) ; // '进线屏电流',
|
| | | }else {
|
| | | panel_curr = (int)res.getValue(3) ; // '进线屏电流',
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | public Central_RT_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 Central_ST_Data {
|
| | |
|
| | | private int dev_id; //'设备id',
|
| | | private Date record_time; //'更新时间',
|
| | | |
| | | private int switch_close_1st_2500A; //'1号2500A进线屏开关合闸状态',
|
| | | private int switch_open_1st_2500A; //'1号2500A进线屏开关分闸状态',
|
| | | private int switch_fault_1st_2500A; //'1号2500A进线屏开关故障状态',
|
| | |
| | | private float curr_b; //'B排电流',
|
| | | private float vol_b; //'B排电压',
|
| | | private String note; //'备用',
|
| | | |
| | | public BatchRead<Integer> createBatchRead(MyModbusMaster master) {
|
| | | BatchRead<Integer> batch = new BatchRead<Integer>(); |
| | | batch.addLocator(0,MyModbusUtils.createInputLocator(1,master)); //'1号2500A进线屏开关合闸状态',
|
| | | batch.addLocator(1,MyModbusUtils.createInputLocator(2,master)); //'1号2500A进线屏开关分闸状态'
|
| | | batch.addLocator(2,MyModbusUtils.createInputLocator(3, master)); //'1号2500A进线屏开关故障状态',
|
| | | batch.addLocator(3,MyModbusUtils.createInputLocator(4,master)); //'2号2500A进线屏开关合闸状态', |
| | | batch.addLocator(4,MyModbusUtils.createInputLocator(5,master)); //'2号2500A进线屏开关分闸状态', |
| | | batch.addLocator(5,MyModbusUtils.createInputLocator(6,master)); //'2号2500A进线屏开关故障状态', |
| | | batch.addLocator(6,MyModbusUtils.createInputLocator(7,master)); //'母联屏合闸状态', |
| | | batch.addLocator(7,MyModbusUtils.createInputLocator(8, master)); //'母联屏分闸状态', |
| | | batch.addLocator(8,MyModbusUtils.createInputLocator(9, master)); //'母联屏开关故障', |
| | | batch.addLocator(9,MyModbusUtils.createInputLocator(10,master)); //'1号2500A负载屏开关合闸状态', |
| | | batch.addLocator(10,MyModbusUtils.createInputLocator(11,master)); //'1号2500A负载屏开关分闸状态',
|
| | | batch.addLocator(11,MyModbusUtils.createInputLocator(12,master)); //'1号2500A负载屏开关故障状态',
|
| | | batch.addLocator(12,MyModbusUtils.createInputLocator(13,master)); //'2号2500A负载屏开关合闸状态',
|
| | | batch.addLocator(13,MyModbusUtils.createInputLocator(14,master)); //'2号2500A负载屏开关分闸状态',
|
| | | batch.addLocator(14,MyModbusUtils.createInputLocator(15,master)); //'2号2500A负载屏开关故障状态',
|
| | | |
| | | |
| | | batch.addLocator(15,MyModbusUtils.createBaseLocator(1,DataType.TWO_BYTE_INT_SIGNED,master)); //'A排电流',
|
| | | batch.addLocator(16,MyModbusUtils.createBaseLocator(2,DataType.TWO_BYTE_INT_SIGNED,master)); //'A排电压',
|
| | | batch.addLocator(17,MyModbusUtils.createBaseLocator(3,DataType.TWO_BYTE_INT_SIGNED,master)); //'B排电流',
|
| | | batch.addLocator(18,MyModbusUtils.createBaseLocator(4,DataType.TWO_BYTE_INT_SIGNED,master)); //'B排电压',
|
| | | |
| | | return batch;
|
| | | }
|
| | | |
| | | public void putBatchResult(BatchResults<Integer> res) {
|
| | | if(null != res) {
|
| | | switch_close_1st_2500A = (int) res.getValue(0); //'1号2500A进线屏开关合闸状态',
|
| | | switch_open_1st_2500A = (int) res.getValue(1); //'1号2500A进线屏开关分闸状态',
|
| | | switch_fault_1st_2500A = (int) res.getValue(2); //'1号2500A进线屏开关故障状态',
|
| | | switch_close_2st_2500A = (int) res.getValue(3); //'2号2500A进线屏开关合闸状态',
|
| | | switch_open_2st_2500A = (int) res.getValue(4); //'2号2500A进线屏开关分闸状态',
|
| | | switch_fault_2st_2500A = (int) res.getValue(5); //'2号2500A进线屏开关故障状态',
|
| | | switch_close_bus_screen = (int) res.getValue(6); //'母联屏合闸状态',
|
| | | switch_open_bus_screen = (int) res.getValue(7); //'母联屏分闸状态',
|
| | | switch_fault_bus_screen = (int) res.getValue(8); //'母联屏开关故障',
|
| | | switch_close_1st_2500A_load = (int) res.getValue(9); //'1号2500A负载屏开关合闸状态',
|
| | | switch_open_1st_2500A_load = (int) res.getValue(10); //'1号2500A负载屏开关分闸状态',
|
| | | switch_fault_1st_2500A_load = (int) res.getValue(11); //'1号2500A负载屏开关故障状态',
|
| | | switch_close_2st_2500A_load = (int) res.getValue(12); //'2号2500A负载屏开关合闸状态',
|
| | | switch_open_2st_2500A_load = (int) res.getValue(13); //'2号2500A负载屏开关分闸状态',
|
| | | switch_fault_2st_2500A_load = (int) res.getValue(14); //'2号2500A负载屏开关故障状态',
|
| | | curr_a = (float)res.getValue(15); //'A排电流',
|
| | | vol_a = (float)res.getValue(16); //'A排电压',
|
| | | curr_b = (float)res.getValue(17); //'B排电流',
|
| | | vol_b = (float)res.getValue(18); //'B排电压',
|
| | | }
|
| | | |
| | | }
|
| | | |
| | |
|
| | | public Central_ST_Data() {
|
| | |
|
| | |
| | | + ", switch_fault_2st_2500A_load=" + switch_fault_2st_2500A_load + ", curr_a=" + curr_a + ", vol_a="
|
| | | + vol_a + ", curr_b=" + curr_b + ", vol_b=" + vol_b + ", note=" + note + "]";
|
| | | }
|
| | | |
| | | }
|
| | |
| | | package com.data.Comm;
|
| | |
|
| | | import java.sql.ResultSet;
|
| | | import java.sql.SQLException;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import com.base.Com;
|
| | | import com.data.Central_RT_Data;
|
| | | import com.data.Central_ST_Data;
|
| | | import com.data.Motor_inf;
|
| | | import com.sql.MysqlConnPool;
|
| | | import com.sql.Sql_Mysql;
|
| | |
|
| | | public class Central_DataParsing_Thread_SQL {
|
| | |
|
| | | |
| | | public static void init(MysqlConnPool pool) {
|
| | | CreateTb_Central_Monitor_Sys_StTable(pool);
|
| | | |
| | | CreateTb_Central_Monitor_Sys_RtTable(pool);
|
| | | |
| | | CreateTb_Central_Monitor_Sys_ControlTable(pool);
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 创建tb_central_monitor_sys_st表
|
| | | * 加载集中监控平台设备设备信息
|
| | | * @param pool
|
| | | * @param motors
|
| | | */
|
| | | public static void CreateTb_Central_Monitor_Sys_StTable(MysqlConnPool pool) {
|
| | | String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Central_Monitor_Sys_St+" (" + |
| | | " num bigint(20) NOT NULL AUTO_INCREMENT," + |
| | | " dev_id int(11) NOT NULL DEFAULT '0' COMMENT '设备id'," + |
| | | " record_time datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '更新时间'," + |
| | | " switch_close_1st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A进线屏开关合闸状态'," + |
| | | " switch_open_1st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A进线屏开关分闸状态'," + |
| | | " switch_fault_1st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A进线屏开关故障状态'," + |
| | | " switch_close_2st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A进线屏开关合闸状态'," + |
| | | " switch_open_2st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A进线屏开关分闸状态'," + |
| | | " switch_fault_2st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A进线屏开关故障状态'," + |
| | | " switch_close_bus_screen int(11) NOT NULL DEFAULT '0' COMMENT '母联屏合闸状态'," + |
| | | " switch_open_bus_screen int(11) NOT NULL DEFAULT '0' COMMENT '母联屏分闸状态'," + |
| | | " switch_fault_bus_screen int(11) NOT NULL DEFAULT '0' COMMENT '母联屏开关故障'," + |
| | | " switch_close_1st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A负载屏开关合闸状态'," + |
| | | " switch_open_1st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A负载屏开关分闸状态'," + |
| | | " switch_fault_1st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A负载屏开关故障状态'," + |
| | | " switch_close_2st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A负载屏开关合闸状态'," + |
| | | " switch_open_2st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A负载屏开关分闸状态'," + |
| | | " switch_fault_2st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A负载屏开关故障状态'," + |
| | | " curr_a float NOT NULL DEFAULT '0' COMMENT 'A排电流'," + |
| | | " vol_a float NOT NULL DEFAULT '0' COMMENT 'A排电压'," + |
| | | " curr_b float NOT NULL DEFAULT '0' COMMENT 'B排电流'," + |
| | | " vol_b float NOT NULL DEFAULT '0' COMMENT 'B排电压'," + |
| | | " note varchar(255) NOT NULL DEFAULT '' COMMENT '备用'," + |
| | | " PRIMARY KEY (num)" + |
| | | ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
| | | public static void loadDeviceData(MysqlConnPool pool,List<Motor_inf> motors) {
|
| | | String sql_str = " SELECT * FROM " + Sql_Mysql.Tb_MW_Motor_inf + " WHERE sys_id = 100001";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | ResultSet res = null;
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | | res = sql.sqlMysqlQuery(sql_str);
|
| | | while(res.next()) {
|
| | | Motor_inf motor = new Motor_inf(res.getInt("dev_id"));
|
| | | motor.setDev_ip(res.getString("dev_ip"));
|
| | | motor.setDev_name(res.getString("dev_name"));
|
| | | motor.setSys_id(res.getInt("sys_id"));
|
| | | motor.setSys_name(res.getString("sys_name"));
|
| | | motor.setNote(res.getString("note"));
|
| | | motors.add(motor);
|
| | | }
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(), e);
|
| | | sql.logger.error(e.toString(),e);
|
| | | } finally {
|
| | | if(null != res) {
|
| | | try {
|
| | | res.close();
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | }
|
| | | }
|
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 创建tb_central_monitor_sys_rt表
|
| | | * 插入或更新直流主配信息
|
| | | * @param pool
|
| | | * @param stdata
|
| | | */
|
| | | public static void CreateTb_Central_Monitor_Sys_RtTable(MysqlConnPool pool) {
|
| | | String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Central_Monitor_Sys_Rt+" (" + |
| | | " num bigint(20) NOT NULL AUTO_INCREMENT," + |
| | | " dev_id int(11) NOT NULL DEFAULT '0' COMMENT '设备id'," + |
| | | " record_time datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '更新时间'," + |
| | | " switch_close int(11) NOT NULL DEFAULT '0' COMMENT '开关合闸状态'," + |
| | | " switch_open int(11) NOT NULL DEFAULT '0' COMMENT '开关分闸状态'," + |
| | | " switch_fault int(11) NOT NULL DEFAULT '0' COMMENT '开关故障状态'," + |
| | | " panel_vol float(11,0) NOT NULL DEFAULT '0' COMMENT '进线屏电压'," + |
| | | " panel_curr float(11,0) NOT NULL DEFAULT '0' COMMENT '进线屏电流'," + |
| | | " note varchar(255) NOT NULL DEFAULT '0' COMMENT '备用'," + |
| | | " PRIMARY KEY (num)" + |
| | | ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
| | | public static void insertOrUpdateTb_Central_Monitor_Sys_St(MysqlConnPool pool,Central_ST_Data stdata) {
|
| | | String sql_str_sel = " select dev_id from " + Sql_Mysql.Tb_Central_Monitor_Sys_St + " where dev_id = " + stdata.getDev_id();
|
| | | String sql_str_ins = " intsert into " + Sql_Mysql.Tb_Central_Monitor_Sys_St + "(dev_id) values("+stdata.getDev_id()+")";
|
| | | String sql_str_upd = " update " + Sql_Mysql.Tb_Central_Monitor_Sys_St + ""
|
| | | + " SET record_time '" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)
|
| | | + "',switch_close_1st_2500A = " + stdata.getSwitch_close_1st_2500A()
|
| | | + ",switch_open_1st_2500A = " + stdata.getSwitch_open_1st_2500A()
|
| | | + ",switch_fault_1st_2500A = " + stdata.getSwitch_fault_1st_2500A()
|
| | | + ",switch_close_2st_2500A = " + stdata.getSwitch_close_2st_2500A()
|
| | | + ",switch_open_2st_2500A = " + stdata.getSwitch_open_2st_2500A()
|
| | | + ",switch_fault_2st_2500A = " + stdata.getSwitch_fault_2st_2500A()
|
| | | + ",switch_close_bus_screen = " + stdata.getSwitch_close_bus_screen()
|
| | | + ",switch_open_bus_screen = " + stdata.getSwitch_open_bus_screen()
|
| | | + ",switch_fault_bus_screen = " + stdata.getSwitch_fault_bus_screen()
|
| | | + ",switch_close_1st_2500A_load = " + stdata.getSwitch_close_1st_2500A_load()
|
| | | + ",switch_open_1st_2500A_load = " + stdata.getSwitch_open_1st_2500A_load()
|
| | | + ",switch_fault_1st_2500A_load = " + stdata.getSwitch_fault_1st_2500A_load()
|
| | | + ",switch_close_2st_2500A_load = " + stdata.getSwitch_close_2st_2500A_load()
|
| | | + ",switch_open_2st_2500A_load = " + stdata.getSwitch_open_2st_2500A_load()
|
| | | + ",switch_fault_2st_2500A_load = " + stdata.getSwitch_fault_2st_2500A_load()
|
| | | + ",curr_a = " + stdata.getCurr_a()
|
| | | + ",vol_a = " + stdata.getVol_a()
|
| | | + ",curr_b = " + stdata.getCurr_b()
|
| | | + ",vol_b = " + stdata.getVol_b()
|
| | | + " Where dev_id = " + stdata.getDev_id();
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | ResultSet res = null;
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(), e);
|
| | | res = sql.sqlMysqlQuery(sql_str_sel);
|
| | | if(res.next()) {
|
| | | sql.sqlMysqlExecute(sql_str_upd);
|
| | | }else {
|
| | | sql.sqlMysqlExecute(sql_str_ins);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | } finally {
|
| | | if(null != res) {
|
| | | try {
|
| | | res.close();
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | }
|
| | | }
|
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 创建tb_central_monitor_sys_control表
|
| | | * 插入或更新进出线屏信息
|
| | | * @param pool
|
| | | * @param rtdata
|
| | | */
|
| | | public static void CreateTb_Central_Monitor_Sys_ControlTable(MysqlConnPool pool) {
|
| | | String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Central_Monitor_Sys_Control+" (" + |
| | | " num bigint(20) NOT NULL," + |
| | | " dev_id int(11) NOT NULL DEFAULT '0' COMMENT '设备id'," + |
| | | " op_cmd int(11) NOT NULL DEFAULT '0' COMMENT '命令控制'," + |
| | | " switch_close_1st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A进线屏开关合闸'," + |
| | | " switch_open_1st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A进线屏开关分闸'," + |
| | | " switch_close_2st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A进线屏开关合闸'," + |
| | | " switch_open_2st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A进线屏开关分闸'," + |
| | | " switch_close_bus_screen int(11) NOT NULL DEFAULT '0' COMMENT '母联屏开关合闸'," + |
| | | " switch_open_bus_screen int(11) NOT NULL DEFAULT '0' COMMENT '母联屏开关分闸'," + |
| | | " switch_close_1st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A负载屏开关合闸'," + |
| | | " switch_open_1st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A负载屏开关分闸'," + |
| | | " switch_close_2st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A负载屏开关合闸'," + |
| | | " switch_open_2st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A负载屏开关分闸'," + |
| | | " PRIMARY KEY (num)" + |
| | | ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
| | | public static void insertOrUpdateTb_Central_Monitor_Sys_Rt(MysqlConnPool pool,Central_RT_Data rtdata) {
|
| | | String sql_str_sel = " select dev_id from " + Sql_Mysql.Tb_Central_Monitor_Sys_Rt + " where dev_id = " + rtdata.getDev_id();
|
| | | String sql_str_ins = " intsert into " + Sql_Mysql.Tb_Central_Monitor_Sys_Rt + "(dev_id) values("+rtdata.getDev_id()+")";
|
| | | String sql_str_upd = " update " + Sql_Mysql.Tb_Central_Monitor_Sys_Rt + ""
|
| | | + " SET record_time '" + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms)
|
| | | + "',switch_close = " + rtdata.getSwitch_close()
|
| | | + ",switch_open = " + rtdata.getSwitch_open()
|
| | | + ",switch_fault = " + rtdata.getSwitch_fault()
|
| | | + ",panel_vol = " + rtdata.getPanel_vol()
|
| | | + ",panel_curr = " + rtdata.getPanel_curr()
|
| | | + " Where dev_id = " + rtdata.getDev_id();
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | ResultSet res = null;
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(), e);
|
| | | res = sql.sqlMysqlQuery(sql_str_sel);
|
| | | if(res.next()) {
|
| | | sql.sqlMysqlExecute(sql_str_upd);
|
| | | }else {
|
| | | sql.sqlMysqlExecute(sql_str_ins);
|
| | | }
|
| | | } catch (Exception e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | } finally {
|
| | | if(null != res) {
|
| | | try {
|
| | | res.close();
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | }
|
| | | }
|
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | }
|
New file |
| | |
| | | package com.data.Comm;
|
| | |
|
| | | import com.data.Central_RT_Data;
|
| | | import com.data.Central_ST_Data;
|
| | | import com.data.Motor_inf;
|
| | | import com.modbus.data.MyModbusMaster;
|
| | | import com.modbus.data.MyModbusUtils;
|
| | | import com.serotonin.modbus4j.BatchRead;
|
| | | import com.serotonin.modbus4j.BatchResults;
|
| | | import com.sql.MysqlConnPool;
|
| | |
|
| | | public class Central_Data_SocketClient_Thread implements Runnable{
|
| | | public static int Dev_Type_LineScreen = 10004; //进出线屏
|
| | | public static int Dev_Type_DcDistribute = 10005; //直流主配
|
| | | |
| | | private MysqlConnPool pool;
|
| | | private Motor_inf motor;
|
| | | private MyModbusMaster master;
|
| | | |
| | | public Central_Data_SocketClient_Thread(MysqlConnPool pool, Motor_inf motor) {
|
| | | this.motor = motor;
|
| | | this.pool = pool;
|
| | | |
| | | master = new MyModbusMaster(motor.getDev_ip(), MyModbusMaster.SLAVEID_DEFAULT);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void run() {
|
| | | int run_count = 0;
|
| | | while(true) {
|
| | | try { |
| | | if(run_count % 2 == 0) {
|
| | | if(Dev_Type_DcDistribute == motor.getDev_id()) {
|
| | | //读取直流主配信息
|
| | | readDcDistributinf(motor.stdata);
|
| | | Central_DataParsing_Thread_SQL.insertOrUpdateTb_Central_Monitor_Sys_St(pool, motor.stdata);
|
| | | }else {
|
| | | //读取进出线屏数据信息
|
| | | readLineScreeninf(motor.rtdata);
|
| | | Central_DataParsing_Thread_SQL.insertOrUpdateTb_Central_Monitor_Sys_Rt(pool, motor.rtdata);
|
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | motor.conn_state = master.getConnectState();
|
| | | if(run_count > 999909) {
|
| | | run_count = 0;
|
| | | }
|
| | | run_count ++; |
| | | Thread.sleep(200);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | } |
| | | }
|
| | | |
| | | /**
|
| | | * 读取直流主配信息
|
| | | * @param stdata
|
| | | */
|
| | | public void readDcDistributinf(Central_ST_Data stdata) {
|
| | | BatchRead<Integer> batch = stdata.createBatchRead(master); |
| | | BatchResults<Integer> res = MyModbusUtils.readMutilRegisters(batch, master);
|
| | | stdata.putBatchResult(res);
|
| | | }
|
| | | |
| | | /**
|
| | | * 读取进出线屏信息
|
| | | * @param stdata
|
| | | */
|
| | | public void readLineScreeninf(Central_RT_Data rtdata) {
|
| | | BatchRead<Integer> batch = rtdata.createBatchRead(master); |
| | | BatchResults<Integer> res = MyModbusUtils.readMutilRegisters(batch, master);
|
| | | rtdata.putBatchResult(res);
|
| | | }
|
| | | |
| | | }
|
New file |
| | |
| | | package com.data.Comm;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import org.apache.logging.log4j.LogManager;
|
| | | import org.apache.logging.log4j.Logger;
|
| | |
|
| | | import com.base.Com;
|
| | | import com.data.Motor_inf;
|
| | | import com.sql.MysqlConnPool;
|
| | |
|
| | | public class Central_Data_SocketServer_Thread extends Thread{
|
| | | public static int Dev_Type_LineScreen = 10004; //进出线屏
|
| | | public static int Dev_Type_DcDistribute = 10005; //直流主配
|
| | | |
| | | |
| | | private MysqlConnPool pool;
|
| | | private List<Motor_inf> motors;
|
| | | private Logger logger = null;
|
| | | |
| | | |
| | | public Central_Data_SocketServer_Thread(MysqlConnPool pool,List<Motor_inf> motors) {
|
| | | this.pool = pool;
|
| | | this.motors = motors;
|
| | | logger = LogManager.getFormatterLogger(this.getClass());
|
| | | }
|
| | | |
| | | @Override
|
| | | public void run() {
|
| | | logger.trace(" Central_Data_SocketServer_Thread Start at " + Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
| | | for(int i = 0;i<motors.size();i++) {
|
| | | Motor_inf motor = motors.get(i);
|
| | | Central_Data_SocketClient_Thread socket = new Central_Data_SocketClient_Thread(pool,motor); |
| | | }
|
| | | }
|
| | | }
|
New file |
| | |
| | | package com.data.Comm;
|
| | |
|
| | | import java.sql.SQLException;
|
| | |
|
| | | import com.sql.MysqlConnPool;
|
| | | import com.sql.Sql_Mysql;
|
| | |
|
| | | public class Central_Data_Task_SQL {
|
| | | |
| | | public static void init(MysqlConnPool pool) {
|
| | | CreateDB_MW_Motor(pool);
|
| | | |
| | | CreateDB_MW_Motor_History(pool); |
| | | |
| | | CreateTb_Central_Monitor_Sys_StTable(pool);
|
| | | |
| | | CreateTb_Central_Monitor_Sys_RtTable(pool);
|
| | | |
| | | CreateTb_Central_Monitor_Sys_ControlTable(pool);
|
| | | }
|
| | | |
| | | /**
|
| | | * 构造3.5mw数据库
|
| | | * @param pool
|
| | | */
|
| | | public static void CreateDB_MW_Motor(MysqlConnPool pool) {
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(" CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.DB_MW_Motor);
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 构造3.5mw历史实时数据库
|
| | | * @param pool
|
| | | */
|
| | | public static void CreateDB_MW_Motor_History(MysqlConnPool pool) {
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(" CREATE DATABASE IF NOT EXISTS " + Sql_Mysql.DB_MW_Motor_History);
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 创建tb_central_monitor_sys_st表
|
| | | * @param pool
|
| | | */
|
| | | public static void CreateTb_Central_Monitor_Sys_StTable(MysqlConnPool pool) {
|
| | | String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Central_Monitor_Sys_St+" (" + |
| | | " num bigint(20) NOT NULL AUTO_INCREMENT," + |
| | | " dev_id int(11) NOT NULL DEFAULT '0' COMMENT '设备id'," + |
| | | " record_time datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '更新时间'," + |
| | | " switch_close_1st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A进线屏开关合闸状态'," + |
| | | " switch_open_1st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A进线屏开关分闸状态'," + |
| | | " switch_fault_1st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A进线屏开关故障状态'," + |
| | | " switch_close_2st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A进线屏开关合闸状态'," + |
| | | " switch_open_2st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A进线屏开关分闸状态'," + |
| | | " switch_fault_2st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A进线屏开关故障状态'," + |
| | | " switch_close_bus_screen int(11) NOT NULL DEFAULT '0' COMMENT '母联屏合闸状态'," + |
| | | " switch_open_bus_screen int(11) NOT NULL DEFAULT '0' COMMENT '母联屏分闸状态'," + |
| | | " switch_fault_bus_screen int(11) NOT NULL DEFAULT '0' COMMENT '母联屏开关故障'," + |
| | | " switch_close_1st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A负载屏开关合闸状态'," + |
| | | " switch_open_1st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A负载屏开关分闸状态'," + |
| | | " switch_fault_1st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A负载屏开关故障状态'," + |
| | | " switch_close_2st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A负载屏开关合闸状态'," + |
| | | " switch_open_2st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A负载屏开关分闸状态'," + |
| | | " switch_fault_2st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A负载屏开关故障状态'," + |
| | | " curr_a float NOT NULL DEFAULT '0' COMMENT 'A排电流'," + |
| | | " vol_a float NOT NULL DEFAULT '0' COMMENT 'A排电压'," + |
| | | " curr_b float NOT NULL DEFAULT '0' COMMENT 'B排电流'," + |
| | | " vol_b float NOT NULL DEFAULT '0' COMMENT 'B排电压'," + |
| | | " note varchar(255) NOT NULL DEFAULT '' COMMENT '备用'," + |
| | | " PRIMARY KEY (num)," + |
| | | " KEY `index_dev_id` (`dev_id`) USING BTREE" + |
| | | ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(), e);
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 创建tb_central_monitor_sys_rt表
|
| | | * @param pool
|
| | | */
|
| | | public static void CreateTb_Central_Monitor_Sys_RtTable(MysqlConnPool pool) {
|
| | | String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Central_Monitor_Sys_Rt+" (" + |
| | | " num bigint(20) NOT NULL AUTO_INCREMENT," + |
| | | " dev_id int(11) NOT NULL DEFAULT '0' COMMENT '设备id'," + |
| | | " record_time datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '更新时间'," + |
| | | " switch_close int(11) NOT NULL DEFAULT '0' COMMENT '开关合闸状态'," + |
| | | " switch_open int(11) NOT NULL DEFAULT '0' COMMENT '开关分闸状态'," + |
| | | " switch_fault int(11) NOT NULL DEFAULT '0' COMMENT '开关故障状态'," + |
| | | " panel_vol float(11,0) NOT NULL DEFAULT '0' COMMENT '进线屏电压'," + |
| | | " panel_curr float(11,0) NOT NULL DEFAULT '0' COMMENT '进线屏电流'," + |
| | | " note varchar(255) NOT NULL DEFAULT '0' COMMENT '备用'," + |
| | | " PRIMARY KEY (num)," + |
| | | " KEY `index_dev_id` (`dev_id`) USING BTREE" + |
| | | ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(), e);
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 创建tb_central_monitor_sys_control表
|
| | | * @param pool
|
| | | */
|
| | | public static void CreateTb_Central_Monitor_Sys_ControlTable(MysqlConnPool pool) {
|
| | | String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Central_Monitor_Sys_Control+" (" + |
| | | " num bigint(20) NOT NULL," + |
| | | " dev_id int(11) NOT NULL DEFAULT '0' COMMENT '设备id'," + |
| | | " op_cmd int(11) NOT NULL DEFAULT '0' COMMENT '命令控制'," + |
| | | " switch_close_1st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A进线屏开关合闸'," + |
| | | " switch_open_1st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A进线屏开关分闸'," + |
| | | " switch_close_2st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A进线屏开关合闸'," + |
| | | " switch_open_2st_2500A int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A进线屏开关分闸'," + |
| | | " switch_close_bus_screen int(11) NOT NULL DEFAULT '0' COMMENT '母联屏开关合闸'," + |
| | | " switch_open_bus_screen int(11) NOT NULL DEFAULT '0' COMMENT '母联屏开关分闸'," + |
| | | " switch_close_1st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A负载屏开关合闸'," + |
| | | " switch_open_1st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '1号2500A负载屏开关分闸'," + |
| | | " switch_close_2st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A负载屏开关合闸'," + |
| | | " switch_open_2st_2500A_load int(11) NOT NULL DEFAULT '0' COMMENT '2号2500A负载屏开关分闸'," + |
| | | " PRIMARY KEY (num)," + |
| | | " KEY `index_dev_id` (`dev_id`) USING BTREE" + |
| | | ") ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(), e);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | private String note;
|
| | |
|
| | | public Central_Control control;
|
| | | public Central_RT_Data rddata;
|
| | | public Central_RT_Data rtdata;
|
| | | public Central_ST_Data stdata;
|
| | |
|
| | | |
| | | public int conn_state = 0; //连接状态1:通讯正常 0:通讯中断
|
| | | public Motor_inf() {
|
| | |
|
| | | }
|
| | |
| | | public Motor_inf(int dev_id) {
|
| | | this.dev_id = dev_id;
|
| | | control = new Central_Control(dev_id);
|
| | | rddata = new Central_RT_Data(dev_id); |
| | | rtdata = new Central_RT_Data(dev_id); |
| | | stdata = new Central_ST_Data(dev_id);
|
| | | }
|
| | |
|
| | |
| | | } |
| | | |
| | | /** |
| | | * 构造读取节点 |
| | | * 构造离散输入读取节点 |
| | | * @param offset |
| | | * @param master |
| | | * @return |
| | | */ |
| | | public static BaseLocator<?> createInputLocator(int offset,MyModbusMaster master) { |
| | | return BaseLocator.inputStatus(master.getSlaveId(), offset); |
| | | } |
| | | |
| | | /** |
| | | * 构造保持寄存器读取节点 |
| | | * @param offset |
| | | * @param master |
| | | * @return |
| | |
| | | |
| | | public final static String Tb_Device_ConnectState = DB_Electric2MWSystem+".tb_device_connectstate"; //设备通讯状态表 |
| | | //--------------------------------------------------------------------------------------------// |
| | | public final static String Tb_MW_Motor_inf = DB_MW_Motor + ".tb_3.5mw_motor_inf"; |
| | | public final static String Tb_MW_Motor_inf = DB_MW_Motor + ".`tb_3.5mw_motor_inf`"; |
| | | public final static String Tb_Central_Monitor_Sys_St = DB_MW_Motor + ".tb_central_monitor_sys_st"; |
| | | public final static String Tb_Central_Monitor_Sys_Rt = DB_MW_Motor + ".tb_central_monitor_sys_rt"; |
| | | public final static String Tb_Central_Monitor_Sys_Control = DB_MW_Motor + ".tb_central_monitor_sys_control"; |
| | |
| | | package main; |
| | | import java.sql.Connection; |
| | | import java.sql.SQLException; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import org.apache.logging.log4j.LogManager; |
| | | import org.apache.logging.log4j.Logger; |
| | | import com.base.Com; |
| | | import com.config.AppConfig; |
| | | import com.data.Motor_inf; |
| | | import com.data.Comm.Central_DataParsing_Thread_SQL; |
| | | import com.data.Comm.Central_Data_Task_SQL; |
| | | import com.sql.MysqlConnPool; |
| | | |
| | | public class main_Central_Monitor { |
| | |
| | | private static MysqlConnPool GB_MysqlConnPool; |
| | | |
| | | private static Logger logger = null; |
| | | |
| | | private static List<Motor_inf> motors = new ArrayList<>(); |
| | | |
| | | static{ |
| | | |
| | |
| | | //初始化连接池中的各种参数信息 |
| | | GB_MysqlConnPool = new MysqlConnPool(m_AppConfig.getMysqlServerIp(), MysqlServer_Port,m_AppConfig.getMysqlConnCountMax()); |
| | | |
| | | |
| | | /*********************************************************************************/ |
| | | /*********************************************************************************/ |
| | | |
| | | Central_DataParsing_Thread_SQL.loadDeviceData(GB_MysqlConnPool, motors); //加载集中监控系统设备信息 |
| | | |
| | | |
| | | |