0

我将使用 RXTX 库读取 java 中的 COM 端口。我想识别 AT 命令中的字符流。

我的阅读功能循环缓冲区并将所有内容保存在 String var 上。

InputStream in; //var sent to function

byte[] buffer = new byte[1024];
int len = -1;

try{
    while ((len = in.read(buffer)>-1){
        String s = new String(buffer,0,len);

        // I've think to save all string into a global var and ciclically
        // read after delay che global string and analyze it for bring the 
        // AT commands
        Global.__GLstring += s;

        System.out.print(s); 
        /* Example sout:

           AT

           OK

           BLABLABLA
           ERROR
        */

    }
} catch (IOException e){
        syserr("Exception"+e);
}

如何在后台创建计时器?有更好的解决方案或功能吗?

我希望能够解释自己。谢谢大家!

4

1 回答 1

1

使用 java.util.Timer。这正是您所需要的。

于 2011-08-14T15:58:02.883 回答