蓝牙打印机_ESC_POS指令集

合集下载

打印机ESCPOS 控制指令

打印机ESCPOS 控制指令

HDD-80260打印机ESC/POS控制指令ESC/POS控制指令
HT横向跳格
FF打印并走纸
CAN页模式下删除打印缓冲区内容
DLEDC4nmt实时产生钱箱开启脉冲
ESCFF页模式下打印
ESCSPn设置字符右间距
ESC!n选择打印模式
ESC$nLnH设置绝对打印位置
ESC&yc1c2[x1d1...d(y×x1)]...[xkd1...d(y×xk)]定义用户自定义字符
ESC*mnLnHd1...dk选择位图模式
ESC?n取消用户自定义字符
ESCGn选择/取消双重打印模式
ESCL选择页模式
ESCMn选择字体
ESCRn选择国际字符集
ESCS选择标准模式
ESCTn在页模式下选择打印区域方向
ESCVn选择字符旋转打印
ESCc5n允许/禁止按键
ESCpmt1t2产生钱箱控制脉冲
FSpnm打印下载到FLASH中的位图
FSqn[xLxHyLyHd1...dk]1...[xLxHyLyHd1...dk]n定义Flash位图
GS!n选择字符大小
GS#n定义当前下载图号
GS*xyd1...d(x×y×8)定义下载位图
GS/m打印下载位图
GS:开始/结束宏定义
GSHn选择HRI字符的打印位置
GSWnLnH设置打印区域宽度
GS\nLnH页模式下设置纵向相对位置
GShn选择条码高度
①GSkmd1...dkNUL②GSkmnd1...dn打印条码
FS!n设置汉字字符模式
FS&选择汉字模式
FS.取消汉字模式
FSSn1n2设置汉字字符左右间距。

Epson的打印机控制指令集ESC_P标准 (适用大部份针式,和喷墨)

Epson的打印机控制指令集ESC_P标准 (适用大部份针式,和喷墨)
*用法:将其命名PL.PRG
*使用命令DO PL WITH \"AR-5400\",\"这是测试行\"+CHR(0x0A)
*注意;第一个参数是要调用的打印机名,可用SET(\"Printer\",3)代替,第二个参数为要打印的字符串
*要打印的字符串后面必须加换行符才能立即输出
*需要说明的是:字体的控制需要用打印机内部的控制码
第一个参数是要调用的打印机名可用setprinter3代替第二个参数为要打印的字要打印的字符串后面必须加换行符才能立即输出需要说明的是
Epson的打印机控制指令集ESC/P标准(适用大部份针式,和喷墨)
描述:Epson的打印机控制指令集ESC/P标
图片:200712121284464103.jpg
描述:Epson的打印机控制指令集ESC/P标
*PARAMETERS PrnName,PrnStr
PrnName= GETPRINTER( )
PrnStr =CHR(7) &&打印机给叫一下
图片:200712121285423596.jpg
描述:Epson的打印机控制指令集ESC/P标
图片:20071212129086487.Байду номын сангаасpg
描述:Epson的打印机控制指令集ESC/P标
图片:20071212129557533.jpg
***直接打印的子程序演示,* PrnStr可以是中文文字**

蓝牙打印机 ESC_POS指令集

蓝牙打印机 ESC_POS指令集

说明:
n = 0, n = 2
打印机对主机请求作出反应,n值定义如下:
n = 0: 恢复到联机状态
n = 2: 清除接收和打印缓冲区,并恢复错误.
ESC SP n
设置字符右间距
格式: ASCII: ESC SP n
十进制: 27 32 n
十六进制: 1B 20 n
说明:
1≤ n≤ 3
默认 n = 1
位 功能 值
01
0 打印机选择 取消 设定
1 顾显选择 取消 设定
2 无定义
3 无定义
4 无定义
5 无定义
6 无定义
7 无定义
ESC ? n 取消用户自定义字符
格式: ASCII: ESC ? n
十进制: 27 63 n
ESC R n
选择国际字符集
格式: ASCII: ESC R n
十进制: 27 82 n
十六进制: 1B 52 n
说明:
ESC R用于选择11个不同国家的不同ASCII字符集。
n=0~10。默认值为0,选择U.S.A方式。
ESC U n
若当时有打印内容则在打印完成后执行走纸。
ESC K n
打印并反向走纸
格式: ASCII: ESC K n
十进制: 27 75 n
十六进制: 1B 4B n
说明:
0 ≤ n ≤ 48
打印缓冲区里的内容,并反方向走纸n/144英寸(n X 0.176 mm)。
m 垂直方向点数 点密度 最大点数 图形打印模式
0 8 单密度 210 相邻点打印
1 8 双密度 420 相邻点不打印
Dk 定义为:
ESC - n 设置/取消下划线模式

ESCPOS打印控制命令

ESCPOS打印控制命令

ESC/POS打印控制命令1、打印命令一览表命令速查命令说明打印命令LF 打印并换行ESC J 打印并走纸n点行格式设置命令ESC 2 设置行间距1/6英寸ESC 3 n 设置行间距为n点行(n/137英寸) ESC a n 设置对齐方式字符设置命令ESC ! n 设置打印字符格式ESC SO 设置字符倍宽打印ESC DC4 取消字符倍宽打印ESC { n 设置/取消字符上下倒置ESC B n 设置/取消字符反白打印ESC % n 设置/取消用户自定义字符ESC & 设定用户自定义字符ESC ? 取消用户自定义字符ESC R n 选择国际字符集ESC t n 选择字符代码页图形设置命令ESC * 打印一点行图形GS * 下装点图设置GS / 打印下装点图钱箱控制命令ESC p 钱箱控制按键控制命令ESC c 5 允许/禁止按键开关初始化命令ESC @ 打印机初始化状态传输命令ESC v 向主机传送打印机状态ESC u 向主机传送周边设置状态GS a 允许/禁止状态自动上传条码设置命令GS H 选择HRI打印方式GS h 设置条码高度GS w 设置条码横向宽度GS k 打印条码位置和页模式命令ESC L 设置页模式FF 打印,并返回到标准模式ESC FF 打印页模式的数据CAN 清除页缓冲区的数据ESC W … 设置页位置和大小ESC $ nL nH 设置页模式的绝对X位置GS $ nL nH 设置页模式的绝对Y位置ESC \ nL nH 设置页模式的相对X位置GS \ nL nH 设置页模式的相对Y位置GS L nL nH 设置页左边距GS W nL nH 设置页宽切纸模式命令ESC i 切纸但不走纸2、打印命令详解概述POS-58打印机使用ESC/POS打印命令集。

打印命令按以下格式说明:命令功能格式:ASCII:以标准ASCII字符序列表示十进制:以十进制数字序列表示十六进制:以十六进制数字序列表示说明:命令功能和使用说明。

便携式蓝牙打印机MPT-III[说明书]

便携式蓝牙打印机MPT-III[说明书]

厦门普瑞特科技有限公司热敏便携收据打印机MPT-III 便携蓝牙打印机系列厦门普瑞特科技有限公司目录注意事项 (3)第一章产品简介 (4)1.1打印机外观 (4)1.2型号说明 (4)1.3附件 (5)第二章性能特点 (6)2.1打印性能 (6)2.2物理参数 (6)2.3环境参数 (6)2.3其他性能 (6)第三章使用方法 (7)3.1使用前的准备 (7)3.1.1 电池安装 (7)3.1.2 打印纸卷安装 (7)3.2基本功能使用 (7)3.2.1 开机 (7)3.2.2 关机 (8)3.2.3 自检 (8)3.2.4 走纸(手动进纸) (8)3.2.5 充电 (8)3.3打印连接及打印 (8)3.3.1 串口连接 (8)3.3.2 原始红外和IrDA连接 (8)3.3.3 蓝牙(Bluetooth) (9)3.4指示灯及蜂鸣信号说明 (9)第四章其他信息 (10)4.1打印机开发手册 (10)4.2预印刷黑标说明 (10)注意事项在使用打印机之前,请仔细阅读本章内容!安全注意事项本打印机只能使用本公司提供的专用电池和电源适配器,否则可能引起产品损坏,电池漏液、起火甚至爆炸。

不要将电池投入火中,不要将电池短路、拆散或加热,否则可能导致电池漏液、起火甚至爆炸。

电池中的液体具有腐蚀性,如果操作不慎导致电池漏液并将液体粘到皮肤或衣物上,请立即用清水洗掉,如不慎进入眼睛内,请立即用大量清水彻底冲洗眼睛并去看医生。

打印时或刚打印结束时不要开启纸仓盖,用手或身体的任何部位接触打印机芯,以免过高的温度导致烫伤。

使用注意事项打印机不可浸入水中,也不要将其长时间暴露在雨中,否则可能导致打印机损坏。

打印过程中不得打开纸仓盖,否则可能导致打印机工作不正常。

在使用串口打印时,在打印过程中不能将串口线拔下,否则可能导致打印数据不完整。

在使用红外方式打印时,在打印过程中要将主设备的红外窗口对准打印机的红外视窗,距离不能超过50厘米,角度不能超过30度,否则可能导致打印乱码或无法打印。

c使用esc指令控制pos机打印小票

c使用esc指令控制pos机打印小票

c使用e s c指令控制p o s机打印小票标准化管理处编码[BBX968T-XBB8968-NNJ668-MM9N]C#使用ESC指令控制POS打印机打印小票1.前言C#打印小票可以与普通打印机一样,调用PrintDocument实现。

也可以发送标注你的ESC 指令实现。

由于调用PrintDocument类时,无法操作使用串口或TCP/IP接口连接的pos 打印机,并且无法发送控制指令实现pos打印机的切纸、走纸等动作。

因此个人建议使用ESC指令进行打印会更通用。

本类需要调用机打印小票ReceiptHelperusing System;usingusing ;usingusing ;using ;using ;using ;using ;using ;usingnamespace{#region结构体定义[StructLayout]public struct OVERLAPPED{int Internal;int InternalHigh;int Offset;int OffSetHigh;int hEvent;};[StructLayout]public struct PRINTER_DEFAULTS{public int pDatatype;public int pDevMode;public int DesiredAccess;}. ...设置打印参数意:打印该行内容后会自动换行(本类会在该行内容末尾添加一个换行符).直到获取到最右侧一列的点果当前像素是黑点,需要把数组里的对应比特位设置为1if (briary[pixidx]){bitidx = 7 - pixidxInCol % 8;低比特位对应末个像素 byteidx = byteidxInCol + pixidxInCol / 8; ET RAW Document";= "RAW";Boolean bl = StartDocPrinter(m_Handle, 1, di);if (!bl){return false;}bl = StartPagePrinter(m_Handle);return bl;}调用本函数之前必须先调用正确的设置字体、左边距函数不可与SetBigFont同时使用像处理 ImageProcessorusing System;usingusing ;using ;using ;using ;usingusing ;usingusing{过此亮度认为白点,否则认为黑点</param>rue表示亮度不同,false表示亮度相同过此亮度认为白点,否则认为黑点</param>相同,0不同= new Boolean[width * height];相同,0不同diffary = new Boolean[width * height];Int32 pixidx = 0;果是黑色,表示相同,白色,表示不同diffary[pixidx] = (pixbri > briDiff); ++pixidx;cmpretpix += 3;}cmpretpix += rowredundancy; }}(datadiff);bl = true;}catch (Exception ex){("CompareImage error:" + ;bl = false;}return bl;}相同,0不同= new Boolean[width * height];rue不同,false相同</param>何一个不同,就认为失败if == &&difftype !={return false;}有像素都相同,认为失败if == &&difftype =={return false;}return true;}///<summary>///检查指定区域的图像是否与方案里的指定值一样(都是相同或者不同)///</summary>///<param name="pixDiffary"></param>///<param name="area"></param>///<returns></returns>public static Boolean ValidateImageArea(Byte[] briDiffary, ImageAreaInfo area, Int32 width, Int32 height){Boolean[] blary = new Boolean[];for (Int32 idx = 0; idx < ; ++idx){blary[idx] = (briDiffary[idx] > 0);}Boolean bl = ValidateImageArea(blary, area, width, height);return bl;}///<summary>///检查图片的比较结果里,某个区域是否与期待的一致///</summary>///<param name="compareret"></param>///<param name="area"></param>///<returns>true-与期待一致;false-不一致</returns>public static Boolean ValidateImageArea(ImageCompareResult compareret, ImageAreaInfo area){Boolean[] pixDiffary = ;Bitmap tmp = new Bitmap;Int32 width = ;Int32 height = ;Boolean bl = ValidateImageArea, area, width, height);return bl;}///<summary>///获取1个比较结果里,指定的区域范围,是全都相同,还是不同///只有所有像素都是相同,才认为是整个区域相同///如果有1个像素不同,则认为整个区域不同///</summary>///<param name="pixDiffary"></param>///<param name="width"></param>///<param name="height"></param>///<param name="startX"></param>///<param name="startY"></param>///<param name="endX"></param>///<param name="endY"></param>///<returns></returns>public static Boolean GetImageAreaDifferentType(Boolean[] pixDiffary, Int32 width, Int32 height,Int32 x1, Int32 y1, Int32 x2, Int32 y2, ref eAreaDifferentType difftype){Int32 areawidth = x2 - x1;Int32 areaheight = y2 - y1;if (pixDiffary == null || width < 1 || height < 1 ||areawidth < 1 || areaheight < 1 ||width < areawidth || height < areaheight ||< width * height){return false;}Boolean allissame = false; //假设所有像素相同Boolean allisdiff = false; //假设所有像素不同Int32 currowFirstPix = 0;for (Int32 y = y1; y <= y2; ++y){currowFirstPix = y * width;for (Int32 x = x1; x <= x2; ++x){if (pixDiffary[currowFirstPix + x]) //当前像素点不同{allisdiff = true;}else//当前像素相同{allissame = true;}//如果已经有部分相同部分不同,退出if (allisdiff && allissame){difftype = ;return true;}}}//现在,所有像素都相同,或都不同if (allisdiff){difftype = ;}else{difftype = ;}return true;}///<summary>///根据亮度容差,把图片转换为非黑即白的图片///</summary>///<param name="briimg"></param>///<param name="brigate"></param>///<returns></returns>public static Boolean GetBlackWhiteImage(Bitmap briimg, Byte[] briDiffary, Int32 brigate, ref Bitmap blackwhiteimage){if (briimg == null){return false;}int width = ;int height = ;long allpixcnt = height * width;//所有像素点数量if (briDiffary == null || != allpixcnt){return false;}blackwhiteimage = new Bitmap(briimg);Int32 pixidx = 0;//当前像素下标BitmapData datasrc = null;BitmapData dataret = null;//每行末尾还有这么多的冗余字节Int32 rowredundancy = 0;Byte curpixBri = 0;//当前的亮度try{datasrc = (new Rectangle(0, 0, width, height),, ;dataret = (new Rectangle(0, 0, width, height),, ;rowredundancy = - width * 3;//每行末尾还有这么多的冗余字节unsafe{byte* pixret = (bytefor (int y = 0; y < height; y++){for (int x = 0; x < width; x++){//亮度差值大于门限的,认为是不同部分,用白色填充 curpixBri = (briDiffary[pixidx] > brigate) Const_BrightnessWhite : Const_BrightnessBlack;pixret[0] = curpixBri;//把亮度值设置到结果图像里 pixret[1] = curpixBri;pixret[2] = curpixBri;++pixidx;pixret += 3;}pixret += rowredundancy;}}(datasrc);(dataret);}catch (Exception ex){("GetBlackWhiteImage error:" + ;return false;}return true;}#endregion#region内部实现///<summary>///比较2个数值之间的差是否大于指定值///</summary>///<param name="val1"></param>///<param name="val2"></param>///<param name="diff"></param>///<returns>超过指定值返回true;否则返回false</returns>private static Boolean CheckDiffOver(Int32 val1, Int32 val2, Int32 diff){if (diff < 1){return false;}if (val1 > val2 && val1 > val2 + diff){return true;}if (val2 > val1 && val2 > val1 + diff){return true;}return false;}#endregion }}。

使用ESC指令控制POS机小票

使用ESC指令控制POS机小票

使用ESC指令控制POS机小票C#使用ESC指令控制POS打印机打印小票1.前言C#打印小票可以与普通打印机一样,调用PrintDocument实现。

也可以发送标注你的ESC 指令实现。

由于调用PrintDocument类时,无法操作使用串口或TCP/IP接口连接的pos 打印机,并且无法发送控制指令实现pos打印机的切纸、走纸等动作。

因此个人建议使用ESC 指令进行打印会更通用。

本类需要调用ImageProcessor.cs2.POS机打印小票ReceiptHelperusing System;usingusing System.Text;usingusing System.Threading;using System.Drawing;using System.Management;using System.IO;using LaisonTech.MediaLib;using /doc/6213217853.html,monBLL;usingnamespace LaisonTech.MediaLib{#region结构体定义[StructLayout(LayoutKind.Sequential)]public struct OVERLAPPED{int Internal;int InternalHigh;int Offset;int OffSetHigh;int hEvent;};[StructLayout(LayoutKind.Sequential)]public struct PRINTER_DEFAULTS{public int pDatatype;public int pDevMode;public int DesiredAccess;}//////对齐方式///public enum eT extAlignMode{Left = 0,Middle = 1,Right = 2}#endregion//////小票打印类/// 使用方法:/// 1 GetPrinterList获取已经安装的所有打印机列表./// Open 打开指定打印机/// 2 控制打印机动作、执行打印内容之前,必须先调用StartPrint,准备向打印机发送控制指令/// 3 调用SetLeft, SetBold, SetAlignMode, SetFontSize ... ...设置打印参数/// 4 PrintText 打印内容.注意:打印该行内容后会自动换行(本类会在该行内容末尾添加一个换行符)/// PrintImageFile 或PrintBitMap打印图片/// 5 控制指令和打印内容都发送完毕后,调用EndPrint执行真正打印动作/// 6 退出程序前调用Close///public class ReceiptHelper{#region指令定义private static Byte[] Const_Init = new byte[] { 0x1B, 0x40,0x20, 0x20, 0x20, 0x0A,0x1B, 0x64,0x10};//设置左边距private const string Const_SetLeft = "1D 4C ";//设置粗体private const string Const_SetBold = "1B 45 ";private const String Const_Bold_YES = "01";private const String Const_Bold_NO = "00";//设置对齐方式private const string Const_SetAlign = "1B 61 ";private const String Const_Align_Left = "30";private const String Const_Align_Middle = "31";private const String Const_Align_Right = "32";//设置字体大小,与SetBigFont 不能同时使用private const string Const_SetFontSize = "1D 21 ";//设置是否大字体,等同于SetFontSize = 2//private const String Const_SetBigFontBold = "1B 21 38";//private const String Const_SetBigFontNotBold = "1B 21 30";//private const String Const_SetCancelBigFont = "1B 21 00";//////打印并走纸///private static Byte[] Const_Cmd_Print = new byte[] { 0x1B, 0x4A, 0x00 };//走纸private const string Const_FeedForward = "1B 4A ";private const string Const_FeedBack = "1B 6A ";//切纸private static Byte[] Const_SetCut = new byte[] { 0x1D, 0x56, 0x30};//查询打印机状态private static Byte[] Const_QueryID = new byte[] { 0x1D, 0x67, 0x61};//回复帧以ID 开头private static String Const_ResponseQueryID = "ID";//////设置图标的指令///private static Byte[] Const_SetImageCommand = new Byte[] { 0x1B, 0x2A, 0x21 }; #endregion#region常量定义//////最大字体大小///public const Int32 Const_MaxFontSize = 8;//////最大走纸距离///public const Int32 Const_MaxFeedLength = 5000;//////最大高宽///public const Int32 Const_MaxImageLength = 480;//////每次通信最多打印的行数///public const Int32 Const_OncePrintRowCount = 24;public const Int32 Const_BrightnessGate = 100;//////无效句柄///public const Int32 Const_InvalidHandle = -1;#endregion#region私有成员//////打印机句柄///private int m_Handle = -1;//////是否已经初始化///private Boolean m_Inited = false;#endregion#region私有函数[DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]public static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, out Int32 hPrinter, IntPtr pd);[DllImport("winspool.Drv", EntryPoint = "StartDocPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]public static extern bool StartDocPrinter(Int32 hPrinter, Int32 level, [In, MarshalAs(UnmanagedType.LPStruct)] DOCINFOA di);[DllImport("winspool.Drv", EntryPoint = "EndDocPrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]public static extern bool EndDocPrinter(Int32 hPrinter);[DllImport("winspool.Drv", EntryPoint = "StartPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]public static extern bool StartPagePrinter(Int32 hPrinter);[DllImport("winspool.Drv", EntryPoint = "EndPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]public static extern bool EndPagePrinter(Int32 hPrinter);[DllImport("winspool.Drv", EntryPoint = "WritePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]public static extern bool WritePrinter(Int32 hPrinter, Byte[] pBytes, Int32 dwCount, out Int32 dwWritten);[DllImport("winspool.Drv", EntryPoint = "ClosePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]public static extern bool ClosePrinter(Int32 hPrinter);//////发送指令/////////private Boolean SendCommand(Byte[] cmd){if (m_Handle == Const_InvalidHandle || cmd == null || cmd.Length < 2){return false;}int writelen = 0;Boolean bl = WritePrinter(m_Handle, cmd, cmd.Length, out writelen);if (!bl) return false;return (writelen >= cmd.Length);}//////发送文本格式的指令/////////private Boolean SendCommand(String hexstrcmd){if (m_Handle == Const_InvalidHandle || hexstrcmd == null || hexstrcmd.Length < 4){return false;}byte[] mybyte = null;Boolean bl = DataFormatProcessor.HexStringT oBytes(hexstrcmd, out mybyte);bl = SendCommand(mybyte);return bl;}#endregion#region内部处理- 打印图片//////把图片转换为指令字节,图片最大高宽不能超过480////////////public static Boolean LoadImage(Bitmap image,ref Byte[] bitarray,ref Int32 datawidth,ref Int32 dataheight) {Int32 newwidth = 0;Int32 newheight = 0;Bitmap destimage = image;Boolean bl = false;//如果高度超过范围,或宽度超过范围,需要进行缩小if (image.Width > Const_MaxImageLength || image.Height > Const_MaxImageLength){//按照高度和宽度,较大的那一边,进行缩放if (image.Width > image.Height){newwidth = Const_MaxImageLength;newheight = (Int32)(image.Height * newwidth / (float)image.Width);}else{newheight = Const_MaxImageLength;newwidth = (Int32)(newheight * image.Width / (float)image.Height);}bl = ImageProcessor.ResizeImage(image, newwidth, newheight, ref destimage);}//把数据转换为字节数组bl = GetBitArray(image, ref bitarray, ref datawidth, ref dataheight);return bl;}//////把图片转换为指令字节,图片最大高宽不能超过480///如果图片的高度不是24的整数倍,则修改为24的整数倍////////////public static Boolean LoadImageFromFile(String imagefilename, ref Byte[] bmpbytes, ref Int32 width, ref Int32 height){Bitmap img = ImageProcessor.LoadBitImage(imagefilename);if (img == null){return false;}Boolean bl = LoadImage(img, ref bmpbytes, ref width, ref height);return bl;}//////把图片转换为位图数组,每个字节的每个比特位,对应当前像素是否需要打印////////////public static Boolean GetBitArray(Bitmap img,ref Byte[] allbitary, ref Int32 width, ref Int32 height){if (img == null){return false;}//ESC指令格式规定://1 打印图片时,每条指令最多只打印24行;不足24行的,也要用全0填充满数据字节//2 打印24行数据时,按照光栅模式纵向获取数据// 即先获取所有x=0的点(第0列)转换为3个字节;// 再获取所有x=1的点转换为3个字节;...直到获取到最右侧一列的点//3 打印完当前24行数据后,再获取后续24行的数据内容,直到所有的数据获取完毕//获取亮度数组Boolean[] briary = null;Boolean bl = ImageProcessor.ToBooleanArray(img, Const_BrightnessGate, ref briary);if (!bl){return false;}height = img.Height;//如果图像高度不是24整数倍,设置为24的整数倍if (height % Const_OncePrintRowCount != 0){height = height + Const_OncePrintRowCount - height %Const_OncePrintRowCount;}width = img.Width;//如果图像宽度不是8的整数倍,设置为8的整数倍if (width % 8 != 0){width = width + 8 - width % 8;}Int32 bytelen = height * width / 8;//每个像素对应1个比特位,因此总字节数=像素位数/8allbitary = new Byte[bytelen];Int32 byteidxInCol = 0;//当前列里首个像素,在目标字节数组里的下标Int32 byteidx = 0;//当前像素在目标数组里的字节下标Int32 bitidx = 0;//当前像素在目标数组里当前字节里的比特位下标Int32 pixidxInCol = 0;//当前像素在当前列里的第几个位置Int32 pixidx = 0;//当前像素在原始图片里的下标Int32 rowidx = 0; //当前处理的像素点所在行,不能超过图像高度Int32 curprocrows = 0;//当前需要处理的行数量while (rowidx < height){//按照纵向次序,把当前列的24个数据,转换为3个字节for (Int32 colidx = 0; colidx < img.Width; ++colidx){//如果当前还剩余超过24行没处理,处理24行if (rowidx + Const_OncePrintRowCount <= img.Height){curprocrows = Const_OncePrintRowCount;}else{//已经不足24行,只处理剩余行数curprocrows = img.Height - rowidx;}pixidxInCol = 0; //本列里从像素0开始处理for (Int32 y = rowidx; y < rowidx + curprocrows; ++y){//原始图片里像素位置pixidx = y * img.Width + colidx;//获取当前像素的亮度值.如果当前像素是黑点,需要把数组里的对应比特位设置为1if (briary[pixidx]){bitidx = 7 - pixidxInCol % 8;//最高比特位对应首个像素.最低比特位对应末个像素byteidx = byteidxInCol + pixidxInCol / 8; //由于最后一段可能不足24行,因此不能使用byteidx++DataFormatProcessor.SetBitValue(bitidx, true, refallbitary[byteidx]);}pixidxInCol++;}byteidxInCol += 3;//每列固定24个像素,3个字节}rowidx += Const_OncePrintRowCount;}return true;}#endregion#region公开函数private static ReceiptHelper m_instance = new ReceiptHelper();//////当前使用的打印机名称///public String PrinterName{get;private set;}//////单件模式//////public static ReceiptHelper GetInstance(){return m_instance;}//////获取本机安装的所有打印机//////public static List GetPrinterList(){List ret = new List();if (PrinterSettings.InstalledPrinters.Count < 1){return ret;}foreach (String printername in PrinterSettings.InstalledPrinters){ret.Add(printername);}return ret;}//////打开打印机/////////public Boolean Open(String printername){if (m_Inited){return true;}Boolean bl = OpenPrinter(printername.Normalize(), out m_Handle, IntPtr.Zero);m_Inited = (bl && m_Handle != 0);return true;}///开始打印,在打印之前必须调用此函数//////public Boolean StartPrint(){if (!m_Inited){return false;}DOCINFOA di = new DOCINFOA();di.pDocName = "My C#.NET RAW Document"; di.pDataType = "RAW";//Start a document.Boolean bl = StartDocPrinter(m_Handle, 1, di); if (!bl){return false;}// Start a page.bl = StartPagePrinter(m_Handle);return bl;}//////结束打印,在打印结束之后必须调用此函数//////public Boolean EndPrint(){if (!m_Inited)return false;}Boolean bl = EndPagePrinter(m_Handle);bl = EndDocPrinter(m_Handle);return bl;}//////销毁//////public Boolean Close(){if (!m_Inited){return true;}m_Inited = false;//关闭设备句柄ClosePrinter(m_Handle);m_Handle = -1;return true;}//////打印文本.在调用本函数之前必须先调用正确的设置字体、左边距/////////public Boolean PrintText(String content){if (!m_Inited){return false;}byte[] bytes = null;if (content.Length < 1){content = " ";}if (content[content.Length - 1] != (char)0x0D && content[content.Length - 1] != (char)0x0A){content = content + (char)0x0A;}bytes = DataFormatProcessor.StringT oBytes(content); bool bl = SendCommand(bytes);return bl;}//////设置对齐方式/////////public bool SetAlignMode(eTextAlignMode alignmode) {if (!m_Inited){return false;}String code = String.Empty;switch (alignmode){case eTextAlignMode.Left:code = Const_Align_Left; break;case eTextAlignMode.Middle: code = Const_Align_Middle; break;case eTextAlignMode.Right:code = Const_Align_Right; break;default:code = Const_Align_Left; break;}//注意:先低字节后高字节string str = Const_SetAlign + code; bool bl = SendCommand(str); return bl;}//////设置左边距/////////public bool SetLeft(int left){if (!m_Inited){return false;}//注意:先低字节后高字节String hexstr = left.ToString("X4");string str = Const_SetLeft + hexstr.Substring(2, 2) + hexstr.Substring(0, 2);bool bl = SendCommand(str);return bl;}//////设置粗体/////////public Boolean SetBold(Boolean bold){if (!m_Inited){return false;}//注意:先低字节后高字节String str = String.Empty;if (bold){str = Const_SetBold + Const_Bold_YES;}else{str = Const_SetBold + Const_Bold_NO;}bool bl = SendCommand(str);return bl;}//////切纸//////public bool Cut(){if (!m_Inited){return false;}bool bl = SendCommand(Const_SetCut);return bl;}//////打印图片/////////public bool PrintImageFile(String imgfilename){if (!m_Inited){return false;}Bitmap img = ImageProcessor.LoadBitImage(imgfilename); if (img == null){return false;}Boolean bl = PrintBitmap(img);return bl;}//////打印图片/////////public bool PrintBitmap(Bitmap bitmap){if (!m_Inited){return false;}if (bitmap == null ||bitmap.Width > Const_MaxImageLength ||bitmap.Height > Const_MaxImageLength){return false;}Byte[] bitary = null;Int32 width = 0;Int32 height = 0;Boolean bl = GetBitArray(bitmap, ref bitary, ref width, ref height);bl = PrintBitmapBytes(bitary, bitmap.Width, bitmap.Height);return bl;}//////打印图片/////////public bool PrintBitmapBytes(Byte[] imgbitarray, Int32 width, Int32 height) {if (!m_Inited){return false;}Int32 bytes = width * height / 8;//检查是否尺寸符合要求if (width > Const_MaxImageLength || height > Const_MaxFeedLength || width < 1 || height < 1 ||imgbitarray == null){return false;}//每次获取24行的数据进行发送,这24行的字节数Int32 blockbytes = width * Const_OncePrintRowCount / 8;if (blockbytes < 1){return false;}Boolean bl = false;//一共需要发送的块数量Int32 blocks = imgbitarray.Length / blockbytes;//每次发送的数据字节数= 1B 2A 21 2字节长度+数据内容Byte[] cmdbytes = new Byte[5 + blockbytes];//指令Array.Copy(Const_SetImageCommand, cmdbytes, 3);//数据长度,即每行的点数DataFormatProcessor.Int16T oBytes(width, ref cmdbytes, 3);//数据内容for (Int32 blockidx = 0; blockidx < blocks; ++blockidx){Array.Copy(imgbitarray, blockidx * blockbytes, cmdbytes, 5, blockbytes);//发送当前指令bl = SendCommand(cmdbytes);if (!bl) return false;//休眠20毫秒Thread.Sleep(20);//发送打印指令bl = SendCommand(Const_Cmd_Print);if (!bl) return false;}return bl;}//////走纸/////////public bool Feed(int length){if (!m_Inited){return false;}if (length < 1)length = 1;if (length > Const_MaxFeedLength) {length = Const_MaxFeedLength; }string len = length.ToString("X2"); len = Const_FeedForward + len; bool bl = SendCommand(len); return bl;}//////回退走纸/////////public bool FeedBack(int length) {if (!m_Inited){return false;}if (length < 1)length = 1;if (length > Const_MaxFeedLength) {length = Const_MaxFeedLength; }string len = length.ToString("X2"); len = Const_FeedBack + len;bool bl = SendCommand(len);return bl;}//////设置字体大小.本函数不可与SetBigFont同时使用//////大小倍率,取值范围1 - 8 ///public bool SetFontSize(Int32 sizerate){if (!m_Inited){return false;}if (sizerate < 1){sizerate = 1;}if (sizerate > Const_MaxFontSize){sizerate = Const_MaxFontSize;}sizerate--;String sizecodestr = Const_SetFontSize + sizerate.ToString("X1") + sizerate.ToString("X1");bool bl = SendCommand(sizecodestr);return bl;}#endregion}}3.图像处理 ImageProcessorusing System;usingusing System.Linq;using System.Text;using System.Drawing;using /doc/6213217853.html,monBLL; usingusing System.IO;usingusingusingnamespace LaisonTech.MediaLib{//////图片格式///public enum ePictureFileFormat{Bmp = 0,Gif = 1,Icon = 2,Jpeg = 3,Png = 4,}//////转为灰度图像的方式///public enum eGrayMode{///算数平均///ArithmeticAverage = 0,///加权平均///WeightedAverage = 1,}//////比较2个图片的指定区域范围,像素的相同类型///public enum eAreaDifferentType{//////所有像素都相同///AllSame = 0,//////所有像素都不同///AllDifferent = 1,//////部分相同部分不同///Partial = 2,}//////图片文件处理///public class ImageProcessor#region常量定义public const Byte Const_BrightnessWhite = 255;public const Byte Const_BrightnessBlack = 0;//////比较结果的图片里,亮度相同部分的填充颜色///public static Color Const_SameBrightnessColor = Color.Black;//////比较结果的图片里,亮度相同部分的填充颜色///public static Color Const_DifferentBrightnessColor = Color.White;public const Byte Const_BlackBrightness = 0;public const Byte Const_WhiteBrightness = 255;public const Int32 Const_MaxBrightness = 255;public const Int32 Const_MinBrightness = -255;//////亮度的中间值public const Int32 Const_MiddleBrightness = 128;#endregion#region屏幕截图,打印//////获取屏幕分辨率/////////public static void GetScreenSize(ref Int32 width, ref Int32 height) {height = Screenwidth = Screen}//////截图指定控件上显示的内容/////////public static Image CaptureControlImage(Control ctrl) {if (ctrl == null){return null;}Control parent = ctrl;if (ctrl.Parent != null){parent = ctrl.Parent;}Point screenPoint = parent.PointT oScreen(ctrl.Location); Image ret = new Bitmap(ctrl.Width, ctrl.Height); Graphics g = Graphics.FromImage(ret);g.CopyFromScreen(screenPoint.X, screenPoint.Y,0, 0, ctrl.Size);g.DrawImage(ret, 0, 0);return ret;}#endregion#region装载图片//////装载图像文件/// /// ///。

ESCPOS命令集

ESCPOS命令集

ESC/POS命令集2007-11-19 14:56切纸指令:发送:十六进制:1B694.1 基本控制指令4.1.1 ESC @[名称] 初始化打印机[格式] ASCII码 ESC @十六进制码 1B 40十进制码 27 64[描述] 清除打印缓冲区中的数据,复位打印机打印参数到当打印机缺省参数。

[注意] * 不是完全恢复到出厂设置,用户参数设置(见三、JPM112打印机工具软件)不会被更改。

[例子] char SendStr[3];SendStr[0] = 0x1BSendStr[1] = 0x40;PrtSendData(SendStr, 2);4.1.2 FF[名称] 打印并走纸到下页首[格式] ASCII码 FF14/53----------------------- 16-----------------------用户文档 JPM112 打印机开发手册(V1.0 )十六进制码 0C十进制码 12[描述] 将打印缓冲区中的数据全部打印出来并返回标准模式。

[注意] * 打印后,删除打印缓冲区中的数据。

* 该命令设置打印位置为行的起始点。

* 如果打印纸有预印刷黑标,则打印缓冲区中的数据后,走纸到黑标处,如果打印纸无黑标,则走纸0.5m后停止,预印刷黑标的规范请见附录B.预印刷黑标说明。

[例子] char SendStr[2];SendStr[0] = 0x0C;PrtSendData( SendStr, 1);4.1.3 LF[名称] 打印并换行[格式] ASCII码 LF十六进制码 0A十进制码 10[描述] 把打印缓冲区中的数据打印出来,并换行。

[注意] * 该命令把打印位置设置为行的开始位置。

[参考] CR[例子] char SendStr[2];SendStr[0]=’\n’; //C语言中’\n’即为换行PrtSendData( SendStr, 1);4.1.4 CR[名称] 打印并回车[格式] ASCII码 CR十六进制码 0D十进制码 13[描述] 打印但不进纸。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

十进制: 27 69 0
十六进制: 1B 45 0
说明:
0 ≤ n ≤ 255
当n的LSB位是0,取消着重模式。
当n的LSB位是1,设置着重模式。
ESC G n
设置/取消重叠模式
格式: ASCII: ESC G NUL
十进制: 27 71 0
十六进制: 1B 47 0
当只有一个自定义字符时,取m=n。
a:自定义字符的水平方向的点数。
d1 d2……db:自定义字符的数据。每个字符 y×x个字节,m-n+1个自定义字符共有:
(y×x)×(m-n+1)个字节。
每个自定义字符数据的格式:
d1 d3 … d(y×x)×(m-n+1)-1
d2 d4 … d(y×x)×(m-n+1)
十进制: 09
十六进制: 09
说明:
打印位置进行到下一水平制表位置。
如果当前打印位置超过了最后一个水平制表位置,则HT命令不被执行。
水平制表位置由 ESC D命令设置。
LF
打印并换行
格式: ASCII: LF
十进制: 10
十六进制: 0A
ESC R n
选择国际字符集
格式: ASCII: ESC R n
十进制: 27 82 n
十六进制: 1B 52 n
说明:
ESC R用于选择11个不同国家的不同ASCII字符集。
n=0~10。默认值为0,选择U.S.A方式。
ESC U n
消除所有的水平制表位置
格式: ASCII: ESC D NULL
十进制: 27 68 0
十六进制: 1B 44 0
说明:
ESC D NUL命令消除所有的水平制表位置,之后再执行的HT命令将无效。
ESC E n
设置/取消着重模式
格式: ASCII: ESC E NUL
打印参数n的每位定义为:
位 功能 值
01
0 字模选择 7×9 5×7
1 无定义
2 无定义
3 着重模式 取消 设定
4 倍 高 取消 设定
5 倍 宽 取消 设定
6 无定义
7 下划线 取消 设定
默认值n=0,
ESC % n
允许/禁止用户自定义字符
格式: ASCII: ESC % n
ESC 3 n
设定 n/144英寸换行量
格式: ASCII: ESC 3 n
十进制: 27 51 n
十六进制: 1B 33 n
说明:
此指令将打印机的换行量设定为 n/144英寸。
n=1 - 255。
ESC 〈
打印头归位
说明:
n = 0, n = 2
打印机对主机请求作出反应,n值定义如下:
n = 0: 恢复到联机状态
n = 2: 清除接收和打印缓冲区,并恢复错误.
ESC SP n
设置字符右间距
格式: ASCII: ESC SP n
十进制: 27 32 n
十六进制: 1B 20 n
说明:
以半点为设定单位(1/144英寸),设置字符右边间距为n个半点距。
默认值n=0。
ESC ! n
设置字符打印方式
格式: ASCII: ESC ! n
十进制: 27 33 n
十六进制: 1B 21 n
说明:
0≤n≤255
ESC ! n是综合性的字符打印方式设置命令,用于选择打印字符的大小和下划线。
中文模式下的命令
代码
功能
FS – n
设置中文字符下划线模式开关
FS ! n
选择中文字体
FS &
选择中文字符模式
FS .
取消中文模式
----------------------------------------------------------------------------------------
n = 4: 纸检测器状态
返回的字节每位设置如下:
n = 1: 打印机状态
n = 2: 脱机状态
n = 3: 错误状态
n = 4: 纸检测器状态
DLE ENQ n
对打印机的实时请求
格式: ASCII: DLE ENQ n
十进制: 16 05 n
十六进制: 10 5
十进制: 27 37 n
十六进制: 1B 25 n
说明:
参数n为一个字节,只有最低位有效。
当n=<*******1>B时,选择用户自定义字符集;
当n=<*******0>B时,选择内部字符集。
0≤n≤255,默认值n=0。
ESC &
设置用户自定义字符
格式: ASCII: ESC & y n m x d1 d2……db
默认值n=0。
ESC a n
设置/取消单向打印
格式: ASCII: ESC U n
十进制: 27 85 n
十六进制: 1B 55 n
说明:
设置/取消单向打印。n=0~255,仅最低位有效。
当n=<×××××××1>B时,在字符方式下设置为准双向打印,在图形方式下设置为单向打印。
当n=<×××××××0>B时,设置双向打印。
功能 回车 设置打印方式 选择或取消用户自定义字符集 定义用户自定义字符集 设置位映射方式 初始化打印机 LED ON/OFF 返回行首 选择行间距为1/6英寸 设置行进为最小间距 蜂鸣器ON/OFF 设置单页长度 选择打印页 选择行间距 选择纸结束信号输出 选择打印纸及检测器(终止打印) 禁止/使能面板开关 禁止/使能ON-LINE开关 打印及N行进纸 设置TAB位置 打印病退回N行 设单页等待时间 选择或取消单页退纸区 全切割 以最小间距进行打印和进纸 以最小间距进行打印和退纸 选择或取消倒过来的字符 局部切割 印章 产生指定脉冲 释放纸 选择打印颜色 选择国际字符子集 设置右边界 选择字符码表 选择或取消单向打印 发送打印机状态 设置或取消两页并行打印 打印送出单页 水平TAB 换行 流水TAB
0≤n1≤255,0≤n2≤1,0≤Dk≤255,k= n1+ n2×256。
n1,n2为两位十六进制数,n1这低字节,n2这高字节,k= n1+ n2×256,表示该命令下载的要打印图形的横向点数,该值应小于打印机 的最大行宽打印点数。如果下送的点图数据超出一行的最大行宽打印点数时,超出的部分被忽略。
十六进制: 1B 3F n
说明:
32 ≤ n ≤ 126
ESC @
初始化打印机
格式: ASCII: ESC @
十进制: 27 64
十六进制: 1B 40
说明:
该命令初始化打印机:使打印机恢复到最初的联机状态,清除以前留下的程序。
ESC D NULL
说明:
0 ≤ n ≤ 255
当n的LSB位是0,取消重叠模式。
当n的LSB位是1,设置重叠模式。
ESC J n
执行n/144英寸走纸
格式: ASCII: ESC J n
十进制: 27 74 n
十六进制: 1B 4A n
说明:
进纸n/144英寸,n值应为0到255之间的任意值。
Xprinter初始密码:123456 佳博初始密码:0000
蓝牙打印机 ESC/POS指令集
英文模式下的命令 代码 CR ESC ! ESC % ESC & ESC * ESC @ ESC ~ ESC < ESC 2 ESC 3 ESC BEL ESC C ESC c0 ESC c1 ESC c3 ESC c4 ESC c5 ESC c6 ESC d ESC D ESC e ESC f ESC F ESC i ESC J ESC K ESC l ESC m ESC o ESC p ESC q ESC r ESC R ESC SP ESC t ESC U ESC V ESC z FF HT LF RS
m 垂直方向点数 点密度 最大点数 图形打印模式
0 8 单密度 210 相邻点打印
1 8 双密度 420 相邻点不打印
Dk 定义为:
ESC - n 设置/取消下划线模式
格式: ASCII: ESC - n
十进制: 27 45 n
十六进制: 1B 2D n
说明:
n = 0, 1, 48, 49
n = 0 or 48,取消下划线模式。
n = 1 or 49, 设置下划线模式。
ESC 2
设定1/6英寸换行量
格式: ASCII: ESC 2
十进制: 27 50
十六进制: 1B 32
说明:
此指令将打印机的换行量设定为1/6英寸。
说明:
打印存放在行编辑缓存中的一行数据并按当前设定的行距向前走纸一行。ESC2,ESC3指令可设定行距的长短。
如果行编辑缓存空,则只按当前设定的行距向前走纸一行。
CR
打印回车
格式: ASCII: CR
十进制: 13
十六进制: 0D
说明:
当打印在行编辑缓存中的一行数据之后,不进行走纸操作。
十进制: 27 38 y n m x d1 d2……db
十六进制: 1B 26 y n m x d1 d2……db
说明:
该命令用于自定义字符。各参数为:
y:字符的纵向字节数。这里取 y=1,2。
n:自定义字符集的起始ASCII码,n≥32。
m:自定义字符集的终止ASCII码,m≤127。自定义字符个数为m-n+1,最多可定义96个字符。
格式: ASCII: ESC 〈
十进制: 27 60
十六进制: 1B 3C
说明:
执行该指令后,打针头会回到原位(home的位置)。
相关文档
最新文档