2014-09-03 102 views
0

我想通過使用java api庫來打開和關閉Xbee的引腳與不同的xbee(XB24-ZB)。使用Xbee java API

這是我的系統cunfig: 1.XBEE - Routher API(COM7) 2.XBEE - 協調員API(COM17)

其中兩個是用相同的ID。 我使用的代碼〔實施例:

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(); 

當我運行的代碼塊上的XBee#的DI0 1確實發生了改變,但爲0(禁用),而不是5 我也得到這個錯誤:

log4j:WARN No appenders could be found for logger (com.rapplogic.xbee.api.InputStreamThread). log4j:WARN No appenders could be found for logger (com.rapplogic.xbee.api.InputStreamThread). log4j:WARN Please initialize the log4j system properly. log4j:WARN Please initialize the log4j system properly.

「AP」被設置爲2,並且我得到的迴應很好。 那麼我在這裏錯過了什麼? 謝謝

回答

0

嘗試使用這些進口:

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

此行添加到您的類:

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

而且,在main()內,把這個行開始:

PropertyConfigurator.configure("log4j.properties"); 

我把它從API src文件夾裏的代碼示例中拿出來了,我的程序運行得很好。