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


Java ZNetRxIoSampleResponse类代码示例

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


ZNetRxIoSampleResponse类属于com.rapplogic.xbee.api.zigbee包,在下文中一共展示了ZNetRxIoSampleResponse类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processResponse

import com.rapplogic.xbee.api.zigbee.ZNetRxIoSampleResponse; //导入依赖的package包/类
/**
 * Called by XBee API thread when a packet is received
 */
public void processResponse(XBeeResponse response) {
	// This is a I/O sample response.  You will only get this is you are connected to a Coordinator that is configured to
	// receive I/O samples from a remote XBee.
	
	if (response.getApiId() == ApiId.ZNET_IO_SAMPLE_RESPONSE) {
		ZNetRxIoSampleResponse ioSample = (ZNetRxIoSampleResponse) response;
		
		log.debug("received i/o sample packet.  contains analog is " + ioSample.containsAnalog() + ", contains digital is " + ioSample.containsDigital());
		
		// check the value of the input pins
		log.debug("pin 20 (DO) digital is " + ioSample.isD0On());
		log.debug("pin 19 (D1) analog is " + ioSample.getAnalog1());
	}
}
 
开发者ID:andrewrapp,项目名称:xbee-api,代码行数:18,代码来源:ZNetIoSampleExample.java

示例2: ZBForceSampleExample

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

示例3: receive

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

示例4: ZBForceSampleExample

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

示例5: broadcastIoSample

import com.rapplogic.xbee.api.zigbee.ZNetRxIoSampleResponse; //导入依赖的package包/类
public void broadcastIoSample(ZNetRxIoSampleResponse packet) {
    
    NDC.push("broadcastIoSample");
    
    try {
    
        XBeeAddress64 xbeeAddress = packet.getRemoteAddress64();
        String deviceAddress = Parser.render4x4(xbeeAddress);
        
        XBeeDeviceContainer prototype = resolve(deviceAddress);
        
        // Let's proceed even if the prototype is null,
        // to record lastSeen and log the sample
        
        logger.debug("prototype: " + prototype);
        
        int buffer[] = packet.getRawPacketBytes();
        int[] sampleBytes = new int[buffer.length - 14];
        
        for (int offset = 0; offset < buffer.length - 15; offset++) {
            
            int value = buffer[offset + 15];
            sampleBytes[offset] = value;
        }
        
        IoSample sample = new IoSample(sampleBytes, xbeeAddress, logger);
        
        logger.debug("sample: " + sample);
        
        if (prototype != null) {
            prototype.broadcastIoSample(sample);
        }
        
        lastSeen.put(deviceAddress, System.currentTimeMillis());
    
    } finally {
        NDC.pop();
    }
}
 
开发者ID:home-climate-control,项目名称:dz,代码行数:40,代码来源:XBeeDeviceFactory.java

示例6: processResponse

import com.rapplogic.xbee.api.zigbee.ZNetRxIoSampleResponse; //导入依赖的package包/类
@Override
public void processResponse(XBeeResponse packet) {
    
    NDC.push("processResponse");
    
    try {
        
        logger.debug("packet: " + packet);
        
        ApiId apiId = packet.getApiId();
        
        switch (apiId) {
        
        case AT_RESPONSE:
            
            AtCommandResponse atCommandResponse = (AtCommandResponse) packet;
            String command = atCommandResponse.getCommand();
            
            if ("ND".equals(command)) {
            
                createPrototype(ZBNodeDiscover.parse(atCommandResponse));
                
            } else if ("NT".equals(command)) {
                
                // No big deal, browse() initiated it and handled it
                
            } else {
                
                logger.warn("Unexpected response received (command: " + command + ")");
            }
            
            break;
            
        case ZNET_IO_SAMPLE_RESPONSE:
            
            broadcastIoSample((ZNetRxIoSampleResponse) packet);
            break;
        
        default:
            
            // Have no idea what this is, don't care
            break;
        }

    } catch (Throwable t) {
        
        logger.error("Oops", t);
    } finally {
        NDC.pop();
    }
    
}
 
开发者ID:home-climate-control,项目名称:dz,代码行数:53,代码来源:XBeeDeviceFactory.java


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