简体   繁体   English

使用Xbee Java API

[英]Using Xbee java API

I am trying to turn Xbee's pin on and off with a diffrent xbee(XB24-ZB) by using the java api library. 我正在尝试通过使用Java api库使用不同的xbee(XB24-ZB)打开和关闭Xbee的引脚。

This is my system cunfig: 1.XBEE - Routher API (COM7) 2.XBEE - Coordinator API (COM17) 这是我的系统计算机:1.XBEE-Routher API(COM7)2.XBEE-Coordinator API(COM17)

Two of them are with the same ID. 其中两个具有相同的ID。 I am using the exmaple code: 我正在使用示例代码:

XBee xbee = new XBee();
xbee.open("COM17", 9600);

// this is the Serial High (SH) + Serial Low (SL) of the remote XBee                    
XBeeAddress64 addr64 = new XBeeAddress64("00 13 A2 00 40 A7 3E 7E");

// Turn on DIO0 (Pin 20)
RemoteAtRequest request = new RemoteAtRequest(addr64, "D0", new int[XBeePin.Capability.DIGITAL_OUTPUT_HIGH.getValue()]);

xbee.sendAsynchronous(request);

RemoteAtResponse response = (RemoteAtResponse) xbee.getResponse();

if (response.isOk()) {
    System.out.println("Successfully turned on DIO0");
} else {
    System.out.println("Attempt to turn on DIO0 failed.  Status: " + response.getStatus());
}

// shutdown the serial port and associated threads
xbee.close();

When I run this block of code the DI0 on xbee #1 does change, but to 0(disabled) and not to 5. I also get this error: 当我运行此代码块时,xbee#1上的DI0确实发生了更改,但是更改为0(禁用)而不是5。我也遇到此错误:

log4j:WARN No appenders could be found for logger (com.rapplogic.xbee.api.InputStreamThread). log4j:WARN找不到记录程序(com.rapplogic.xbee.api.InputStreamThread)的附加程序。 log4j:WARN No appenders could be found for logger (com.rapplogic.xbee.api.InputStreamThread). log4j:WARN找不到记录程序(com.rapplogic.xbee.api.InputStreamThread)的附加程序。 log4j:WARN Please initialize the log4j system properly. log4j:WARN请正确初始化log4j系统。 log4j:WARN Please initialize the log4j system properly. log4j:WARN请正确初始化log4j系统。

The "AP" is set to 2 as said and the response I get is good. 如上所述,“ AP”设置为2,我得到的响应很好。 So what am I missing here? 那我在这里想念什么? Thank you 谢谢

Try to use these imports: 尝试使用以下导入:

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

Add this line to you class: 将此行添加到您的班级:

private final static Logger log = Logger.getLogger(YourClass.class);

And, inside the main(), put this line beginning: 然后,在main()中,将以下行开始:

PropertyConfigurator.configure("log4j.properties");

I took it from the code examples inside the API src folder, and with it my programs are running just fine. 我从API src文件夹中的代码示例中获取了它,并且我的程序运行得很好。

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

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