我通过NuGet安装了Zebra.Printer.SDK,并包含了using Zebra.Sdk.Comm;和using Zebra.Sdk.Printer;。我正在尝试通过USB连接到打印机。在该示例中,它们执行以下操作:
} else {
printerConnection = new UsbConnection(selectedItem.Address);
}我在我的应用程序中尝试了相同的方法。但是我找不到UsbConnection类。我需要添加额外的依赖项吗?
包含示例的SDK Installation
发布于 2020-05-27 01:46:37
如果正确安装了Nuget库,则应该具有运行应用程序所需的库依赖项。对于usb通信,您需要允许接口通信的usb dll。请从该Link下载多平台开发工具包,它有一个名为PC -.NET的文件夹,单击它,然后转到“C:\Program Files\Zebra Technologies\link_os_sdk\PC-.NET\v2.15.2634\demos-desktop\Source”,”它有一个完整的Visual Studio项目,您可以立即安装和运行。这个示例代码包含了您需要的所有内容,包括用于usb通信的dll。
有关USB类API文档,请访问以下链接。
Zebra.Sdk.Comm命名空间
https://techdocs.zebra.com/link-os/2-14/pc_net/content/html/85823b27-9fa5-7681-c212-8e536f601bbe.htm
UsbConnection类
https://techdocs.zebra.com/link-os/2-14/pc_net/content/html/ab837158-704b-90f5-f754-c05091f89421.htm
公共UsbConnection(string symbolicName)
参数
symbolicName类型: System.String
由UsbDiscoverer.GetZebraUsbPrinters()成员函数返回的设备的USB符号名称。
\?\usb#vid_0a5f&pid_016e#zq520r#{28d78fad-5a12-11d1-ae5b-0000f803a8c2}:symbolicName示例
private void SendZplOverUsb(string symbolicName) {
// Instantiate connection for ZPL USB port at given address/symbolicName
Connection thePrinterConn = new UsbConnection(symbolicName);
try {
// Open the connection - physical connection is established here.
thePrinterConn.Open();
// This example prints "This is a ZPL test." near the top of the label.
string zplData = "^XA^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS^XZ";
// Send the data to printer as a byte array.
thePrinterConn.Write(Encoding.UTF8.GetBytes(zplData));
} catch (ConnectionException e) {
// Handle communications error here.
Console.WriteLine(e.ToString());
} finally {
// Close the connection to release resources.
thePrinterConn.Close();
}
}https://stackoverflow.com/questions/62017991
复制相似问题