简体   繁体   English

尝试通过C#中的Zebra SDK从Windows Mobile仿真器连接到USB Zebra打印机

[英]Trying to connect to an USB Zebra printer from a Windows Mobile emulator via the Zebra SDK in C#

I have a Zebra GK420t printer plugged in via USB to a PC . 我有一台Zebra GK420t打印机通过USBPC The PC is running MS Visual Studio. PC正在运行MS Visual Studio。

I have created a new Project -> Other Languages -> Visual C# -> Smart Device -> Windows Mobile 6 Professional project. 我创建了一个新Project -> Other Languages -> Visual C# -> Smart Device -> Windows Mobile 6 Professional项目。

I have created a class: 我创建了一个类:

using System;
using System.Collections.Generic;
using System.Text;
using ZSDK_API.Comm;
using ZSDK_API.ApiException;

namespace Zebra2
{
    class CTest
    {
        static void Main(string[] args)
        {
            try
            {
                // Instantiate connection for ZPL USB port with a given port name. 
                ZebraPrinterConnection thePrinterConn = new UsbPrinterConnection("USB001:");
                // "LPT" is the default prefix for most Windows CE/Mobile USB ports 

                // 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.Default.GetBytes(zplData));

                // Close the connection to release resources.
                thePrinterConn.Close();
            }
            catch (ZebraPrinterConnectionException e)
            {
                // Handle communications error here.
                Console.Write(e.StackTrace);
            }
        }
    }
}

In Visual, I added a Reference for the ZSDK_API.dll successfully. 在Visual中,我成功为ZSDK_API.dll添加了Reference

When I try to add a reference for the ZebraUsb.dll , I get the error message : 当我尝试为ZebraUsb.dll添加引用时, 出现错误消息

A reference to 'ZebraUsb.dll' couldn't be added.

If I build the code without the reference for this dll, the build is successful. 如果我在没有此dll引用的情况下构建代码,则构建成功。 But at runtime, an exception is raised on the line where the Open() method is invoked. 但是在运行时,在调用Open()方法的行上引发了一个异常。 The error message is: 错误消息是:

An unhandled exception of type ZSDK_API.ApiException.ZebraGeneralException' occurred in ZSDK_API.dll.
Additional information: Can't find PInvoke DLL 'ZebraUsb.dll'.

Second problem: I'm not sure what argument I should give to the UsbPrinterConnection constructor. 第二个问题:我不确定应该给UsbPrinterConnection构造函数使用什么参数。 On the PC, the port for the printer is USB001 . 在PC上,打印机的端口为USB001 I'm not sure how it's being seen from the emulator. 我不确定如何从模拟器中看到它。 The printer can also be seen as a share via \\\\PC\\printer . 也可以通过\\\\PC\\printer将打印机视为共享。

Can you help me? 你能帮助我吗? Best regards. 最好的祝福。

For all USB printers on Windows PC you normally have to add the printers USB driver first. 对于Windows PC上的所有USB打印机,通常必须先添加打印机的USB驱动程序。 This driver can be a USB Serial one or something special. 该驱动程序可以是USB串行驱动程序,也可以是特殊的驱动程序。 Such drivers do not exist for Windows Mobile. Windows Mobile不存在此类驱动程序。

The Zebra GK420t is a desktop barcode label printer and not designed to be used from Windows Mobile. Zebra GK420t是台式条形码标签打印机,不适用于Windows Mobile。

You may install the printer on your Windows PC and share it over the network, either using Windows Printer Sharing or TCP/IP printer services (LPR). 您可以使用Windows打印机共享或TCP / IP打印机服务(LPR)在Windows PC上安装打印机并通过网络共享它。 Then you might write an application that sends print commands over the network to this shared connection. 然后,您可以编写一个应用程序,该应用程序通过网络将打印命令发送到此共享连接。

Zebra also offers a range of portable printers and a Windows Mobile SDK. Zebra还提供了一系列便携式打印机和Windows Mobile SDK。 These may match your needs more than the GK420t. 这些可能比GK420t更符合您的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM