EPSON/POS指令集封装

来源:互联网 发布:开网店用什么软件好 编辑:程序博客网 时间:2024/05/01 03:42
只是对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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 期货平台跑路了怎么办 浮云牧场没房了怎么办 融资股票停牌了怎么办 买入的股票停牌怎么办 淘宝抢到便宜货老板不发货怎么办 微信代购买到假货了怎么办 微信代购收到假货怎么办 苹果商店下载很慢怎么办 谷歌商店下载东西慢怎么办 买家说少发货了怎么办 人肉代购被海关扣了怎么办 韩国代购被海关扣了怎么办 爱奇艺开通自动续费忘了账号怎么办 小米手机云储存空间不足怎么办 路由器被黑了打不开网页怎么办 致人轻伤跑了怎么办 轻伤对方要30万怎么办 老公用老婆的钱怎么办 想注册个公司要怎么办 域名续费不知道找谁怎么办 代收快递弄丢了怎么办 货到付款的快递人不在怎么办 快递送货上门人不在怎么办 ems快递签收人不在怎么办 快递被别人取了怎么办 怎么办快递宗和收发点 快递电话写错了怎么办 网上买沙发想退货怎么办 买的电脑想退货怎么办 买了衣服想退货怎么办 天猫买药审核通过后不要了怎么办 京东维修无发票怎么办 京东维修没有发票怎么办 苹果6s外音没了怎么办 苹果6splus开不了机怎么办 顺丰快递寄件填错收件人地址怎么办 收快递电话换了怎么办 顺丰快递没人收怎么办 网购东西没收到怎么办 中通快递没收到怎么办 快递员不给验货怎么办