本文整理汇总了Java中com.rapplogic.xbee.api.XBee类的典型用法代码示例。如果您正苦于以下问题:Java XBee类的具体用法?Java XBee怎么用?Java XBee使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XBee类属于com.rapplogic.xbee.api包,在下文中一共展示了XBee类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ZNetIoSampleExample
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
private ZNetIoSampleExample() throws Exception {
XBee xbee = new XBee();
try {
// replace with the com port of your XBee coordinator
xbee.open("/dev/tty.usbserial-A6005v5M", 9600);
xbee.addPacketListener(this);
// wait forever
synchronized(this) { this.wait(); }
} finally {
if (xbee != null && xbee.isConnected()) {
xbee.close();
}
}
}
示例2: BroadcastReceiverExample
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
private BroadcastReceiverExample() throws XBeeException {
XBee xbee = new XBee();
try {
// replace with your com port and baud rate. this is the com port of my coordinator
xbee.open("/dev/tty.usbserial-A6005uPi", 9600);
while (true) {
XBeeResponse response = xbee.getResponse();
log.info("received response " + response);
}
} finally {
if (xbee != null && xbee.isConnected()) {
xbee.close();
}
}
}
示例3: setup
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
void setup() {
try {
//optional. set up logging
PropertyConfigurator.configure(dataPath("")+"log4j.properties");
xbee = new XBee();
// replace with your COM port
xbee.open("/dev/tty.usbserial-A6005v5M", 9600);
xbee.addPacketListener(new PacketListener() {
public void processResponse(XBeeResponse response) {
queue.offer(response);
}
}
);
}
catch (Exception e) {
System.out.println("XBee failed to initialize");
e.printStackTrace();
System.exit(1);
}
}
示例4: BroadcastReceiverExample
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
private BroadcastReceiverExample() throws XBeeException {
XBee xbee = new XBee();
try {
// replace with your com port and baud rate. this is the com port of my coordinator
xbee.open("/dev/tty.usbserial-A6005uPi", 9600);
while (true) {
XBeeResponse response = xbee.getResponse();
log.info("received response " + response);
}
} finally {
xbee.close();
}
}
示例5: main
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
lock = new Semaphore(1,true);
xbee = new XBee();
xbee.open(args[0],9600);
int initial_port = 8889;
int number_writers = 2;
for (int i=0; i<number_writers; i++){
(new Thread (new xbeeWrite(lock, br,xbee,initial_port))).start();
System.out.println("Started xBeeWriter on port "+initial_port);
initial_port++;
Thread.sleep(1000);
}
(new Thread (new xbeeRead(lock,xbee))).start();
(new Thread (new nodeDiscover(lock,xbee,30000,5))).start();
}catch(Exception e){
e.printStackTrace();
}
}
示例6: testJSSCStartup
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
public void testJSSCStartup() throws Exception {
// create the JSSCSerialComm object, this is the replacement object for the default RxTx one used internally.
JSSCSerialComm serial = new JSSCSerialComm();
// connect to COM7 at 115200 baud. 8 bits, 1 stop bit, 0 parity is assumed
serial.openSerialPort("COM7", 115200);
// xbee object that we will connect up too
XBee xbee = new XBee();
// replaces xbee.open() which uses the RxTx model
xbee.initProviderConnection(serial);
// test we are connected (This is a jUnit test after all)
assertTrue(xbee.isConnected());
// close the xBee
xbee.close();
}
示例7: BroadcastSenderExample
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
private BroadcastSenderExample() throws XBeeException {
XBee xbee = new XBee();
try {
// replace with your com port and baud rate. this is the com port of my coordinator
xbee.open("/dev/ttyUSB0", 9600);
while (true) {
// put some arbitrary data in the payload
int[] payload = ByteUtils.stringToIntArray("the\nquick\nbrown\nfox");
ZNetTxRequest request = new ZNetTxRequest(XBeeAddress64.BROADCAST, payload);
// make it a broadcast packet
request.setOption(ZNetTxRequest.Option.BROADCAST);
log.info("request packet bytes (base 16) " + ByteUtils.toBase16(request.getXBeePacket().getPacket()));
xbee.sendAsynchronous(request);
// we just assume it was sent. that's just the way it is with broadcast.
// no transmit status response is sent, so don't bother calling getResponse()
try {
// wait a bit then send another packet
Thread.sleep(15000);
} catch (InterruptedException e) {
}
}
} finally {
if (xbee != null && xbee.isConnected()) {
xbee.close();
}
}
}
示例8: ZNetExplicitReceiverExample
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
private ZNetExplicitReceiverExample() throws Exception {
XBee xbee = new XBee();
try {
// replace with the com port or your receiving XBee
// this is the com port of my end device on my mac
xbee.open("/dev/tty.usbserial-A6005uRz", 9600);
while (true) {
try {
// we wait here until a packet is received.
XBeeResponse response = xbee.getResponse();
if (response.getApiId() == ApiId.ZNET_EXPLICIT_RX_RESPONSE) {
ZNetExplicitRxResponse rx = (ZNetExplicitRxResponse) response;
log.info("received explicit packet response " + response.toString());
} else {
log.debug("received unexpected packet " + response.toString());
}
} catch (Exception e) {
log.error(e);
}
}
} finally {
if (xbee != null && xbee.isConnected()) {
xbee.close();
}
}
}
示例9: configureEndDevice
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
private void configureEndDevice(XBee xbee) throws XBeeException {
// basic end device configuration (assumes ZNet radio flashed with end device API firmware)
XBeeResponse response = null;
// reset to factory settings
response = xbee.sendAtCommand(new AtCommand("RE"));
log.debug("RE is " + response);
// set PAN id to arbitrary value
response = xbee.sendAtCommand(new AtCommand("ID", new int[] {0x1a, 0xaa}));
log.debug("ID is " + response);
// set NI -- can be any arbitrary sequence of chars
response = xbee.sendAtCommand(new AtCommand("NI", new int[] {'E','N','D','_','D','E','V','I','C','E','_','2' }));
log.debug("NI is " + response);
// set API mode to 2. factory setting is 1
response = xbee.sendAtCommand(new AtCommand("AP", 2));
log.debug("AP is " + response);
// save to settings to survive power cycle
response = xbee.sendAtCommand(new AtCommand("WR"));
log.debug("WR is " + response);
// software reset
response = xbee.sendAtCommand(new AtCommand("FR"));
log.debug("FR is " + response);
}
示例10: configureCoordinator
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
private void configureCoordinator(XBee xbee) throws XBeeException {
// basic coordinator configuration (assumes ZNet radio flashed with COORDINATOR API firmware)
XBeeResponse response = null;
// reset to factory settings
response = xbee.sendAtCommand(new AtCommand("RE"));
log.debug("RE is " + response);
// set PAN id to arbitrary value
response = xbee.sendAtCommand(new AtCommand("ID", new int[] {0x1a, 0xaa}));
log.debug("RE is " + response);
// set NI
response = xbee.sendAtCommand(new AtCommand("NI", new int[] {'C','O','O','R','D','I','N','A','T','O','R' }));
log.debug("NI is " + response);
// set API mode to 2. factory setting is 1
response = xbee.sendAtCommand(new AtCommand("AP", 2));
log.debug("AP is " + response);
// save to settings to survive power cycle
response = xbee.sendAtCommand(new AtCommand("WR"));
log.debug("WR is " + response);
// software reset
response = xbee.sendAtCommand(new AtCommand("FR"));
log.debug("FR is " + response);
}
示例11: configureIOSamples
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
/**
* This assumes an end device that is already has the configureEndDevice configuration
* Does not save configuration! -- use WR if you want this configure to survive power on/off.
*
* @param xbee
* @throws XBeeException
*/
private void configureIOSamples(XBee xbee) throws XBeeException {
// basic coordinator configuration (assumes ZNet radio flashed with COORDINATOR API firmware)
XBeeResponse response = null;
// set IR to 1 sample every 10 seconds. Set to 0 to disable
response = xbee.sendAtCommand(new AtCommand("IR", new int[] {0x27, 0x10}));
log.debug("IR is " + response);
// set pin 20 to monitor digital input
response = xbee.sendAtCommand(new AtCommand("DO", 0x3));
log.debug("DO is " + response);
// set pin 19 to monitor analog input
response = xbee.sendAtCommand(new AtCommand("D1", 0x2));
log.debug("D1 is " + response);
// set pin 18 to monitor analog input
response = xbee.sendAtCommand(new AtCommand("D2", 0x2));
log.debug("D2 is " + response);
// set pin 16 to monitor digital input
response = xbee.sendAtCommand(new AtCommand("D6", 0x3));
log.debug("D6 is " + response);
// optionally configure DH + DL; if set to zero (default), samples will be sent to coordinator
}
示例12: SleepTestCoordinator
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
public SleepTestCoordinator(String args[]) throws XBeeTimeoutException, XBeeException, InterruptedException {
PropertyConfigurator.configure("log4j.properties");
XBee xbee = new XBee(new XBeeConfiguration().withStartupChecks(false));
//coord
xbee.open("/dev/tty.usbserial-A6005uRz", 9600);
// replace with end device's 64-bit address (SH + SL)
// router (firmware 23A7)
XBeeAddress64 addr64 = new XBeeAddress64(0, 0x13, 0xa2, 0, 0x40, 0x0a, 0x3e, 0x02);
if (args.length == 1 && (args[0].equals("on") || args[0].equals("off"))) {
log.info("Turning D0 " + args[0]);
RemoteAtRequest request = new RemoteAtRequest(addr64, "D0", new int[] {args[0].equals("on") ? 5 : 4});
RemoteAtResponse response = (RemoteAtResponse) xbee.sendSynchronous(request, 15000);
if (response.isOk()) {
log.info("Successfully turned " + args[0] + " pin 20 (D0)");
} else {
log.warn("Failed to turn " + args[0] + " pin 20. status is " + response.getStatus());
}
Thread.sleep(2000);
if (xbee != null && xbee.isConnected()) {
xbee.close();
}
} else {
System.err.println("arg should be on or off");
}
}
示例13: ZNetIoSampleExample
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
private ZNetIoSampleExample() throws Exception {
XBee xbee = new XBee();
try {
// replace with the com port of your XBee coordinator
xbee.open("/dev/tty.usbserial-A6005v5M", 9600);
xbee.addPacketListener(this);
// wait forever
synchronized(this) { this.wait(); }
} finally {
xbee.close();
}
}
示例14: ZBForceSampleExample
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
private ZBForceSampleExample() throws Exception {
XBee xbee = new XBee();
try {
// replace with the com port of your XBee coordinator
xbee.open("/dev/tty.usbserial-A6005v5M", 9600);
while (true) {
// All XBees allow you to request an I/O sample on a local XBee (serial connected), however this is not very interesting.
// With ZNet/ZB Pro radios we can use Remote AT to force an I/O sample on an end device.
// The following code issues a force sample on a XBee end device and parses the io sample.
// replace with your end device 64-bit address
XBeeAddress64 addr64 = new XBeeAddress64(0, 0x13, 0xa2, 0, 0x40, 0x0a, 0x3e, 0x02);
XBeeRequest request = new ZBForceSampleRequest(addr64);
try {
XBeeResponse response = xbee.sendSynchronous(request, 6000);
RemoteAtResponse remoteAt = (RemoteAtResponse) response;
if (remoteAt.isOk()) {
// extract the i/o sample
ZNetRxIoSampleResponse ioSample = ZNetRxIoSampleResponse.parseIsSample(remoteAt);
// make sure you configured the remote XBee to D1=2 (analog input) or you will get an error
log.info("10 bit analog1 sample is " + ioSample.getAnalog1());
} else {
log.info("Remote AT request failed: " + response);
}
} catch (XBeeTimeoutException e) {
log.info("request timed out");
}
// wait a bit
Thread.sleep(2000);
}
} finally {
xbee.close();
}
}
示例15: ZBIOSampleReceiveExample
import com.rapplogic.xbee.api.XBee; //导入依赖的package包/类
public ZBIOSampleReceiveExample() throws SerialPortException, XBeeException, InterruptedException {
LOG.info(String.format("Will use port %s", portName));
try {
xbee = new XBee();
xbee.initProviderConnection(new JSSCXBeeConnection(portName));
LOG.info("Connection to XBee initialised successfully");
receive(10);
} finally {
// Ensure xbee is always closed otherwise port will be in use the next time we try to use it
LOG.info("Closing XBee connection");
xbee.close();
}
}