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


Java XBee.open方法代码示例

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


在下文中一共展示了XBee.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: setup

import com.rapplogic.xbee.api.XBee; //导入方法依赖的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

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

示例5: main

import com.rapplogic.xbee.api.XBee; //导入方法依赖的package包/类
/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    
  try{
   InputStreamReader isr = new InputStreamReader(System.in);
   BufferedReader br = new BufferedReader(isr);
   lock = new Semaphore(1,true);
   xbee = new XBee();
   xbee.open(args[0],9600);
   int initial_port = 8889;
   int number_writers = 2;
   for (int i=0; i<number_writers; i++){
       (new Thread (new xbeeWrite(lock, br,xbee,initial_port))).start();
       System.out.println("Started xBeeWriter on port "+initial_port);
       initial_port++;
       Thread.sleep(1000);
   }
   (new Thread (new xbeeRead(lock,xbee))).start();
   (new Thread (new nodeDiscover(lock,xbee,30000,5))).start();
}catch(Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:teclid,项目名称:XBeeMashup,代码行数:26,代码来源:Main.java

示例6: 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

示例7: 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

示例8: 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

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

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

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

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

示例13: 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

示例14: 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

示例15: 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


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