将原始数据发送到 Zebra TTP 2030 打印机并获取其状态

发布于 2024-09-03 17:47:49 字数 2426 浏览 2 评论 0原文

我正在使用 .net c# Web 应用程序,需要在斑马打印机 (TTP2030) 上打印文本和条形码。使用 此处的 RawPrinterHelper。我几乎得到了打印机的命令,作为 unicode 字符串。

因此,要打印条形码,我会这样做:

string enq = Convert.ToChar(5).ToString();
string esc = Convert.ToChar(27).ToString();
string nul = Convert.ToChar(0).ToString();
string rs = Convert.ToChar(30).ToString();
string lf = Convert.ToChar(10).ToString();
string cr = Convert.ToChar(13).ToString();

StringBuilder sb = new StringBuilder();

sb.Append(esc + "BS" + nul + nul + Convert.ToChar(72).ToString() + nul + nul);
sb.Append(nul + nul + Convert.ToChar(64).ToString() + nul + Convert.ToChar(2).ToString() + Convert.ToChar(2).ToString());
sb.Append(esc + "BW" + nul + "733104000099" + nul);
sb.Append(lf + rs);

RawPrinterHelper.SendStringToPrinter(printerName, sb.ToString());

该命令的助记符是

< ESC>BS<0><0>< h 48><0><0>
<00><0>< h 40><0><2><2>
< ESC>BW<00>733104000099<00>
< LF>< RS>

我不知道的是我是否正确发送了诸如 << 的内容。 h 48>。根据手册,前导 h 后跟一个空格表示十六进制值。在这种情况下,该值表示条形码的 X 坐标(低位字节 - 我不知道这是什么)。

如果此值以像素(或毫米)为单位,如何转换为十六进制,然后转换为要发送到打印机的 unicode?

另外,如何转换我的十进制值必须发送吗?

例如,为了打印标尺线,我发送:

< ESC>r<0><0><0><0><1><230><0><24><3>

都是十进制值,表示位置,启动、停止等。

如何转换此命令以便可以发送到打印机

我无法开始工作的另一件事是从打印机获取数据。有几个可用的命令,例如获取纸张状态、序列号、固件等。为了尝试实现此目的,我首先

[DllImport("winspool.drv", CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern int ReadPrinter(IntPtr hPrinter, StringBuilder data, int buf, out int pcRead);

RawPrinterHelper 类中添加了这些命令。然后我尝试使用 SendFileToPrinter 和一个 .prn 文件发送命令,该文件是从斑马获得的一个名为 kiosk Printer toolbox 的小应用程序中保存的网站

(我选择发送文件而不是上面描述的 SendStringToPrinter 方法,因为我不相信我在那里做了正确的事情,而且我还测试了将命令文件发送到打印机有几个不同的命令并且它可以工作)。

然后调用 ReadPrinter(hPrinter, sb, 6, out dwWritten); 但 sb 为空。该方法返回 0。有人知道如何从打印机读取数据吗? 我应该考虑采用完全不同的方法来打印(文本和条形码)并获取打印机状态吗?

I'm woking on a .net c# web app where I need to print on a zebra printer (TTP2030) text and barcodes. Using the RawPrinterHelper class from here. I pretty much got the commands to the printer, as a unicode string.

So, to print a barcode I do:

string enq = Convert.ToChar(5).ToString();
string esc = Convert.ToChar(27).ToString();
string nul = Convert.ToChar(0).ToString();
string rs = Convert.ToChar(30).ToString();
string lf = Convert.ToChar(10).ToString();
string cr = Convert.ToChar(13).ToString();

StringBuilder sb = new StringBuilder();

sb.Append(esc + "BS" + nul + nul + Convert.ToChar(72).ToString() + nul + nul);
sb.Append(nul + nul + Convert.ToChar(64).ToString() + nul + Convert.ToChar(2).ToString() + Convert.ToChar(2).ToString());
sb.Append(esc + "BW" + nul + "733104000099" + nul);
sb.Append(lf + rs);

RawPrinterHelper.SendStringToPrinter(printerName, sb.ToString());

The mnemonic for that command is

< ESC>BS<0><0>< h 48><0><0>
<00><0>< h 40><0><2><2>
< ESC>BW<00>733104000099<00>
< LF>< RS>

What I don't know is if I'm sending correctly things like < h 48>. From the manual, a leading h followed by a space indicates a hex value. In this case that value represents the X coordinate (the low order byte - I don't know what this is) of the barcode.

If this value is in pixels (or mm), how do I convert to hex and then to the unicode I'm sending to the printer?

Also, how do I convert the decimal values I have to send?

For example for printing a ruler line I send:

< ESC>r<0><0><0><0><1><230><0><24><3>

All are decimal values, meaning position, start, stop etc.

How do I convert this command so I can send to the printer?

Another thing I cannot get to work is getting data from the printer. There are several commands available, like getting the paper status, the serial number, firmware etc. To try to achieve this first I added

[DllImport("winspool.drv", CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern int ReadPrinter(IntPtr hPrinter, StringBuilder data, int buf, out int pcRead);

in the RawPrinterHelper class. Then I tried to send the command using SendFileToPrinter and a .prn file I saved from a small app called kiosk printer toolbox I got from the zebra website

(I chose to send a file instead of the SendStringToPrinter approach I described above because, well, I don't trust I'm doing the right thing there, and also I tested sending a commands file to the printer with several different commands and it worked).

Then called ReadPrinter(hPrinter, sb, 6, out dwWritten); but sb is empty. The method returns 0. Does anyone know how I can read data from the printer? Is there a totally different approach I should be considering for printing (text and barcodes) and getting the printer status?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空气里的味道 2024-09-10 17:47:49

java中有一个特定的函数可以做到这一点。我会去看看 QZ-Print。您只能打印到在您的网络应用程序家用计算机上本地运行的打印机,其他人也无法打印。我会去检查一下那个小程序,看看你想要做什么。 IT 是专门为斑马打印机编写的。

There is a specific function in java that does this. I'd go check out QZ-Print. You'll only be able to print to a printer that is running locally on your web apps home machine, no one else will be able too. I'd go check that applet out for what you are wanting to do. IT was specifically written for zebra printers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文