📄 sampletagreaderclient.java
字号:
/* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. * */package sample;import java.io.*;import java.util.*;import java.net.URI;import java.util.logging.*;import java.util.Properties;import java.rmi.RMISecurityManager;import com.sun.autoid.util.ReaderClient;import net.jini.core.discovery.LookupLocator;import net.jini.discovery.DiscoveryManagement;import com.sun.autoid.identity.*;import com.sun.autoid.reader.Reader;import com.sun.autoid.event.IdentifierListEvent;/* * This class is to provide an example to access reader's getTagList methods. * Using this class, one can find the reader from Event Manger's Jini lookup server * and then be able to access the reader's finctions. Here give an example to call * read/write tag methods. */public class SampleTagReaderClient { public SampleTagReaderClient() {} /* main to call Reader's interface to read tags */ public static void main(String[] args) { /** this is required */ System.setSecurityManager(new RMISecurityManager()); String readerName = System.getProperty("com.sun.autoid.ReaderName", "PMLReader"); String groupStr = System.getProperty("com.sun.autoid.JiniGroup", "ALL"); String locatorStr = System.getProperty("com.sun.autoid.JiniLocator"); String tagBitSizeStr = System.getProperty("com.sun.autoid.TagBitSize"); int tagBitSize = 64; if (tagBitSizeStr != null) tagBitSize = Integer.parseInt(tagBitSizeStr); ReaderClient client = null; try { client = new ReaderClient(readerName, ReaderClient.getGroups(groupStr), ReaderClient.getLocators(locatorStr)); // Wait while looking for the reader System.out.println("Wait while looking for the " + readerName + " reader ..."); Thread.sleep(3*1000); Reader reader = client.getReader(); if (reader == null){ System.out.println("Did not find reader - " + readerName); System.out.println("Exit."); System.exit(1); } // Get the list of tags (assume scanLength is 500ms) java.util.Collection c = reader.getTagList(readerName, 500); Iterator i = c.iterator(); while (i.hasNext()) { IdentifierListEvent eventList = (IdentifierListEvent) i.next(); System.out.println("The following tags were read from the reader: " + eventList.getSource()); Iterator j = eventList.getTagList().iterator(); while (j.hasNext()) { Identifier epc = (Identifier)j.next(); System.out.println("tag= " + epc.getURI()); } } System.out.println("------------"); System.out.println("Checking autored"); System.out.println("Autoread is: " + reader.isAutoRead(readerName)); System.out.println("Turning off autoread"); try { reader.setAutoRead(readerName, false); } catch (Exception ex) { System.out.println("Could not set autoread to false"); } System.out.println("Sleeping"); try { Thread.sleep(10000); } catch (InterruptedException ignore) { } System.out.println("------------"); System.out.println("Checking autored"); System.out.println("Autoread is: " + reader.isAutoRead(readerName)); System.out.println("Turning on autoread"); try { reader.setAutoRead(readerName, true); } catch (Exception ex) { System.out.println("Could not set autoread to false"); } }catch (Exception ex){ ex.printStackTrace(); } finally { if (client != null) client.terminate(); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -