本文整理汇总了Java中com.rapplogic.xbee.api.XBee.getResponse方法的典型用法代码示例。如果您正苦于以下问题:Java XBee.getResponse方法的具体用法?Java XBee.getResponse怎么用?Java XBee.getResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rapplogic.xbee.api.XBee
的用法示例。
在下文中一共展示了XBee.getResponse方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
}
示例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 {
xbee.close();
}
}
示例3: 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();
}
}
}
示例4: 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 {
xbee.close();
}
}
示例5: ZNetExplicitSenderExample
import com.rapplogic.xbee.api.XBee; //导入方法依赖的package包/类
private ZNetExplicitSenderExample() 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("COM5", 9600);
xbee.open("/dev/tty.usbserial-A6005v5M", 9600);
// replace with end device's 64-bit address (SH + SL)
XBeeAddress64 addr64 = new XBeeAddress64(0, 0x13, 0xa2, 0, 0x40, 0x0a, 0x3e, 0x02);
// create an array of arbitrary data to send
int[] payload = new int[] { 0, 0x66, 0xee };
// loopback test
int sourceEndpoint = 0;
int destinationEndpoint = ZNetExplicitTxRequest.Endpoint.DATA.getValue();
DoubleByte clusterId = new DoubleByte(0x0, ZNetExplicitTxRequest.ClusterId.SERIAL_LOOPBACK.getValue());
//DoubleByte clusterId = new DoubleByte(0x0, ZNetExplicitTxRequest.ClusterId.TRANSPARENT_SERIAL.getValue());
// first request we just send 64-bit address. we get 16-bit network address with status response
ZNetExplicitTxRequest request = new ZNetExplicitTxRequest(0xff, addr64, XBeeAddress16.ZNET_BROADCAST,
ZNetTxRequest.DEFAULT_BROADCAST_RADIUS, ZNetTxRequest.Option.UNICAST, payload, sourceEndpoint, destinationEndpoint, clusterId, ZNetExplicitTxRequest.znetProfileId);
log.info("sending explicit " + request.toString());
while (true) {
xbee.sendAsynchronous(request);
XBeeResponse response = xbee.getResponse();
log.info("received response " + response.toString());
try {
// wait a bit then send another packet
Thread.sleep(5000);
} catch (InterruptedException e) {
}
}
} finally {
if (xbee != null && xbee.isConnected()) {
xbee.close();
}
}
}
示例6: ZNetReceiverExample
import com.rapplogic.xbee.api.XBee; //导入方法依赖的package包/类
private ZNetReceiverExample() throws Exception {
XBee xbee = new XBee();
try {
// replace with the com port of your receiving XBee (typically your end device)
// router
xbee.open("/dev/tty.usbserial-A6005uPi", 9600);
while (true) {
try {
// we wait here until a packet is received.
XBeeResponse response = xbee.getResponse();
log.info("received response " + response.toString());
if (response.getApiId() == ApiId.ZNET_RX_RESPONSE) {
// we received a packet from ZNetSenderTest.java
ZNetRxResponse rx = (ZNetRxResponse) response;
log.info("Received RX packet, option is " + rx.getOption() + ", sender 64 address is " + ByteUtils.toBase16(rx.getRemoteAddress64().getAddress()) + ", remote 16-bit address is " + ByteUtils.toBase16(rx.getRemoteAddress16().getAddress()) + ", data is " + ByteUtils.toBase16(rx.getData()));
// optionally we may want to get the signal strength (RSSI) of the last hop.
// keep in mind if you have routers in your network, this will be the signal of the last hop.
AtCommand at = new AtCommand("DB");
xbee.sendAsynchronous(at);
XBeeResponse atResponse = xbee.getResponse();
if (atResponse.getApiId() == ApiId.AT_RESPONSE) {
// remember rssi is a negative db value
log.info("RSSI of last response is " + -((AtCommandResponse)atResponse).getValue()[0]);
} else {
// we didn't get an AT response
log.info("expected RSSI, but received " + atResponse.toString());
}
} else {
log.debug("received unexpected packet " + response.toString());
}
} catch (Exception e) {
log.error(e);
}
}
} finally {
if (xbee != null && xbee.isConnected()) {
xbee.close();
}
}
}
示例7: ApiReceiverExample
import com.rapplogic.xbee.api.XBee; //导入方法依赖的package包/类
private ApiReceiverExample() throws Exception {
XBee xbee = new XBee();
int count = 0;
int errors = 0;
try {
// my end device
xbee.open("/dev/tty.usbserial-A6005v5M", 9600);
// my coordinator
//xbee.open("/dev/tty.usbserial-A4004Rim", 9600);
while (true) {
try {
XBeeResponse response = xbee.getResponse();
count++;
if (response.isError()) {
log.info("response contains errors", ((ErrorResponse)response).getException());
errors++;
}
for (int i = 0; i < response.getPacketBytes().length; i++) {
log.info("packet [" + i + "] " + ByteUtils.toBase16(response.getPacketBytes()[i]));
}
if (response.getApiId() == ApiId.RX_16_RESPONSE) {
log.info("Received RX 16 packet " + ((RxResponse16)response));
} else if (response.getApiId() == ApiId.RX_64_RESPONSE) {
log.info("Received RX 64 packet " + ((RxResponse64)response));
} else {
log.info("Ignoring mystery packet " + response.toString());
}
log.debug("Received response: " + response.toString() + ", count is " + count + ", errors is " + errors);
} catch (Exception e) {
log.error(e);
}
}
} finally {
if (xbee != null && xbee.isConnected()) {
xbee.close();
}
}
}
示例8: IoSamplesExample
import com.rapplogic.xbee.api.XBee; //导入方法依赖的package包/类
private IoSamplesExample() throws Exception {
XBee xbee = new XBee();
try {
xbee.open("/dev/tty.usbserial-A6005v5M", 9600);
while (true) {
try {
XBeeResponse response = xbee.getResponse();
log.info("Received i/o response: " + response);
log.info("packet bytes is " + ByteUtils.toBase16(response.getPacketBytes()));
if (response.isError()) {
log.info("response contains errors", ((ErrorResponse)response).getException());
continue;
}
if (response.getApiId() == ApiId.RX_16_IO_RESPONSE) {
RxResponseIoSample ioSample = (RxResponseIoSample)response;
log.info("Received I/O sample from " + ioSample.getSourceAddress());
// optionally output the rssi strength
//log.info("rssi is " + ioSample.getRssi());
// loops just once since IT = 1
for (IoSample sample: ioSample.getSamples()) {
if (ioSample.containsAnalog()) {
log.info("Analog pin 20 10-bit reading is " + sample.getAnalog0());
log.info("Digital pin 11 is " + (sample.isD4On() ? "on" : "off"));
log.info("Digital pin 12 is " + (sample.isD7On() ? "on" : "off"));
} else {
// we know it's change detect since analog was not sent
log.info("Received change detect for Digital pin 12: " + (sample.isD7On() ? "on" : "off"));
}
}
} else {
// not what we expected
log.info("Ignoring mystery packet " + response.toString());
}
} catch (Exception e) {
log.error(e);
}
}
} finally {
if (xbee != null && xbee.isConnected()) {
xbee.close();
}
}
}
示例9: ZNetExplicitSenderExample
import com.rapplogic.xbee.api.XBee; //导入方法依赖的package包/类
private ZNetExplicitSenderExample() 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("COM5", 9600);
xbee.open("/dev/tty.usbserial-A6005v5M", 9600);
// replace with end device's 64-bit address (SH + SL)
XBeeAddress64 addr64 = new XBeeAddress64(0, 0x13, 0xa2, 0, 0x40, 0x0a, 0x3e, 0x02);
// create an array of arbitrary data to send
int[] payload = new int[] { 0, 0x66, 0xee };
// loopback test
int sourceEndpoint = 0;
int destinationEndpoint = ZNetExplicitTxRequest.Endpoint.DATA.getValue();
DoubleByte clusterId = new DoubleByte(0x0, ZNetExplicitTxRequest.ClusterId.SERIAL_LOOPBACK.getValue());
//DoubleByte clusterId = new DoubleByte(0x0, ZNetExplicitTxRequest.ClusterId.TRANSPARENT_SERIAL.getValue());
// first request we just send 64-bit address. we get 16-bit network address with status response
ZNetExplicitTxRequest request = new ZNetExplicitTxRequest(0xff, addr64, XBeeAddress16.ZNET_BROADCAST,
ZNetTxRequest.DEFAULT_BROADCAST_RADIUS, ZNetTxRequest.Option.UNICAST, payload, sourceEndpoint, destinationEndpoint, clusterId, ZNetExplicitTxRequest.znetProfileId);
log.info("sending explicit " + request.toString());
while (true) {
xbee.sendAsynchronous(request);
XBeeResponse response = xbee.getResponse();
log.info("received response " + response.toString());
try {
// wait a bit then send another packet
Thread.sleep(5000);
} catch (InterruptedException e) {
}
}
} finally {
xbee.close();
}
}
示例10: ZNetReceiverExample
import com.rapplogic.xbee.api.XBee; //导入方法依赖的package包/类
private ZNetReceiverExample() throws Exception {
XBee xbee = new XBee();
try {
// replace with the com port of your receiving XBee (typically your end device)
// router
xbee.open("/dev/tty.usbserial-A6005uPi", 9600);
while (true) {
try {
// we wait here until a packet is received.
XBeeResponse response = xbee.getResponse();
log.info("received response " + response.toString());
if (response.getApiId() == ApiId.ZNET_RX_RESPONSE) {
// we received a packet from ZNetSenderTest.java
ZNetRxResponse rx = (ZNetRxResponse) response;
log.info("Received RX packet, option is " + rx.getOption() + ", sender 64 address is " + ByteUtils.toBase16(rx.getRemoteAddress64().getAddress()) + ", remote 16-bit address is " + ByteUtils.toBase16(rx.getRemoteAddress16().getAddress()) + ", data is " + ByteUtils.toBase16(rx.getData()));
// optionally we may want to get the signal strength (RSSI) of the last hop.
// keep in mind if you have routers in your network, this will be the signal of the last hop.
AtCommand at = new AtCommand("DB");
xbee.sendAsynchronous(at);
XBeeResponse atResponse = xbee.getResponse();
if (atResponse.getApiId() == ApiId.AT_RESPONSE) {
// remember rssi is a negative db value
log.info("RSSI of last response is " + -((AtCommandResponse)atResponse).getValue()[0]);
} else {
// we didn't get an AT response
log.info("expected RSSI, but received " + atResponse.toString());
}
} else {
log.debug("received unexpected packet " + response.toString());
}
} catch (Exception e) {
log.error(e);
}
}
} finally {
if (xbee.isConnected()) {
xbee.close();
}
}
}
示例11: ApiReceiverExample
import com.rapplogic.xbee.api.XBee; //导入方法依赖的package包/类
private ApiReceiverExample() throws Exception {
XBee xbee = new XBee();
int count = 0;
int errors = 0;
try {
// my end device
xbee.open("/dev/tty.usbserial-A6005v5M", 9600);
// my coordinator
//xbee.open("/dev/tty.usbserial-A4004Rim", 9600);
while (true) {
try {
XBeeResponse response = xbee.getResponse();
count++;
if (response.isError()) {
log.info("response contains errors", ((ErrorResponse)response).getException());
errors++;
}
for (int i = 0; i < response.getPacketBytes().length; i++) {
log.info("packet [" + i + "] " + ByteUtils.toBase16(response.getPacketBytes()[i]));
}
if (response.getApiId() == ApiId.RX_16_RESPONSE) {
log.info("Received RX 16 packet " + ((RxResponse16)response));
} else if (response.getApiId() == ApiId.RX_64_RESPONSE) {
log.info("Received RX 64 packet " + ((RxResponse64)response));
} else {
log.info("Ignoring mystery packet " + response.toString());
}
log.debug("Received response: " + response.toString() + ", count is " + count + ", errors is " + errors);
} catch (Exception e) {
log.error(e);
}
}
} finally {
xbee.close();
}
}
示例12: IoSamplesExample
import com.rapplogic.xbee.api.XBee; //导入方法依赖的package包/类
private IoSamplesExample() throws Exception {
XBee xbee = new XBee();
try {
xbee.open("/dev/tty.usbserial-A6005v5M", 9600);
while (true) {
try {
XBeeResponse response = xbee.getResponse();
log.info("Received i/o response: " + response);
log.info("packet bytes is " + ByteUtils.toBase16(response.getPacketBytes()));
if (response.isError()) {
log.info("response contains errors", ((ErrorResponse)response).getException());
continue;
}
if (response.getApiId() == ApiId.RX_16_IO_RESPONSE) {
RxResponseIoSample ioSample = (RxResponseIoSample)response;
log.info("Received I/O sample from " + ioSample.getSourceAddress());
// optionally output the rssi strength
//log.info("rssi is " + ioSample.getRssi());
// loops just once since IT = 1
for (IoSample sample: ioSample.getSamples()) {
if (ioSample.containsAnalog()) {
log.info("Analog pin 20 10-bit reading is " + sample.getAnalog0());
log.info("Digital pin 11 is " + (sample.isD4On() ? "on" : "off"));
log.info("Digital pin 12 is " + (sample.isD7On() ? "on" : "off"));
} else {
// we know it's change detect since analog was not sent
log.info("Received change detect for Digital pin 12: " + (sample.isD7On() ? "on" : "off"));
}
}
} else {
// not what we expected
log.info("Ignoring mystery packet " + response.toString());
}
} catch (Exception e) {
log.error(e);
}
}
} finally {
xbee.close();
}
}