本文整理汇总了Java中com.rapplogic.xbee.api.PacketListener类的典型用法代码示例。如果您正苦于以下问题:Java PacketListener类的具体用法?Java PacketListener怎么用?Java PacketListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PacketListener类属于com.rapplogic.xbee.api包,在下文中一共展示了PacketListener类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setup
import com.rapplogic.xbee.api.PacketListener; //导入依赖的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);
}
}
开发者ID:andrewrapp,项目名称:xbee-api,代码行数:23,代码来源:Processing.java
示例2: receive
import com.rapplogic.xbee.api.PacketListener; //导入依赖的package包/类
private void receive(int maxPackets) throws InterruptedException {
int processedPackets = 0;
PacketListener listener = new PacketListener() {
public void processResponse(XBeeResponse response) {
if(response instanceof ZNetRxIoSampleResponse) {
ZNetRxIoSampleResponse sample = (ZNetRxIoSampleResponse)response;
LOG.info(String.format("Received sample [A0:%d]", sample.getAnalog0()));
} else {
LOG.warn(String.format("Unexpected response type %s, ignoring", response.getClass().getName()));
}
synchronized (this) {
notify();
}
}
};
xbee.addPacketListener(listener);
while (processedPackets < maxPackets) {
synchronized (listener) {
listener.wait();
processedPackets++;
}
}
}
开发者ID:allanlang,项目名称:xbee-api-jssc,代码行数:29,代码来源:ZBIOSampleReceiveExample.java
示例3: open
import com.rapplogic.xbee.api.PacketListener; //导入依赖的package包/类
@Override
protected void open(final Map<String, Object> context) throws Exception {
if (context.get("connectionType") instanceof LocalConnection) {
LocalConnection localConnection = (LocalConnection) context.get("connectionType");
xbee.open((String) localConnection.getSerialPort(), localConnection.getBaudRate());
} else {
SerialServerConnection ser = (SerialServerConnection) context.get("connectionType");
xbee.initProviderConnection((XBeeConnection)new SocketXBeeConnection(ser.getHost(), ser.getPort()));
}
final boolean verbose = (Boolean) context.get("verbose");
xbee.addPacketListener(new PacketListener() {
@Override
public void processResponse(XBeeResponse response) {
if (response.getApiId() == ApiId.ZNET_RX_RESPONSE || response.getApiId() == ApiId.RX_64_RESPONSE) {
if (verbose) {
System.out.println("Received rx packet from arduino " + response);
}
if (response.getApiId() == ApiId.ZNET_RX_RESPONSE) {
ZNetRxResponse zb = (ZNetRxResponse) response;
if (zb.getData()[0] == MAGIC_BYTE1 && zb.getData()[1] == MAGIC_BYTE2) {
addReply(zb.getData());
} else {
System.out.println("Ignoring non-programming packet " + zb);
}
} else {
RxResponse rx64 = (RxResponse64) response;
if (rx64.getData()[0] == MAGIC_BYTE1 && rx64.getData()[1] == MAGIC_BYTE2) {
addReply(rx64.getData());
} else {
System.out.println("Ignoring non-programming packet " + rx64);
}
}
} else if (response.getApiId() == ApiId.ZNET_TX_STATUS_RESPONSE) {
ZNetTxStatusResponse zNetTxStatusResponse = (ZNetTxStatusResponse) response;
if (zNetTxStatusResponse.isSuccess()) {
// yay
} else {
// interrupt thread in case it's waiting for ack, which will never come
System.out.println("Failed to deliver packet. Interrupting main thread. Response: " + response);
interrupt();
}
} else if (response.getApiId() == ApiId.TX_STATUS_RESPONSE) {
TxStatusResponse txStatusResponse = (TxStatusResponse) response;
if (txStatusResponse.isSuccess()) {
// yay
} else {
// interrupt thread in case it's waiting for ack, which will never come
System.out.println("Failed to deliver packet. Interrupting main thread. Response: " + response);
interrupt();
}
}
}
});
}
开发者ID:andrewrapp,项目名称:arduino-remote-uploader,代码行数:63,代码来源:XBeeSketchUploader.java
注:本文中的com.rapplogic.xbee.api.PacketListener类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论