• 小票打印机指令集封装(支持EPSON指令)


    import java.io.IOException; import java.io.OutputStream; import java.net.InetSocketAddress; import java.net.Socket; import java.net.UnknownHostException; public class TestMain { private static void print(String ip,String printContent) { Socket socket = null; try { socket = new Socket(); socket.connect(new InetSocketAddress(ip, 9100), 4000); System.out.println("CashierDesk=====小票机连接成功,IP:" + ip); OutputStream os = socket.getOutputStream(); // 切纸命令 String text = printContent + " "; byte[] CMD_INIT = { 27, 64 }; os.write(CMD_INIT); os.write(text.getBytes("GB2312")); final byte[] CMD_CUT = { 0x1D, 0x56, 0x01 }; os.write(CMD_CUT); System.out.println("CashierDesk=====小票机打印完成,IP:" + ip); } catch (UnknownHostException e) { System.out.println("CashierDesk=====小票机连接失败,IP:" + ip); e.printStackTrace(); } catch (IOException e) { System.out.println("CashierDesk=====小票机连接失败,IP:" + ip); e.printStackTrace(); } finally { if (socket != null) { try { socket.close(); } catch (IOException e) { e.printStackTrace(); } } } } public static void main(String[] args) { String ip = "192.168.80.209"; String printContent = "";                  printContent += "********************倍数放大******************** "; printContent += "纵向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.longitudinalDouble(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "横向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.transverseDouble();printContent += "我是中文 I'm english 54123456 ";printContent += PrinterCmdUtils.ZoomCancel(); printContent += " "; printContent += "横向,纵向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.bothDouble(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "********************加粗加粗******************** "; printContent += "纵向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.longitudinalDouble(); printContent += PrinterCmdUtils.boldOn(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.boldOff(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "横向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.transverseDouble();printContent += PrinterCmdUtils.boldOn(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.boldOff(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "横向,纵向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.bothDouble();printContent += PrinterCmdUtils.boldOn(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.boldOff(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "********************改变字体******************** "; printContent += "改变字体(仅支持英文,数字) "; printContent += PrinterCmdUtils.fontB();printContent += "我是中文 I'm english 54123456 ";printContent += PrinterCmdUtils.fontA(); printContent += " "; printContent += "纵向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.longitudinalDouble(); printContent += PrinterCmdUtils.fontB(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.fontA(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "横向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.transverseDouble();printContent += PrinterCmdUtils.fontB(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.fontA(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "横向,纵向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.bothDouble();printContent += PrinterCmdUtils.fontB(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.fontA(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "********************反显打印******************** "; printContent += "纵向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.longitudinalDouble(); printContent += PrinterCmdUtils.reversePrint(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.reverseCancel(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "横向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.transverseDouble();printContent += PrinterCmdUtils.reversePrint(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.reverseCancel(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "横向,纵向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.bothDouble();printContent += PrinterCmdUtils.reversePrint(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.reverseCancel(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "********************汉字间距1******************* "; printContent += "纵向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.longitudinalDouble(); printContent += PrinterCmdUtils.margin1(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.marginCancle(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "横向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.transverseDouble();printContent += PrinterCmdUtils.margin1(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.marginCancle(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "横向,纵向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.bothDouble();printContent += PrinterCmdUtils.margin1(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.marginCancle(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "********************汉字间距2******************* "; printContent += "纵向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.longitudinalDouble(); printContent += PrinterCmdUtils.margin2(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.marginCancle(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "横向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.transverseDouble();printContent += PrinterCmdUtils.margin2(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.marginCancle(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";printContent += "横向,纵向放大两倍(汉字,英文,数字都支持) "; printContent += PrinterCmdUtils.bothDouble();printContent += PrinterCmdUtils.margin2(); printContent += "我是中文 I'm english 54123456 "; printContent += PrinterCmdUtils.marginCancle(); printContent += PrinterCmdUtils.ZoomCancel(); printContent += " ";*/print(ip, printContent); } }

  • 相关阅读:
    Unity3d Shader开发(四)UsePass ,GrabPass ,SubShader Tags
    Unity3d Shader开发(三)Pass(Pass Tags,Name,BindChannels )
    Unity3d Shader开发(三)Pass(Blending )
    Unity3d Shader开发(三)Pass(Alpha testing )
    Unity3d Shader开发(三)Pass(Fog )
    Unity3d Shader开发(三)Pass(Texturing )
    Scrapy 学习笔记爬豆瓣 250
    Python 高效编程技巧实战(2-1)如何在列表,字典, 集合中根据条件筛选数据
    Spring Boot 集成 Spring Security 使用自定义的安全数据源
    SpringBoot 集成 Spring Session
  • 原文地址:https://www.cnblogs.com/xieyulin/p/7070149.html
Copyright © 2020-2023  润新知