简体   繁体   English

在Java中从Xbee获取信息

[英]Getting Information From Xbee In Java

I m trying to get some information from my Xbee but it s not working 我正在尝试从Xbee获取一些信息,但是它不起作用

This is the code of my Class Test : 这是我的Class Test的代码:

 public static void main (String[] args){
     XBee xbee = new XBee();
     try {
        xbee.open("COM3", 9600);
    } catch (XBeeException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    while (true) {
        try {
            XBeeResponse response = xbee.getResponse(10000);
            // we got a response!
        } catch (XBeeTimeoutException e) {
            // we timed out without a response
        } catch (XBeeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

And im using Xbee API http://code.google.com/p/xbee-api/ 即时通讯使用Xbee API http://code.google.com/p/xbee-api/

but always i get this errors : 但总是我得到这个错误:

com.rapplogic.xbee.api.XBeeException: AT command timed-out while attempt to set/read in API mode. com.rapplogic.xbee.api.XBeeException:尝试在API模式下设置/读取时,AT命令超时。 The XBee radio must be in API mode (AP=2) to use with this library at com.rapplogic.xbee.api.XBee.doStartupChecks(XBee.java:124) at com.rapplogic.xbee.api.XBee.initConnection(XBee.java:170) at com.rapplogic.xbee.api.XBee.open(XBee.java:142) at com.mohamed.test.main(test.java:16) XBee无线电必须处于API模式(AP = 2)才能与此库一起在com.rapplogic.xbee.api.XBee.initConnection( com.rapplogic.xbee.api.XBee.open(XBee.java:142)的com.mohamed.test.main(test.java:16)的XBee.java:170)

Thank Youuuuuu 感谢Youuuuuu

What platform are you on? 您在什么平台上? If Windows, can you communicate with the XBee using Digi's X-CTU program? 如果是Windows,可以使用Digi的X-CTU程序与XBee通信吗? Have you confirmed the baud rate and that the module is in the right mode (ATAP must be set to 2)? 您是否已确认波特率并且模块处于正确模式(必须将ATAP设置为2)?

From the error, it looks like you haven't set the API mode for your XBee module to 2. Try to set it using X-CTU(windows based program). 从该错误看来,您尚未将XBee模块的API模式设置为2。请尝试使用X-CTU(基于Windows的程序)进行设置。 Here is an example how to using X-CTU to set API mode (XBee Series 2): Setting up X-Bee to API modde 这是如何使用X-CTU设置API模式(XBee系列2)的示例: 将X-Bee设置为API modde

I recomend you that use OutputStream and InputStream of package java.io to comunicate with XBee module by serial. 我建议您使用java.io包的OutputStream和InputStream通过串行方式与XBee模块通信。 With this class you can send and recevide module information. 使用此类,您可以发送和接收模块信息。 Sure that the module is in AT mode. 确保模块处于AT模式。

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

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