WirelessLCDSystem.java 文件源码

java
阅读 18 收藏 0 点赞 0 评论 0

项目:EmbeddedMonitor 作者:
@Override
public void serialEvent(SerialPortEvent spe) {
    if (SerialPortEvent.DATA_AVAILABLE == spe.getEventType()) {
        // avoid the high frequency of the notifying
        // just check the read thread first 
        // and then choose to restart or ignore the notity
        if((null != serialReadThread) && serialReadThread.isAlive()){
            // do nothing here
            // or you can close the notify here
            // and open when the thread is done
            serialPort.notifyOnDataAvailable(false);
        }else{
            // you must re-run the thread
            // here you need only one method but using thread.start() with two
            // same thread
            // here you can use start, because we already know that the 
            // thread is dead
            // here you can't use the start method again 
            // the data is already exist,
            // so just use run to make it run again
            //srialReadThread.start();
            // you can never restart a thread again
            serialReadThread = new Thread(new SerialReader(serialIn)); 
            // start it
            serialReadThread.start();
        }
    }// end if
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号