EPSON/POS指令集封装
来源:互联网 发布:开网店用什么软件好 编辑:程序博客网 时间:2024/05/01 03:42
只是对EPSON/POS常用指令集进行了封装,对于那些不使用驱动的票据打印会有用一点。
EpsonPosPrinterCommand对EPSON/POS常用指令集进行了封装
EpsonPosPrinterCommand对EPSON/POS常用指令集进行了封装
import java.awt.image.BufferedImage;/** * Epson打印指令集 * @author <a href="mailto:iffiff1@hotmail.com">Tyler Chen</a> 新增日期:2008-6-19 * @author <a href="mailto:iffiff1@hotmail.com">Tyler Chen</a> 修改日期:2008-6-19 */public class EpsonPosPrinterCommand {public static final byte HT = 0x9;public static final byte LF = 0x0A;public static final byte CR = 0x0D;public static final byte ESC = 0x1B;public static final byte DLE = 0x10;public static final byte GS = 0x1D;public static final byte FS = 0x1C;public static final byte STX = 0x02;public static final byte US = 0x1F;public static final byte CAN = 0x18;public static final byte CLR = 0x0C;/** * n = 1: Transmit printer status * n = 2: Transmit offline status * n = 3: Transmit error status * n = 4: Transmit paper roll sensor status */public static final byte[] DLE_EOT_n = new byte[] { DLE, 0x04, 0x01 };/** * n = 1: Recover from an error and restart printing from the line where the error occurred * n = 2: Recover from an error aft clearing the receive and print buffers */public static final byte[] DLE_ENQ_n = new byte[] { DLE, 0x05, 0x01 };/** * n = 1 * m = 0, 1 * 1 ≤ t ≤ 8 * m Connector pin * m = 0: Drawer kick-out connector pin 2. * m = 1: Drawer kick-out connector pin 5. * pulse ON time is [t × 100 ms] and the OFF time is [t × 100 ms]. */public static final byte[] DLE_DC4_n_m_t = new byte[] { DLE, 0x14, 0x01,0x00, 0x01 };public static final byte[] ESC_SELECT_DEF_CHAR = new byte[] { ESC, '%',0x00 };public static final byte[] ESC_CANCEL_DEF_CHAR = new byte[] { ESC, '%',0x01 };//Define user-defined characters//ESC & y c1 c2 [x1 d1...d(y ×××× x1)]...[xk d1...d(y ×××× xk)]//Select bit-image mode//ESC * m nL nH d1...dkpublic static final byte[] ESC_UNDER_LINE_OFF = new byte[] { ESC, '-', 0x00 };public static final byte[] ESC_UNDER_LINE_ON = new byte[] { ESC, '-', 0x01 };public static final byte[] ESC_DEFAULT_LINE_SP = new byte[] { ESC, '2' };public static final byte[] ESC_ENABLE_PRINTER = new byte[] { ESC, '=', 0x01 };public static final byte[] ESC_INIT = new byte[] { ESC, '@' };public static final byte[] ESC_HT_RESET = new byte[] { ESC, 'D', };public static final byte[] ESC_EM_OFF = new byte[] { ESC, 'E', 0x00 };public static final byte[] ESC_EM_ON = new byte[] { ESC, 'E', 0x01 };public static final byte[] ESC_BLOD_OFF = new byte[] { ESC, 'G', 0x00 };public static final byte[] ESC_BLOD_ON = new byte[] { ESC, 'G', 0x01 };public static final byte[] ESC_CHARSET_CHINESS = new byte[] { ESC, 'R', 15 };public static final byte[] ESC_ALIGN_LEFT = new byte[] { ESC, 'a', 0x00 };public static final byte[] ESC_ALIGN_CENTER = new byte[] { ESC, 'a', 0x01 };public static final byte[] ESC_ALIGN_RIGHT = new byte[] { ESC, 'a', 0x02 };public static final byte[] ESC_PAPER_END_SENSOR_DISABLE_ALL = new byte[] {ESC, 'c', '3', 0x00 };public static final byte[] ESC_PAPER_END_SENSOR_ENABLE_ALL = new byte[] {ESC, 'c', '3', 0x0F };public static final byte[] ESC_PAPER_END_SENSOR_ENABLE_NEAR = new byte[] {ESC, 'c', '3', 0x01 };public static final byte[] ESC_PAPER_END_SENSOR_ENABLE_ROLL = new byte[] {ESC, 'c', '3', 0x04 };public static final byte[] ESC_STOP_PRINT_SENSOR_DISABLE = new byte[] {ESC, 'c', '4', 0x00 };public static final byte[] ESC_STOP_PRINT_SENSOR_ANABLE = new byte[] { ESC,'c', '4', 0x01 };public static final byte[] ESC_PANEL_BUTTON_DISABLE = new byte[] { ESC,'c', '5', 0x00 };public static final byte[] ESC_PANEL_BUTTON_ENABLE = new byte[] { ESC, 'c','5', 0x01 };public static final byte[] ESC_UPSIDE_OFF = new byte[] { ESC, '{', 0x00 };public static final byte[] ESC_UPSIDE_ON = new byte[] { ESC, '{', 0x01 };public static final byte[] ESC_CUT_PAPER = new byte[] { GS, 'V', 0x00 };public static final byte[] ESC_CUT_MODE = new byte[] { GS, 'V', 0x00 };//GS IIII n//GS a n//FS 2 c1 c2 [d1...dk]public static final byte[] ESC_TRANSMIT_PAPER_STATUS = new byte[] { GS,'r', 0x01 };public static final byte[] ESC_TRANSMIT_DRAWER_STATUS = new byte[] { GS,'r', 0x02 };public static final byte[] ESC_UNDERLINE_OFF = new byte[] { FS, '-', 0x00 };public static final byte[] ESC_UNDERLINE_ON = new byte[] { FS, '-', 0x01 };public static final byte[] ESC_CN_MODE_OFF = new byte[] { FS, '.' };public static final byte[] ESC_CN_MODE = new byte[] { FS, '&' };public static final byte[] ESC_CN_SIZE_QUADRUPLE_OFF = new byte[] { FS,'W', 0x00 };public static final byte[] ESC_CN_SIZE_QUADRUPLE_ON = new byte[] { FS, 'W',0x01 };public static final byte[] ESC_OPEN_DRAWER = new byte[] { STX, 'M' };public static final byte[] ESC_OPEN_DRAWER_US = new byte[] { US, 'M' };public static final byte[] ESC_DRAWER_RATE_9600 = new byte[] { STX, 'B',0x00 };public static final byte[] ESC_DRAWER_RATE_2400 = new byte[] { STX, 'B',0x02 };public static byte[] setPrintMode(boolean fontB, boolean both,boolean doubleWidth, boolean doubleHeight, boolean underLine) {int n = 0;if (fontB) {n |= 1;}if (both) {n |= 1 << 3;}if (doubleHeight) {n |= 1 << 4;}if (doubleWidth) {n |= 1 << 5;}if (underLine) {n |= 1 << 7;}return new byte[] { ESC, '!', (byte) n };}public static byte[] setCharSpacing(int n) {n = (n > -1 || n < 256 ? n : 0);/** * Set right-side character spacing * 0 ≤ n ≤ 255 */return new byte[] { ESC, ' ', (byte) n };}public static byte[] setLineSpacing(int n) {n = (n > -1 || n < 256 ? n : 24);return new byte[] { ESC, '3', (byte) n };}public static byte[] cancelUserDefineCharacters(int offset) {if (offset < 0 || (offset + 31) > 126) {return new byte[0];}return new byte[] { ESC, '?', (byte) (31 + offset) };}public static byte[] setHT() {// TODOreturn new byte[] { ESC, 'D' };}public static byte[] printAndFeedPaper(int n) {n = (n > 255 ? 255 : n);n = (n < 0 ? 0 : n);return new byte[] { ESC, 'J', (byte) n };}public static byte[] printAndFeedLines(int n) {n = (n > 255 ? 255 : n);n = (n < 0 ? 0 : n);return new byte[] { ESC, 'd', (byte) n };}public static byte[] generatePulse(int onTime, int offTime) {int t2 = 255 * 2;int t5 = 255 * 5;offTime = (offTime < onTime ? onTime : offTime);offTime = (offTime > t5 ? t5 : offTime);int m = (offTime > t2 ? 1 : 0);int ot1 = (m == 1 ? onTime / 5 : onTime / 2);int ot2 = (m == 1 ? offTime / 5 : offTime / 2);return new byte[] { ESC, 'p', (byte) m, (byte) ot1, (byte) ot2 };}public static byte[] selectCharacterCodeTable(int n) {return new byte[] { ESC, 't', (byte) n };}public static byte[] printNvBitImage(int n, int m) {return new byte[] { ESC, 'p', (byte) n, (byte) m };}public static byte[] setNvBitImage(BufferedImage[] images) {return null;}public static byte[] testPrint(int paper, int pattern) {paper = (paper == 0 || paper == 1 || paper == 2 || paper == 48|| paper == 49 || paper == 50) ? paper : 0;pattern = (pattern == 1 || pattern == 2 || pattern == 3|| pattern == 49 || pattern == 50 || pattern == 51)? pattern: 1;return new byte[] { ESC, '(', 'A', 0x02, 0x00, (byte) paper,(byte) pattern };}public static byte[] setCutMode(int n) {n = n % 256;int m = 66;return new byte[] { GS, 'V', (byte) m, (byte) n };}public static byte[] setMultiByteCharMode(boolean doubleWidth,boolean doubleHeight, boolean underLine) {int n = 0;if (doubleWidth) {n |= 1 << 2;}if (doubleHeight) {n |= 1 << 3;}if (underLine) {n |= 1 << 7;}return new byte[] { FS, '!', (byte) n };}public static final byte[] ESC_FONT_A = new byte[] { ESC, 'M', 0x00 };public static final byte[] ESC_FONT_B = new byte[] { ESC, 'M', 0x01 };public static byte[] getFontA() {return new byte[] { ESC, 'M', 0x00 };}public static byte[] getFontB() {return new byte[] { ESC, 'M', 0x01 };}public static byte[] getColorDefault() {return new byte[] { ESC, 'r', 0x00 };}public static byte[] getColorRed() {return new byte[] { ESC, 'r', 0x01 };}public static byte[] setDisplayRate(char n) {return new byte[] { STX, 'B', (byte) n };}public static byte[] sendDisplayData(String data) {if (data == null || data.length() == 0) {return new byte[0];}byte[] bytes = data.getBytes();int len = bytes.length + 4;byte[] bs = new byte[len];bs[0] = ESC;bs[1] = 'Q';bs[2] = 'A';bs[len - 1] = CR;for (int i = 0; i < bytes.length; i++) {bs[i + 3] = bytes[i];}return bs;}public static byte[] setDisplayState(char n) {return new byte[] { ESC, 's', (byte) n };}public static void main(String[] args) throws Exception {//String imagePixelToPosString = ImagePixelUtils.imagePixelToPosString("C:/2.bmp", 0);//test_1();//ImagePixelUtils.printImageToDots("C:/test.bmp");//ImagePixelUtils.imagePixelToPosString_24("C:/f.bmp", 32);//ImagePixelUtils.imagePixelToPosString_8("C:/test.bmp", 1);//System.out.println(Byte.SIZE);//System.out.println(Integer.toBinaryString(1));//java.text.DecimalFormat df = new java.text.DecimalFormat("00000000");//System.out.println(df.format(0x01));}}本文属于转载!进入原文地址
阅读全文
0 0
- EPSON/POS指令集封装
- EPSON ESC/POS指令
- EPSON ESC/POS指令
- C#版OPOS打印(基于北洋OPOS SDK二次开发包,支持EPSON和北洋、佳博、商祺等支持标准ESC/POS指令的POS打印机)
- C#版OPOS打印(基于北洋OPOS SDK二次开发包,支持EPSON和北洋、佳博、商祺等支持标准ESC/POS指令的POS打印机)
- C#版OPOS打印(基于北洋OPOS SDK二次开发包,支持EPSON和北洋、佳博、商祺等支持标准ESC/POS指令的POS打印机)
- 基于北洋OPOS SDK二次开发包,支持EPSON和北洋、佳博、商祺等支持标准ESC/POS指令的POS打印机
- C#版OPOS打印(基于北洋OPOS SDK二次开发包,支持EPSON和北洋、佳博、商祺等支持标准ESC/POS指令的POS打印机)
- C#版OPOS打印(基于北洋OPOS SDK二次开发包,支持EPSON和北洋、佳博、商祺等支持标准ESC/POS指令的POS打印机)
- 基于北洋OPOS SDK二次开发包,支持EPSON和北洋、佳博、商祺等支持标准ESC/POS指令的POS打印机
- C# 实现Epson热敏打印机打印 Pos机用
- ESC/POS指令体系
- ESC/POS指令集在android设备上使用实例
- 关于pos打印机通过tcp/ip操作打印指令集
- ESC POS 指令打印图片
- 票据打印机-ESC/POS指令使用
- android ESC/POS兼容指令集 蓝牙打印图片和图片叠加水印
- ESC/POS指令集在Android设备上使用实例(通过socket)
- OpenGL管线(用经典管线代说着色器内部)
- 腾讯bugly-微信tinker热修复快速接入
- 在Java7中使用try语句自动关闭资源
- 1643 线段覆盖 3
- 微信公众号-如何快速支持APP上的活动开发
- EPSON/POS指令集封装
- mysql中Timestamp,time,datetime 区别
- struts2的xml配置action
- odoo开发 -- Web Service API
- U-net使用, 图像分割(边缘检测)
- matlab下常用到的目录操作
- 超大文件打开工具---10G的日志文件
- JAVA深入
- android-关于Button设置圆角之后不能点击变色的问题