本文整理汇总了Java中com.rapplogic.xbee.api.XBee.sendAsynchronous方法的典型用法代码示例。如果您正苦于以下问题:Java XBee.sendAsynchronous方法的具体用法?Java XBee.sendAsynchronous怎么用?Java XBee.sendAsynchronous使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.rapplogic.xbee.api.XBee
的用法示例。
在下文中一共展示了XBee.sendAsynchronous方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
}
示例2: 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 {
xbee.close();
}
}
示例3: 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();
}
}
}
示例4: 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();
}
}
}
示例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 {
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.isConnected()) {
xbee.close();
}
}
}