c# - 无法通过 PrintServer 将原始 ZPL 发送到 Zebra 打印机

标签 c# printing zebra-printers zpl printqueue

问题

我正在尝试将 zpl RAW 发送到打印服务器。有一台 Zebra ZM400 打印机。 我可以获得 PrintServer、PrintQueue 对象。此外,我可以添加一个作业,并写入其 JobStream。

我检查了打印队列(在 Windows 上),文档已发送。打印机数据指示灯闪烁 0/2 秒。

进展

这是我打印到打印服务器的代码:

PrintServer ps = new PrintServer(@"\\192.168.1.1");
PrintQueue pq = ps.GetPrintQueue("Printer 01");

Byte[] myByteBuffer = Encoding.ASCII.GetBytes(
    @"^XA^MMP^PW300^LS0^LT0^FT10,60^APN,30,30^FH\^FDSAMPLE TEXT^FS^XZ");

PrintSystemJobInfo psji = pq.AddJob();
psji.JobStream.Write(myByteBuffer, 0, myByteBuffer.Length);
psji.JobStream.Flush();
psji.JobStream.Close();

问题

当我检查打印队列(在 Windows 上)时,文档有 0 个字节。然后,打印机什么也不打印。

我是否遗漏了一些特殊字符?或者,我是否发送了错误的原始数据?

最佳答案

在我的应用程序中,我使用了以下运行良好的代码:

ZPLString = @"^XA^MMP^PW300^LS0^LT0^FT10,60^APN,30,30^FH\^FDSAMPLE TEXT^FS^XZ";
// Open connection
System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient();
client.Connect("10.10.5.85", 9100);

// Write ZPL String to connection
System.IO.StreamWriter writer = new System.IO.StreamWriter(client.GetStream());
writer.Write(ZPLString);
writer.Flush();

// Close Connection
writer.Close();
client.Close();

编辑:*端口 6101 是 Zebra 打印机的默认端口,9100 是备用端口

关于c# - 无法通过 PrintServer 将原始 ZPL 发送到 Zebra 打印机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42415748/

相关文章:

c# - C# 中的全局变量

c# - StreamSocket下DataWriter的StoreAsync是如何工作的?

java - JTextArea 打印对话框

java - 使用 Android 在 Android MZ320 中使用 cpcl 将图像和文本打印到收据

c# - 你能写 Javascript object init shorthand C# style 吗?

c# - 如何在 C# 中确定多播数据包的源 IP?

iphone - 从 IOS 截取并打印屏幕截图

css - @media print 中可以使用@page 规则吗?

android - 如何阻止 Zebra 打印机 RW 420 在从 Printer.getGraphics Util 发出打印图像命令时自动送入大量额外纸张?

bmp - 使用 ZPL 打印 BMP