简体   繁体   中英

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 . The PC is running MS Visual Studio.

I have created a new Project -> Other Languages -> Visual C# -> Smart Device -> Windows Mobile 6 Professional project.

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.

When I try to add a reference for the ZebraUsb.dll , I get the error message :

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

If I build the code without the reference for this dll, the build is successful. But at runtime, an exception is raised on the line where the Open() method is invoked. 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. On the PC, the port for the printer is 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 .

Can you help me? Best regards.

For all USB printers on Windows PC you normally have to add the printers USB driver first. This driver can be a USB Serial one or something special. Such drivers do not exist for Windows Mobile.

The Zebra GK420t is a desktop barcode label printer and not designed to be used from 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). 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. These may match your needs more than the GK420t.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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