通过 USB 将原始 ZPL 发送到 Zebra 打印机
通常,当我将 Zebra LP 2844-Z 插入 USB 端口时,计算机会将其视为打印机,并且我可以像任何其他通用打印机一样从记事本进行打印。但是,我的应用程序具有一些条形码功能。我的应用程序解析一些输入并生成内存中的 ZPL 字符串。我如何将此 ZPL 数据发送到我的 USB 设备?
Typically, when I plug in my Zebra LP 2844-Z to the USB port, the computer sees it as a printer and I can print to it from notepad like any other generic printer. However, my application has some bar code features. My application parses some input and generates an in-memory string of ZPL. How would I send this ZPL data to my USB device?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
我找到了答案......或者至少是最简单的答案(如果有多个)。当我安装打印机时,我将其重命名为“ICS 标签打印机”。以下是如何更改选项以允许传递 ZPL 命令:
在我的代码中,我只需将“${”添加到 ZPL 的开头,将“}$”添加到末尾并将其打印为纯文本。这是与“ZDesigner LP 2844-Z 打印机版本 2.6.42(Build 2382)的 Windows 驱动程序”一起使用的。效果就像一个魅力!
I found the answer... or at least, the easiest answer (if there are multiple). When I installed the printer, I renamed it to "ICS Label Printer". Here's how to change the options to allow pass-through ZPL commands:
In my code, I just have to add "${" to the beginning of my ZPL and "}$" to the end and print it as plain text. This is with the "Windows driver for ZDesigner LP 2844-Z printer Version 2.6.42 (Build 2382)". Works like a charm!
我发现了一种通过 COM 端口向 Zebra 打印机写入数据的更简单方法。我转到 Windows 控制面板并添加了一台新打印机。对于端口,我选择 COM1(打印机插入的端口)。我使用了“通用/纯文本”打印机驱动程序。我禁用了后台打印程序(打印机首选项中的标准选项)以及所有高级打印选项。现在,我可以将任何字符串打印到该打印机,如果该字符串包含 ZPL,则打印机可以很好地呈现 ZPL!不需要特殊的“开始序列”或类似的时髦东西。为简单而欢呼!
I've found yet an easier way to write to a Zebra printer over a COM port. I went to the Windows control panel and added a new printer. For the port, I chose COM1 (the port the printer was plugged in to). I used a "Generic / Text Only" printer driver. I disabled the print spooler (a standard option in the printer preferences) as well as all advanced printing options. Now, I can just print any string to that printer and if the string contains ZPL, the printer renders the ZPL just fine! No need for special "start sequences" or funky stuff like that. Yay for simplicity!
Visual Studio C# 解决方案(位于 http://support.microsoft.com/kb /322091)
步骤 1.) 创建类 RawPrinterHelper...
步骤 2.) 创建一个包含文本框和按钮的表单(文本框将保存 ZPL在此示例中发送)。在按钮单击事件中添加代码...
使用此解决方案,您可以进行调整以满足特定要求。也许对特定打印机进行硬编码。也许可以动态地而不是从文本框导出 ZPL 文本。任何。也许您不需要图形界面,但这显示了如何发送 ZPL。您的使用取决于您的需求。
Visual Studio C# solution (found at http://support.microsoft.com/kb/322091)
Step 1.) Create class RawPrinterHelper...
Step 2.) Create a form with text box and button (text box will hold the ZPL to send in this example). In button click event add code...
With this solution, you can tweak to meet specific requirements. Perhaps hardcode the specific printer. Perhaps derive the ZPL text dynamically rather than from a text box. Whatever. Perhaps you don't need a graphical interface, but this shows how to send the ZPL. Your use depends on your needs.
您还没有提到一种语言,所以我将为您提供一些如何使用 C 语言中的直接 Windows API 来完成此操作的提示。
首先,使用
OpenPrinter
。接下来,使用StartDocPrinter
具有的
结构设置为pDatatype
字段DOC_INFO_1“RAW”
- 这告诉打印机驱动程序不要对发送到打印机的任何内容进行编码,而是将其原封不动地传递。使用StartPagePrinter
表示第一页,WritePrinter
将数据发送到打印机,使用EndPagePrinter
、EndDocPrinter
关闭code> 和ClosePrinter
完成后。You haven't mentioned a language, so I'm going to give you some some hints how to do it with the straight Windows API in C.
First, open a connection to the printer with
OpenPrinter
. Next, start a document withStartDocPrinter
having thepDatatype
field of theDOC_INFO_1
structure set to"RAW"
- this tells the printer driver not to encode anything going to the printer, but to pass it along unchanged. UseStartPagePrinter
to indicate the first page,WritePrinter
to send the data to the printer, and close it withEndPagePrinter
,EndDocPrinter
andClosePrinter
when done.ZPL 是正确的方法。在大多数情况下,使用抽象为 GDI 命令的驱动程序是正确的;然而,Zebra 标签打印机是一个特例。使用 Zebra 打印机进行打印的最佳方法是直接生成 ZPL。请注意,Zebra 打印机的实际打印机驱动程序是“纯文本”打印机 - 不存在可以更新或更改的“驱动程序”,就像我们认为大多数打印机都有驱动程序一样。它只是绝对简约意义上的驱动程序。
ZPL is the correct way to go. In most cases it is correct to use a driver that abstracts to GDI commands; however Zebra label printers are a special case. The best way to print to a Zebra printer is to generate ZPL directly. Note that the actual printer driver for a Zebra printer is a "plain text" printer - there is not a "driver" that could be updated or changed in the sense we think of most printers having drivers. It's just a driver in the absolute minimalist sense.
安装共享打印机:\localhost\zebra
以文本形式发送 ZPL,首先尝试复制:
复制 file.zpl \localhost\zebra
非常简单,几乎不需要编码。
Install an share your printer: \localhost\zebra
Send ZPL as text, try with copy first:
copy file.zpl \localhost\zebra
very simple, almost no coding.
对于 2021 年因上述问题折磨自己的人来说,如果您身处 .NET 世界,那么请使用 RawPrint< /a> NuGet 包。
从那里绕过驱动程序直接将 ZPL 字符串打印到打印机,它是:
For anybody torturing themselves with the above in 2021, if you're in the .NET world then get hold of the RawPrint NuGet package.
From there to print your ZPL string directly to the printer, bypassing drivers, it's:
找到了惊人的简单解决方案 - 适用于 Chrome(Windows,未在 Mac 上测试)
Zebra ZP 450
Found amazing simple solution - working for Chrome (Windows, not tested on Mac)
Zebra ZP 450
我花了8个小时才做到这一点。
很简单...
您应该有这样的代码:
将该变量内容从 3(打开的文件已存在)更改为 1(创建一个新文件)。
它适用于 Windows 7 和 XP。
I spent 8 hours to do that.
It is simple...
You shoud have a code like that:
Change that variable content from 3 (open file already exist) to 1 (create a new file).
It'll work at Windows 7 and XP.