package com.dev.fbs9100;
|
|
import java.util.Enumeration;
|
|
import com.battdata_rt.BattData_RT_Array;
|
import com.config.AppConfig;
|
import com.sql.MysqlConnPool;
|
|
import gnu.io.CommPortIdentifier;
|
|
public class FBS9100S_SerialPortThread extends Thread{
|
private FBS9100S_SerialPortClient SerialPortClient; //´æ·Åµ±Ç°´®¿ÚͨÐŶÔÏó
|
private MysqlConnPool m_ConnPool = null;
|
private BattData_RT_Array m_Data;
|
private AppConfig m_app_cfg;
|
|
public FBS9100S_SerialPortThread(MysqlConnPool pool, BattData_RT_Array data, AppConfig cfg){
|
m_ConnPool = pool;
|
m_Data = data;
|
m_app_cfg = cfg;
|
}
|
|
@Override
|
public void run() {
|
System.out.println(this.getName() + " - FBS9100S_SerialPortThread Started");
|
System.out.println(m_app_cfg.getSerialPort()+"ÉèÖõĴ®¿ÚΪ");
|
while (true) {
|
try {
|
// »ñµÃµ±Ç°ËùÓпÉÓô®¿Ú
|
Enumeration<CommPortIdentifier> portList = CommPortIdentifier.getPortIdentifiers();
|
for(;portList.hasMoreElements();){
|
CommPortIdentifier port = portList.nextElement();
|
if (port.getPortType() == CommPortIdentifier.PORT_SERIAL) {
|
if(port.getName().equalsIgnoreCase(m_app_cfg.getSerialPort())){
|
if(SerialPortClient == null){
|
//Ê×´ÎÆô¶¯
|
SerialPortClient = new FBS9100S_SerialPortClient(port,m_ConnPool,m_Data);
|
SerialPortClient.start();
|
}else if(!SerialPortClient.S_thread_run_flag){
|
try {
|
if(SerialPortClient.serialPort != null){
|
SerialPortClient.serialPort.close();
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
//·ÇÊ×´ÎÆô¶¯,µ«ÊÇÉÏ´ÎͨÐÅʧ°Ü
|
sleep(1000);
|
SerialPortClient = new FBS9100S_SerialPortClient(port,m_ConnPool,m_Data);
|
SerialPortClient.start();
|
}
|
}
|
}
|
}
|
sleep(2000);
|
} catch (InterruptedException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
|
public static void main(String[] args) {
|
|
}
|
}
|