简体   繁体   中英

Communicating with an XBee module using Java

I want to connect my xbee-api-0.9 module Java and communicate with it by sending AT commands.

import com.rapplogic.xbee.api.XBee;
import com.rapplogic.xbee.api.XBeeException;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class Xbee_1 {
    private final static Logger log = Logger.getLogger(Xbee_1.class);
    public static void main( String []args){
        PropertyConfigurator.configure("log4j.properties");
        XBee xbee = new XBee();
        try {
            xbee.open("COM34", 9600);
        } catch (XBeeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println("nepeut pas s'ouvr");
        }
        System.out.println("ok");
    }
}

Digi has an Open Source Java library to interface with their XBee modules. It was announced earlier this year. I suggest that you use that as your starting point.

Creating XBee applications just got way easier. Gone are the days of toiling away for every inch of code. In order to make it as simple as possible for you to write applications that interact with XBee, we have created the XBee Java Library. This library supports ZigBee, 802.15.4, DigiMesh and Point-to-Multipoint XBee devices!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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