C使用ESC指令控制POS机打印小票.doc

上传人:罗晋 文档编号:9013831 上传时间:2021-01-30 格式:DOC 页数:8 大小:40KB
返回 下载 相关 举报
C使用ESC指令控制POS机打印小票.doc_第1页
第1页 / 共8页
C使用ESC指令控制POS机打印小票.doc_第2页
第2页 / 共8页
C使用ESC指令控制POS机打印小票.doc_第3页
第3页 / 共8页
C使用ESC指令控制POS机打印小票.doc_第4页
第4页 / 共8页
C使用ESC指令控制POS机打印小票.doc_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《C使用ESC指令控制POS机打印小票.doc》由会员分享,可在线阅读,更多相关《C使用ESC指令控制POS机打印小票.doc(8页珍藏版)》请在三一文库上搜索。

1、C#使用ESC指令控制POS打印机打印小票 1.前言C#打印小票可以与普通打印机一样,调用PrintDocument实现。也可以发送标注你的ESC指令实现。由于 调用PrintDocument类时,无法操作使用串口或TCP/IP接口连接的pos打印机,并且无法发送控制指令实现pos打印机的切纸、走纸等动作。因此个人建议使用ESC指令进行打印会更通用。本类需要调用 机打印小票ReceiptHelperusing System;using ;using ;using ;using ;using ;using ;using ;using #region 结构体定义 StructLayout publ

2、ic 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; . .设置打印参数意:打印该行内容后会自动换行(本类会在该行内容末尾添加一个换行符).直到获取到最右侧一列的点 果当前像素是黑点,需要把数组里的对应比特位设置为1 if (briary

3、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 Sys

4、tem;using ;using ;using ;using ;using ; using 过此亮度认为白点,否则认为黑点 rue表示亮度不同,false表示亮度相同 过此亮度认为白点,否则认为黑点 相同,0不同 = new Booleanwidth * height; 相同,0不同 diffary = new Booleanwidth * height; Int32 pixidx = 0;果是黑色,表示相同,白色,表示不同 diffarypixidx = (pixbri briDiff); +pixidx; cmpretpix += 3; cmpretpix += rowredundancy

5、; (datadiff); bl = true; catch (Exception ex) (CompareImage error: + ; bl = false; return bl; 相同,0不同 = new Booleanwidth * height; rue不同,false相同 何一个不同,就认为失败 if = & difftype != return false; 有像素都相同,认为失败 if = & difftype = return false; return true; / / 检查指定区域的图像是否与方案里的指定值一样(都是相同或者不同) / / / / public sta

6、tic Boolean ValidateImageArea(Byte briDiffary, ImageAreaInfo area, Int32 width, Int32 height) Boolean blary = new Boolean; for (Int32 idx = 0; idx 0); Boolean bl = ValidateImageArea(blary, area, width, height); return bl; / / 检查图片的比较结果里,某个区域是否与期待的一致 / / / / true-与期待一致;false-不一致 public static Boolean

7、 ValidateImageArea(ImageCompareResult compareret, ImageAreaInfo area) Boolean pixDiffary = ; Bitmap tmp = new Bitmap; Int32 width = ; Int32 height = ; Boolean bl = ValidateImageArea, area, width, height); return bl; / / 获取1个 比较结果里,指定的区域范围,是全都相同,还是不同 / 只有所有像素都是相同,才认为是整个区域相同 / 如果有1个像素不同,则认为整个区域不同 / /

8、/ / / / / / / 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 | area

9、height 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 (pixDiffarycurrowFirstPix +

10、x) /当前像素点不同 allisdiff = true; else/当前像素相同 allissame = true; /如果已经有部分相同部分不同,退出 if (allisdiff & allissame) difftype = ; return true; /现在,所有像素都相同,或都不同 if (allisdiff) difftype = ; else difftype = ; return true; / / 根据亮度容差,把图片转换为非黑即白的图片 / / / / public static Boolean GetBlackWhiteImage(Bitmap briimg, Byte

11、 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;

12、 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 = (byte*) for (int y = 0; y height;

13、 y+) for (int x = 0; x brigate) ? Const_BrightnessWhite : Const_BrightnessBlack; pixret0 = curpixBri;/把亮度值设置到结果图像里 pixret1 = curpixBri; pixret2 = curpixBri; +pixidx; pixret += 3; pixret += rowredundancy; (datasrc); (dataret); catch (Exception ex) (GetBlackWhiteImage error: + ; return false; return true; #endregion #region 内部实现 / / 比较2个数值之间的差是否大于指定值 / / / / / 超过指定值返回true;否则返回false private static Boolean CheckDiffOver(Int32 val1, Int32 val2, Int32 diff) if (diff val2 & val1 val2 + diff) return true; if (val2 val1 & val2 val1 + diff) return true; return false; #endregion

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 科普知识


经营许可证编号:宁ICP备18001539号-1