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);
|
}
|
|
}
|