SerialReader.java 文件源码

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

项目:ArduinoDB 作者:
/**
 * Handle an event on the serial port. Read the data and print it.
 */
public synchronized void serialEvent(SerialPortEvent oEvent) {
    //System.out.println("Serial event successfully triggered");

           if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
        try {
                               String inputLine = null;
                               if(input.ready()){
            inputLine=input.readLine();
            System.out.println(inputLine);

                               //StringTokenizer to read an entire line of tata. It is expected that successive
                               //reads are in successive lines. 
                               StringTokenizer stringTokenizer = new StringTokenizer(inputLine,",");

                               String arduinoID = stringTokenizer.nextToken();
                               statement.setString(1,arduinoID);
                               System.out.println(arduinoID);
                               String humidity = stringTokenizer.nextToken();
                               System.out.println(humidity);
                               statement.setString(2,humidity);                                
                               String temperature = stringTokenizer.nextToken();
                               System.out.println(temperature);
                               statement.setString(3,temperature);
                               statement.executeUpdate();



                               }
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }
    // Ignore all the other eventTypes, but you should consider the other ones.
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号