Wes*_*ley 3 c# bluetooth zebra-printers
我必须通过蓝牙将字体文件发送到我的打印机 Zebra RW420。我使用 Zebra Windows Mobile SDK,但找不到任何方法将其发送并存储在打印机上。我可以通过 Label Vista 手动完成,但必须在 200 多台打印机上完成。
有人有任何建议或知道我可以使用 SDK 中的什么方法吗?
提前致谢。
CISDF 是正确的答案,可能是您计算的校验和值不正确。我在连接到 USB 端口的 RW420 上放置了一个端口嗅探器,发现它可以工作。实际上,我将一些 PCX 图像发送到打印机,然后在标签中使用它们。
! CISDF
<filename>
<size>
<cksum>
<data>
Run Code Online (Sandbox Code Playgroud)
第 4 行末尾有一个 CRLF。使用 0000 作为校验和会导致打印机忽略任何校验和验证(我在一些 ZPL 手册中发现了一些对此非常晦涩的引用,尝试了一下并且成功了)。<文件名> 是文件的 8.3 名称,因为它将存储在打印机上的文件系统中,<大小> 是文件的大小,长度为 8 个字符,格式为十六进制数字。<cksum> 是作为校验和的数据字节之和的二进制补码。<data> 当然是要存储在打印机上的文件内容。
下面是我用来将示例图像发送到打印机的实际 C# 代码:
// calculate the checksum for the file
// get the sum of all the bytes in the data stream
UInt16 sum = 0;
for (int i = 0; i < Properties.Resources.cmlogo.Length; i++)
{
sum += Convert.ToUInt16(Properties.Resources.cmlogo[ i]);
}
// compute the two's complement of the checksum
sum = (Uint16)~sum;
sum += 1;
// create a new printer
MP2Bluetooth bt = new MP2Bluetooth();
// connect to the printer
bt.ConnectPrinter("<MAC ADDRESS>", "<PIN>");
// write the header and data to the printer
bt.Write("! CISDF\r\n");
bt.Write("cmlogo.pcx\r\n");
bt.Write(String.Format("{0:X8}\r\n", Properties.Resources.cmlogo.Length));
bt.Write(String.Format("{0:X4}\r\n", sum)); // checksum, 0000 => ignore checksum
bt.Write(Properties.Resources.cmlogo);
// gracefully close our connection and disconnect
bt.Close();
bt.DisconnectPrinter();
Run Code Online (Sandbox Code Playgroud)
MP2Bluetooth 是我们在内部使用的一个类,用于抽象 BT 连接和通信 - 我相信您也有自己的类!