本文整理汇总了Java中com.rapplogic.xbee.api.XBee.sendSynchronous方法的典型用法代码示例。如果您正苦于以下问题:Java XBee.sendSynchronous方法的具体用法?Java XBee.sendSynchronous怎么用?Java XBee.sendSynchronous使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rapplogic.xbee.api.XBee
的用法示例。
在下文中一共展示了XBee.sendSynchronous方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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");
}
}
示例2: 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();
}
}
示例3: AP2
import com.rapplogic.xbee.api.XBee; //导入方法依赖的package包/类
private void AP2(XBee target) throws XBeeTimeoutException, XBeeException, IOException {
XBeeResponse rsp = target.sendSynchronous(new AtCommand("AP", 2), XBeeConstants.TIMEOUT_AP_MILLIS);
if (rsp.isError()) {
throw new IOException("Can't set AP=2, response: " + rsp);
}
}
示例4: AT
import com.rapplogic.xbee.api.XBee; //导入方法依赖的package包/类
private void AT(XBee xbee, String command) {
NDC.push("AT");
try {
XBeeResponse rsp = xbee.sendSynchronous(new AtCommand(command), 10*1000);
logger.info(command + " response: " + rsp);
} catch (Throwable t) {
logger.fatal(command + " failed", t);
} finally {
NDC.pop();
}
}
示例5: 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 {
if (xbee != null && xbee.isConnected()) {
xbee.close();
}
}
}
示例6: 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);
xbee.close();
} else {
System.err.println("arg should be on or off");
}
}