当前位置: 首页>>代码示例>>Java>>正文


Java XBee.isConnected方法代码示例

本文整理汇总了Java中com.rapplogic.xbee.api.XBee.isConnected方法的典型用法代码示例。如果您正苦于以下问题:Java XBee.isConnected方法的具体用法?Java XBee.isConnected怎么用?Java XBee.isConnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.rapplogic.xbee.api.XBee的用法示例。


在下文中一共展示了XBee.isConnected方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();		
		}
	}
}
 
开发者ID:andrewrapp,项目名称:xbee-api,代码行数:17,代码来源:ZNetIoSampleExample.java

示例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();		
		}
	}
}
 
开发者ID:andrewrapp,项目名称:xbee-api,代码行数:19,代码来源:BroadcastReceiverExample.java

示例3: 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();		
		}
	}
}
 
开发者ID:andrewrapp,项目名称:xbee-api,代码行数:35,代码来源:BroadcastSenderExample.java

示例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 {
		if (xbee != null && xbee.isConnected()) {
			xbee.close();		
		}
	}
}
 
开发者ID:andrewrapp,项目名称:xbee-api,代码行数:32,代码来源:ZNetExplicitReceiverExample.java

示例5: 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");
	}
}
 
开发者ID:andrewrapp,项目名称:xbee-api,代码行数:37,代码来源:SleepTestCoordinator.java

示例6: 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();		
		}
	}
}
 
开发者ID:andrewrapp,项目名称:xbee-api,代码行数:48,代码来源:ZNetExplicitSenderExample.java

示例7: 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();		
		}
	}
}
 
开发者ID:andrewrapp,项目名称:xbee-api,代码行数:43,代码来源:ZBForceSampleExample.java

示例8: 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();		
		}
	}
}
 
开发者ID:andrewrapp,项目名称:xbee-api,代码行数:49,代码来源:ZNetReceiverExample.java

示例9: 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();		
		}
	}
}
 
开发者ID:andrewrapp,项目名称:xbee-api,代码行数:47,代码来源:ApiReceiverExample.java

示例10: 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();		
		}
	}
}
 
开发者ID:andrewrapp,项目名称:xbee-api,代码行数:52,代码来源:IoSamplesExample.java

示例11: 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();
		}
	}
}
 
开发者ID:allanlang,项目名称:xbee-api-jssc,代码行数:49,代码来源:ZNetReceiverExample.java


注:本文中的com.rapplogic.xbee.api.XBee.isConnected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。