RawPrinterHelper无法使用ESC POS命令打印条形码 [英] RawPrinterHelper unable to print Barcode using ESC POS Commands

查看:612
本文介绍了RawPrinterHelper无法使用ESC POS命令打印条形码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个相对简单的任务变成了数小时的挫败感,所以去了:

A relatively simple task is turning into hours of frustration so here goes:

我有各种热敏打印机,我们使用Microsoft发布的RawPrinterHelper进行打印. 通常使用字符串"构建器构建字符串并调用SendStringToPrinter,我们会得到一张打印纸.

I have various Thermal printers and we print to the using the RawPrinterHelper that Microsoft posted. Usually use a String builder build the string and call the SendStringToPrinter and we have a printed piece of paper.

我正在尝试通过支持的ESC/POS命令打印简单的条形码.我们将这些功能用于其他所有功能都可以使用的功能(剪切,更改字体大小),但条形码无法打印.

I'm trying to print a simple barcode via the ESC/POS commands that are supported. WE use these for other functions (cutting, change font sizes) that all works, the barcode refuses to print.

ESC POS命令为:GS k m n d1 d2…dn m:条形码类型 n:条形码长度-表示条形码数据字节数 d1条码

ESC POS Command is : GS k m n d1 d2 … dn m:barcode type e.g. n:barcode length -indicates the number of bar code data bytes d1 the barcode

我的问题是,如何发送条形码的长度? 我相信这是我的问题所在.

The question I have is, How do I send the length of the barcode? I believe this where my problem lies.

代码段:

StringBuilder print = new StringBuilder();
barcode = "1234567890";
char commandGS = '\x1D';
char linefeed = '\x0A';
char esc = '\x1B';
char commandFontSize = '\x21';
char commandk = '\x6B';
char code128 = '\x69';
print.Append(commandGS);
print.Append(commandk);
print.Append(code128);
print.Append(barcode.Length);
print.Append(barcode);
string printJob = print.ToString();
RawPrinterHelper.SendStringToPrinter(printerName, printJob);

推荐答案

您可能需要一个字节来表示条形码的长度,而不是文本来表示条形码的长度.

You probably need a byte to represent the length of the barcode rather than the text representation of the length of the barcode.

所以不是

print.Append(barcode.Length);

使用

print.Append((char)barcode.Length);

我认为长度不超过255.

I assume the length does not exceed 255.

编辑后添加:您可以使用类似的东西检查发送的字节

Edited to add: You can examine the bytes which you are sending with something like

var bb = Encoding.UTF8.GetBytes(printJob);
bb.ToList().ForEach(x => Console.Write(x.ToString("X2") + " "));

,并检查它们是否符合您要发送的内容.您可能还想比较在当前代码中发送给起作用的东西的消息.

and check that they conform to what you intend to send. You may also want to compare what is sent to something which does work in your current code.

这篇关于RawPrinterHelper无法使用ESC POS命令打印条形码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆