蓝牙打印机_ESC_POS指令集
- 格式:pdf
- 大小:272.93 KB
- 文档页数:16
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设置汉字字符左右间距。
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 便携蓝牙打印机系列厦门普瑞特科技有限公司目录注意事项 (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使用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机小票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装载图片//////装载图像文件/// /// ///。
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[描述] 打印但不进纸。
打印机E S C P O S控制指令集团企业公司编码:(LL3698-KKI1269-TM2483-LUI12689-ITT289-H D D-80260打印机E S C/P O S控制指令ESC/POS控制指令HT横向跳格如果下一个跳格位置没有设置,该指令被忽略。
如果下一个横向跳格位置超越打印区域,将当前位置设置为[打印宽度+1]。
水平跳格位置由指令ESCD来设置。
如果接收到此命令时当前位置在[打印宽度+1],打印机执行当前行缓冲区满动作并且将打印位置移到下一行的起始位置。
默认值跳格位置是每8个标准ASCII字符(12×24)字符跳一格。
当前行缓冲区满时,打印机执行下列动作:标准模式下,打印机打印当前行内容并将打印位置置于下一行的起始位置。
页模式下,打印机进行换行并将打印位置置于下一行的起始位置。
LF打印并走纸一行该指令将当前位置置于行首。
FF打印并走纸打印后清除缓冲区的内容。
由ESCW指令设置的打印区域被重置为默认设置。
打印机不执行切纸动作。
该指令将当前位置置于行首。
该指令只在页模式下有效。
CR打印并回车设置打印位置为行首。
串行接口模式下该指令被忽略。
并口模式下该指令是否有效由打印机配置决定。
CAN页模式下删除打印缓冲区内容该指令只在页模式下有效。
如果先前设定区域与当前区域有重叠部分,重叠部分也被删除。
DLEDC4nmt实时产生钱箱开启脉冲当打印机正在执行钱箱开启命令(ESCp或DELDC4)时,该命令被忽略。
串口模式下,打印机接收该指令后立即执行。
并口模式下,打印机忙的时候该指令不执行。
如果打印数据中包含和此指令相同的数据,则这些数据将被当作该指令执行。
用户必须考虑到这种情况。
该指令尽量不要插在2个或更多字节的指令序列中。
即使打印机被ESC=(选择外设)命令设置为禁止,该指令依然有效。
ESCFF页模式下打印该指令只在页模式下有效。
打印后不清除打印缓冲区的内容、ESCT和ESCW设置和字符的位置。
react-native-bluetooth-escpos-printer是一个用于在React Native应用中实现蓝牙ESC/POS打印机功能的库。
它允许您通过蓝牙连接ESC/POS打印机,并使用提供的API进行打印操作。
要使用react-native-bluetooth-escpos-printer,您需要按照以下步骤进行操作:1. 安装库:使用npm或yarn将库安装到您的React Native项目中。
您可以在终端中运行以下命令来安装库:shell复制代码npm install react-native-bluetooth-escpos-printer2. 链接库:在React Native中,您需要将原生模块链接到您的应用中。
在终端中运行以下命令来链接库:shell复制代码react-native link react-native-bluetooth-escpos-printer3. 导入库:在您的React Native组件中,您需要导入库并使用它提供的API。
您可以使用以下代码导入库:javascript复制代码import { ESCPOS, ESCPOSPrinter } from'react-native-bluetooth-escpos-printer';4. 连接打印机:使用ESCPOSPrinter类提供的API,您可以连接到您的ESC/POS打印机。
您可以使用以下代码创建一个打印机实例并连接到打印机:javascript复制代码const printer = new ESCPOSPrinter();printer.connect(printerId); // printerId是打印机的标识符或地址5. 打印操作:一旦连接到打印机,您可以使用ESCPOS类提供的API进行打印操作。
例如,您可以使用以下代码打印文本和图片:javascript复制代码const text = 'Hello, world!';const imagePath = 'path/to/image.png';printer.printText(text);printer.printImage(imagePath);6. 断开连接:完成打印操作后,您应该断开与打印机的连接。