I have a USB interface board with XBee Pro Series 2 connected to my computer. X-CTU works well for the module, such as range test, neighbor discovery, etc.
Now I tried to control the module from my own program. After reading some references, I tried xbee-api written in Java.
http://code.google.com/p/xbee-api/
I have set my XBee module to be API mode 2. Then I tried ApiAtTest example in the code, the simplest example.
Oops, I got the following error:
Stable Library
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
[2010-04-19 17:43:42,865] [XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.XBeePacketParser] Read base10=126,base16=0x7e,base2=01111110 from input stream
[2010-04-19 17:43:42,891] [XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.PacketStream] Read Length MSB byte, val is base10=0,base16=0x00,base2=00000000
[2010-04-19 17:43:42,892] [XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.PacketStream] Read Length LSB byte, val is base10=4,base16=0x04,base2=00000100
[2010-04-19 17:43:42,893] [XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.PacketStream] Read API ID byte, val is base10=8,base16=0x08,base2=00001000
[2010-04-19 17:43:42,893] [XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.PacketStream] Read Checksum byte, val is base10=1,base16=0x01,base2=00000001
[2010-04-19 17:43:42,896] [XBee Packet Parser Thread] [ERROR] [com.rapplogic.xbee.api.PacketStream] Failed due to exception. Returning ErrorResponse. bytes read: 0x00 0x04 0x08 0x01
java.lang.NullPointerException
at com.rapplogic.xbee.api.PacketStream.parsePacket(PacketStream.java:151)
at com.rapplogic.xbee.api.XBeePacketParser.run(XBeePacketParser.java:73)
at java.lang.Thread.run(Unknown Source)
[2010-04-19 17:43:42,899] [XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.XBeePacketParser] Read base10=77,base16=0x4d,base2=01001101 from input stream
[2010-04-19 17:43:42,899] [XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.XBeePacketParser] expected start byte but got this 0x4d, discarding
[2010-04-19 17:43:42,900] [XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.XBeePacketParser] Read base10=89,base16=0x59,base2=01011001 from input stream
[2010-04-19 17:43:42,901] [XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.XBeePacketParser] expected start byte but got this 0x59, discarding
[2010-04-19 17:43:42,901] [XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.XBeePacketParser] Read base10=80,base16=0x50,base2=01010000 from input stream
[2010-04-19 17:43:42,902] [XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.XBeePacketParser] expected start byte but got this 0x50, discarding
Exception in thread “main” [2010-04-19 17:43:47,954] [XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.XBeePacketParser] Packet parser thread was interrupted
[2010-04-19 17:43:47,955] [XBee Packet Parser Thread] [WARN] [com.rapplogic.xbee.api.XBeePacketParser] Packet parser thread is exiting
com.rapplogic.xbee.api.XBeeTimeoutException
at com.rapplogic.xbee.api.XBee.sendSynchronous(XBee.java:236)
at com.rapplogic.xbee.api.XBee.sendAtCommand(XBee.java:159)
at com.rapplogic.xbee.examples.ApiAtTest.(ApiAtTest.java:70)
at com.rapplogic.xbee.examples.ApiAtTest.main(ApiAtTest.java:106)
I debugged the program slowly and carefully and found that the response I got is the AT command I sent.
I sent 0x7e 0x00 0x04 0x08 0x01 0x4d 0x59 0x50, the “MY” command API-packet. It is expected to get response of MY, such as “5767” got from X-CTU. However, I got 0x7e 0x00 0x04 0x08 0x01 0x4d 0x59 0x50 again. As 0x08 is the API-ID, it represents for AT Command. While there is no such kind of response, the error above happened.
I am very confusing about this now and don’t know how to forward. Wish someone can give me some suggestion. Thank you very much first.