从串行输入流中读取数据

时间:2013-11-13 23:20:04

标签: java arduino

我正在编写一个程序,通过串口与Arduino进行通信,然后返回String(长度为70,以*#结尾)。在我的主要内容中,我想阅读此String,我该怎么做?

public static synchronized void serialEvent(SerialPortEvent oEvent) {
     if (oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE) {
         try {
             String inputLine=input.readLine();
             if (inputLine.endsWith("*#")){

                read = inputLine;
             }
             System.out.println(inputLine);
         } catch (Exception e) {
             System.err.println(e.toString());
         } 
     }
}

system.out正在返回字符串,但是当我在main中打印'read'时,它出现了垃圾(我认为是指向我输入缓冲区的指针)。 read是一个静态字符串,这是静态的意思是我不能改变它的值吗?

0 个答案:

没有答案
相关问题