Question

En général, quand je branche mon Zebra LP 2844-Z au port USB, l'ordinateur, il considère comme une imprimante et je peux imprimer à partir notepad comme toute autre imprimante générique. Cependant, mon application a des caractéristiques de codes à barres. Mon application parse une entrée et génère une chaîne en mémoire de ZPL. Comment puis-je envoyer ces données ZPL à mon périphérique USB?

Était-ce utile?

La solution 2

Je l'ai encore trouvé un moyen plus facile d'écrire sur une imprimante Zebra via un port COM. Je suis allé au panneau de configuration de Windows et a ajouté une nouvelle imprimante. Pour le port, j'ai choisi COM1 (le port de l'imprimante est branché sur). J'ai utilisé un « générique / texte » pilote d'imprimante. J'ai désactivé le spooler d'impression (une option standard dans les préférences de l'imprimante), ainsi que toutes les options d'impression avancées. Maintenant, je peux imprimer une chaîne à cette imprimante et si la chaîne contient ZPL, l'imprimante rend le ZPL très bien! Pas besoin de substance spéciale « commencer des séquences » ou funky comme ça. Yay pour la simplicité!

Autres conseils

J'ai trouvé la réponse ... ou tout au moins, la réponse la plus facile (s'il existe plusieurs). Lorsque j'ai installé l'imprimante, je retitré à « Étiquette ICS imprimante ». Voici comment modifier les options pour permettre pass-through commandes ZPL:

  1. Faites un clic droit sur le "ICS Label Printer" et choisissez "Propriétés".
  2. Dans l'onglet « Général », cliquez sur le bouton « Options d'impression ... ».
  3. Dans l'onglet « Configuration avancée », cliquez sur le bouton « Autre ».
  4. Assurez-vous qu'il ya une coche dans la case « Activer le mode Passthrough ».
  5. Assurez-vous que la "séquence de démarrage:". Est "$ {"
  6. Assurez-vous que la "séquence de fin:". Est "} $"
  7. Cliquez sur le bouton "Fermer".
  8. Cliquez sur le bouton "OK".
  9. Cliquez sur le bouton "OK".

Dans mon code, je dois juste ajouter « $ { » au début de mon ZPL et « } $ » à la fin et l'imprimer sous forme de texte. Ceci est le "pilote Windows pour imprimante ZDesigner LP 2844-Z Version 2.6.42 (Const 2382)". Fonctionne comme un charme!

Solution Visual Studio C # (trouvé à http://support.microsoft. com / kb / 322091 )

Étape 1.) Créer une classe RawPrinterHelper ...

using System;
using System.IO;
using System.Runtime.InteropServices;

public class RawPrinterHelper
{
    // Structure and API declarions:
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public class DOCINFOA
    {
        [MarshalAs(UnmanagedType.LPStr)]
        public string pDocName;
        [MarshalAs(UnmanagedType.LPStr)]
        public string pOutputFile;
        [MarshalAs(UnmanagedType.LPStr)]
        public string pDataType;
    }
    [DllImport("winspool.Drv", EntryPoint = "OpenPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern bool OpenPrinter([MarshalAs(UnmanagedType.LPStr)] string szPrinter, out IntPtr hPrinter, IntPtr pd);

    [DllImport("winspool.Drv", EntryPoint = "ClosePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern bool ClosePrinter(IntPtr hPrinter);

    [DllImport("winspool.Drv", EntryPoint = "StartDocPrinterA", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern bool StartDocPrinter(IntPtr hPrinter, Int32 level, [In, MarshalAs(UnmanagedType.LPStruct)] DOCINFOA di);

    [DllImport("winspool.Drv", EntryPoint = "EndDocPrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern bool EndDocPrinter(IntPtr hPrinter);

    [DllImport("winspool.Drv", EntryPoint = "StartPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern bool StartPagePrinter(IntPtr hPrinter);

    [DllImport("winspool.Drv", EntryPoint = "EndPagePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern bool EndPagePrinter(IntPtr hPrinter);

    [DllImport("winspool.Drv", EntryPoint = "WritePrinter", SetLastError = true, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
    public static extern bool WritePrinter(IntPtr hPrinter, IntPtr pBytes, Int32 dwCount, out Int32 dwWritten);

    // SendBytesToPrinter()
    // When the function is given a printer name and an unmanaged array
    // of bytes, the function sends those bytes to the print queue.
    // Returns true on success, false on failure.
    public static bool SendBytesToPrinter(string szPrinterName, IntPtr pBytes, Int32 dwCount)
    {
        Int32 dwError = 0, dwWritten = 0;
        IntPtr hPrinter = new IntPtr(0);
        DOCINFOA di = new DOCINFOA();
        bool bSuccess = false; // Assume failure unless you specifically succeed.

        di.pDocName = "My C#.NET RAW Document";
        di.pDataType = "RAW";

        // Open the printer.
        if (OpenPrinter(szPrinterName.Normalize(), out hPrinter, IntPtr.Zero))
        {
            // Start a document.
            if (StartDocPrinter(hPrinter, 1, di))
            {
                // Start a page.
                if (StartPagePrinter(hPrinter))
                {
                    // Write your bytes.
                    bSuccess = WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
                    EndPagePrinter(hPrinter);
                }
                EndDocPrinter(hPrinter);
            }
            ClosePrinter(hPrinter);
        }
        // If you did not succeed, GetLastError may give more information
        // about why not.
        if (bSuccess == false)
        {
            dwError = Marshal.GetLastWin32Error();
        }
        return bSuccess;
    }

    public static bool SendFileToPrinter(string szPrinterName, string szFileName)
    {
        // Open the file.
        FileStream fs = new FileStream(szFileName, FileMode.Open);
        // Create a BinaryReader on the file.
        BinaryReader br = new BinaryReader(fs);
        // Dim an array of bytes big enough to hold the file's contents.
        Byte[] bytes = new Byte[fs.Length];
        bool bSuccess = false;
        // Your unmanaged pointer.
        IntPtr pUnmanagedBytes = new IntPtr(0);
        int nLength;

        nLength = Convert.ToInt32(fs.Length);
        // Read the contents of the file into the array.
        bytes = br.ReadBytes(nLength);
        // Allocate some unmanaged memory for those bytes.
        pUnmanagedBytes = Marshal.AllocCoTaskMem(nLength);
        // Copy the managed byte array into the unmanaged array.
        Marshal.Copy(bytes, 0, pUnmanagedBytes, nLength);
        // Send the unmanaged bytes to the printer.
        bSuccess = SendBytesToPrinter(szPrinterName, pUnmanagedBytes, nLength);
        // Free the unmanaged memory that you allocated earlier.
        Marshal.FreeCoTaskMem(pUnmanagedBytes);
        return bSuccess;
    }
    public static bool SendStringToPrinter(string szPrinterName, string szString)
    {
        IntPtr pBytes;
        Int32 dwCount;
        // How many characters are in the string?
        dwCount = szString.Length;
        // Assume that the printer is expecting ANSI text, and then convert
        // the string to ANSI text.
        pBytes = Marshal.StringToCoTaskMemAnsi(szString);
        // Send the converted ANSI string to the printer.
        SendBytesToPrinter(szPrinterName, pBytes, dwCount);
        Marshal.FreeCoTaskMem(pBytes);
        return true;
    }
}

Étape 2.) Créer un formulaire avec zone de texte et le bouton (zone de texte contiendra le ZPL à envoyer dans cet exemple). En cliquage Code événement add ...

private void button1_Click(object sender, EventArgs e)
        {
            // Allow the user to select a printer.
            PrintDialog pd = new PrintDialog();
            pd.PrinterSettings = new PrinterSettings();
            if (DialogResult.OK == pd.ShowDialog(this))
            {
                // Send a printer-specific to the printer.
                RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, textBox1.Text);
                MessageBox.Show("Data sent to printer.");
            }
            else
            {
                MessageBox.Show("Data not sent to printer.");
            }
        }

Avec cette solution, vous pouvez modifier pour répondre aux besoins spécifiques. Peut-être hardcode l'imprimante spécifique. Peut-être tirer le texte ZPL dynamiquement plutôt que d'une zone de texte. Peu importe. Peut-être que vous n'avez pas besoin d'une interface graphique, mais cela montre comment envoyer les ZPL. Votre utilisation dépend de vos besoins.

Vous n'avez pas mentionné une langue, donc je vais vous donner quelques quelques conseils comment faire avec l'API Windows directement dans C.

Tout d'abord, ouvrez une connexion à l'imprimante avec OpenPrinter . Ensuite, commencer un document StartDocPrinter ayant le champ pDatatype du la structure DOC_INFO_1 ensemble à "RAW" - cela indique le pilote d'imprimante ne pas quoi que ce soit encode à l'imprimante, mais de le transmettre sans changement. Utilisez StartPagePrinter pour indiquer la première page, WritePrinter pour envoyer les données à l'imprimante, et à proximité avec EndPagePrinter, EndDocPrinter et ClosePrinter lorsque vous avez terminé.

ZPL est la bonne façon d'aller. Dans la plupart des cas, il est correct d'utiliser un pilote résumés aux commandes GDI; mais les imprimantes d'étiquettes Zebra sont un cas particulier. La meilleure façon d'imprimer sur une imprimante Zebra est de générer ZPL directement. Notez que le pilote d'imprimante réelle pour une imprimante Zebra est une imprimante « texte brut » - il n'y a pas un « pilote » qui pourrait être mis à jour ou modifié en ce sens, nous pensons à la plupart des imprimantes ayant des pilotes. Il est juste un conducteur au sens minimaliste absolu.

J'ai passé 8 heures pour le faire. Il est simple ...

Vous shoud ont un code comme ça:

private const int GENERIC_WRITE = 0x40000000;

//private const int OPEN_EXISTING = 3;
private const int OPEN_EXISTING = 1;
private const int FILE_SHARE_WRITE = 0x2;
private StreamWriter _fileWriter;
private FileStream _outFile;
private int _hPort;

Changement que le contenu de la variable 3 (fichier ouvert existent déjà) à 1 (créer un nouveau fichier). Il va travailler à Windows 7 et XP.

Installer une part imprimante: \ localhost \ Zebra Envoyer ZPL sous forme de texte, essayez avec copie d'abord:

copie file.zpl \ localhost \ zebra

très simple, presque pas de codage.

Vous pouvez utiliser COM ou P / Invoke de .Net, pour ouvrir le pilote Winspool.drv et envoyer octets directement aux périphériques. Mais vous ne voulez pas le faire; cela fonctionne généralement que pour le seul appareil sur une version du pilote que vous testez un avec, et les pauses sur tout le reste. Prenez ce depuis longtemps, douloureuse, expérience personnelle.

Qu'est-ce que vous voulez faire est d'obtenir une police de code à barres ou d'une bibliothèque qui attire des codes à barres en utilisant GDI ancien ou des commandes GDI + plaine; il y a un pour .Net . Cela fonctionne sur tous les appareils, même après Zebra change le conducteur.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top