只是对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...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));
}
}
分享到:
相关推荐
使用ESC/POS打印指令控制微型打印机打印,必备手册. 全面解释了各种打印方式:如字体的放大,下划线,中文字符的打印等.
爱普生指令全集 esc/pos指令
该打印控制命令(WPSON StandardCode for Printer)是...ESC/POS打印命令集是ESC打印控制命令的简化版本,现在大多数票据打印都采用ESC/POS指令集。其显著特征是:其中很大一部分指令都是以ESC控制符开始的一串代码。
爱普生的BA-T500II 可搭配M-T500II系列4种纸宽的热敏打印机芯使用,是目前市场上功能最为强大的热敏控制板。采用VC++10 (VS2010组件) 重新编写了BA-T500II热敏控制板的全部ESC/POS指令例程。
Epson ESC/POS开发入门 Epson ESC/POS指令集开发入门
EPSON ESC/POS指令 对指令进行了重点标注,可以参考学习。
ESC/POS通用打印机指令集
完成的爱普生TM-T82全部ESC/POS指令的几乎所有细节的演示,除去即将过时的几条指令。 1) 串口借助了System.IO.Serialport 4.0, 2) 网络接口借助了System.Net.Socket 4.0. 3) USB接口基于LibUsbDotNet 2.2.8 TM-T82...
热敏打印机开发必备的指令集手册,是爱普生官方的指令集,开发必备!!
EPSON系列票据打印机指令集EPSON series bill printer instruction set
收据打印机二次开发包,支持有支持ESC/POS指令的打印机。DELPHI,VB,VC
ESC/POS 打印控件,主要针对epson 52II系列的热敏
ESC/POS by C#2010 for Epson TM-T82 完成的爱普生TM-T82全部ESC/POS指令的几乎所有细节的演示,除去即将过时的几条指令。 1) 串口借助了System.IO.Serialport 4.0, 2) 网络接口借助了System.Net.Socket 4.0. ...
指令集
利用RS232串口在QT5.51中免驱动开发爱普生ESC-POS热敏打印机,打印机型号为80mm,芯烨。另外随程序附送爱普生热敏打印机开发手册。
png2pos, 将PNG图像转换为 esc/pos的实用程序 png2pos png2pos是将PNG图像转换为( 打印机控制代码和转义序列)/POS格式的实用程序,由POS热敏打印机使用。 输出文件可以直接发送到打印机。png2pos不包含任何Epson驱动...
分享EPSON指令集,支持EPSON大多数打印机,如LQ-300,LQ570,LQ670,LQ870,LQ-1070,LQ2170,Stylus 800,Stylus Color,sq-870等。
EPSON指令集 打印控制命令 5.1.打印控制命令 5.1.1 概述 BS-210BM 提供了ESC/POS命令集。下面将对每个命令进行说明。每个命令的说明包括格式和解释两部分。格式部分提供了命令的ASCII码、十进制码和十六进码三种...
EPSON爱普生机器人指令大全