⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sampleprinterclient.java

📁 SUnRDIS网络应用平台,可以在该平台上开发RFID应用,系统.
💻 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 com.sun.autoid.util.PrinterClient;import com.sun.autoid.identity.*;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 provides an example of how to print tags to a printer. * Using this class, one can find the printer from Event Manager's Jini lookup server  * and then be able to access the printer's functions.  */public class SamplePrinterClient {        public SamplePrinterClient() {}        /*      * main to call Reader's interface to read tags     */     public static void main(String[] args) {         PrinterClient client = null;                  /** this is required */         System.setSecurityManager(new RMISecurityManager());                  String printerName = System.getProperty("com.sun.autoid.ReaderName", "ZebraPrinter");                  String tagBitSizeStr = System.getProperty("com.sun.autoid.TagBitSize");         int tagBitSize = 64;         if (tagBitSizeStr != null)             tagBitSize = Integer.parseInt(tagBitSizeStr);                  String identifier = null;         if (args.length > 0)                identifier = args[0];                  // Identifier argumen must be specified.         if (identifier == null){             System.out.println("Need identifier URI");             System.exit(1);         }                      try {                          // Create new PrinterClient given the printer name.	     client = new PrinterClient(printerName);                          // Wait while looking for the printer             System.out.println("Wait while looking for the " + printerName + " printer ...");             Thread.sleep(3*1000);                          // Create Identifier to write to tag             Identifier id = IdentifierFactory.createIdentifier(new URI(identifier), tagBitSize);                          // Create properties for printing             int count = 1; // default             Properties properties = new Properties();             properties.put("template", "default"); // default             properties.put("COUNT", String.valueOf(count));             properties.put("description", "Sample");             properties.put("SHIP_TO_CUSTOMER_NAME", "Sun Microsystems");             properties.put("SHIP_TO_ADDRESS1", "Newtork Circle");             properties.put("SHIP_TO_CITY", "Santa Clara");             properties.put("SHIP_TO_STATE_PROV", "California");             properties.put("SHIP_TO_POSTAL", "94087");                          String UCC = null;             if (id instanceof EPC_SGTIN_BASE) {                 UCC = ((EPC_SGTIN_BASE)id).getGTIN14();             }else if (id instanceof EPC_SSCC_BASE) {                 UCC = ((EPC_SSCC_BASE)id).getSSCC();             }else if(id instanceof EPC_GIAI_BASE){                 UCC = ((EPC_GIAI_BASE)id).getGIAI();             }else if (id instanceof EPC_GRAI_BASE) {                 UCC = ((EPC_GRAI_BASE)id).getGRAI();             }else if (id instanceof EPC_SGLN_BASE) {                 UCC = ((EPC_SGLN_BASE)id).getSGLN();             }             if(UCC != null)                 properties.put("UCC", UCC);                          // Finally, print the Identifier             client.printTag(id, properties);                      }catch (Exception ex){             ex.printStackTrace();         } finally {             if (client != null)                client.terminate();         }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -