EPSON/POS指令集封装

只是对EPSON/POS常用指令集进行了封装,对于那些不使用驱动的票据打印会有用一点。
[b]EpsonPosPrinterCommand[/b]对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...dk

public 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() {
// TODO
return 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Introduction.........................................................................................................................1 About This Manual..................................................................................................................................2 Conventions Used in This Manual........................................................................................................2 Icons....................................................................................................................................................... 2 Command names and parameters.................................................................................................... 3 Information organization.................................................................................................................... 3 Nonrecommended and deleted commands.....................................................................................3 INT and MOD...................................................................................................................................... 4 Command Summary.......................................................................................................C-1 Command List by Function................................................................................................................C-2 Command List by ASCII Order..........................................................................................................C-6 Individual Command Explanations..................................................................................................C-9 Binary Mode Commands................................................................................................................C-216 Recommended Operations..............................................................................................R-1 Recommended Command Order...................................................................................................... R-4 Set the Printing Area............................................................................................................................ R-5 The printable area............................................................................................................................ R-6 Setting left and right margins......................................................................................................... R-9 Setting page length......................................................................................................................... R-10 Setting top and bottom margins................................................................................................... R-13 Setting bottom margin...................................................................................................................R-13 Select Characters................................................................................................................................R-15 Assign character tables.................................................................................................................. R-15 Defining user-defined characters................................................................................................R-17 Selecting an international character set......................................................................................R-41 Select a Font........................................................................................................................................R-42 Print quality (draft, LQ, or NLQ)................................................................................................R-43 Standard and scalable fonts (multipoint mode)........................................................................R-43 Enhancements................................................................................................................................R-51 Super/subscript............................................................................................................................. R-54 Select Supporting Features............................................................................................................... R-55 Selecting unidirectional print head movement......................................................................... R-55 Selecting print color....................................................................................................................... R-55 Select the Print Position.................................................................................................................... R-56 Moving the horizontal position................................................................................................... R-57 Moving the vertical position........................................................................................................R-60 Send Print Data................................................................................................................................... R-64 Sending Graphics Data......................................................................................................................R-65 Extended raster graphics (ESC . 2)..............................................................................................R-83 Printing Bar Codes............................................................................................................................. R-84 Extended ESC/P 2 Programming Guide........................................................................................R-99 Programming examples.............................................................................................................. R-104 ii Contents Command Table..............................................................................................................T-1 24/48-Pin Printers.................................................................................................................................T-2 9-Pin Printers.......................................................................................................................................T-22 Feature Summary............................................................................................................F-1 24/48-Pin Printers.................................................................................................................................F-3 9-Pin Printers.......................................................................................................................................F-78 Appendix..........................................................................................................................A-1 Character Tables...................................................................................................................................A-2 Proportional Width Information......................................................................................................A-21 Proportional width during multipoint mode (ESC/P 2 only)................................................A-21 24/48-pin proportional width tables...........................................................................................A-21 9-pin proportional width tables...................................................................................................A-26 ASCII Code Table...............................................................................................................................A-30 Parallel Interface.................................................................................................................................A-31 Internal Serial Interface.....................................................................................................................A-35 Six-pin DIN connector type..........................................................................................................A-35 25-pin subminiature D-shell connector (female) type..............................................................A-36 Optional Serial Interfaces..................................................................................................................A-37 Selecting PreESC/P 2 Fonts in ESC/P 2 Multipoint Mode..........................................................A-38 Glossary..........................................................................................................................G-1 Index..................................................................................................................................I-
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值