PortRXTX.java 文件源码

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

项目:project-bianca 作者:
/**
 * rxtxlib's "serial event handling" - would be more simple if they just
 * implemented InputStream correctly :P
 */
@Override
public void serialEvent(SerialPortEvent event) {
    log.info(String.format("rxtx event on port %s", portName));

    Integer newByte = -1;

    try {
        while (listening && ((newByte = read()) > -1)) {
            // listener.onByte(newByte); // <-- FIXME ?? onMsg() < ???
            for (String key : listeners.keySet()) {
                listeners.get(key).onByte(newByte);
            }
            ++stats.total;
            if (stats.total % stats.interval == 0) {
                stats.ts = System.currentTimeMillis();
                log.error(String.format("===stats - dequeued total %d - %d bytes in %d ms %d Kbps", stats.total, stats.interval, stats.ts - stats.lastTS, 8 * stats.interval
                        / (stats.ts - stats.lastTS)));
                // publishQueueStats(stats);
                stats.lastTS = stats.ts;
            }
            // log.info(String.format("%d",newByte));
            // rxtx leave whenever it has no new data to delver with a -1
            // which is not what an Java InputStream is supposed to do.. 
        }

        log.info(String.format("%d",newByte));
    } catch (Exception e) {
        ++rxErrors;
        Logging.logError(e);
    } 

}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号