简体   繁体   English

Java 用RXTX库识别AT指令

[英]Java recognize AT commands with RXTX library

I'm going to read COM port in java with RXTX library.我将使用 RXTX 库读取 java 中的 COM 端口。 I want to recognize the flow of char in AT commands.我想识别 AT 命令中的字符流。

My reading function cycle a buffer and save all on a String var.我的阅读 function 循环缓冲区并将所有内容保存在 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);
}

How can I create the timer in the background?如何在后台创建计时器? There are better solutions or functions already made?有更好的解决方案或功能吗?

I hope to be able to explain myself.我希望能够解释自己。 Thanks to all!谢谢大家!

Use java.util.Timer.使用 java.util.Timer。 This is exactly what you need.这正是您所需要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM