/**
         * When a ZebraPrinterConnection has been established, this method
         * gets the printer and gathers information from the printer such as
         * the printer language and prints to the printer
         * **/

        private void threadedConnect(String addressName)
        {
            try
            {
                /**
                 * Open the connection
                 * **/
                connection.Open();
                Thread.Sleep(1000);
            }
            catch (ZebraPrinterConnectionException)
            {
                updateGuiFromWorkerThread("Unable to connect with printer", Color.Red);
                disconnect();
            }
            catch (Exception)
            {
                updateGuiFromWorkerThread("Error communicating with printer", Color.Red);
                disconnect();
            }

            printer = null;
            if (connection != null && connection.IsConnected())
            {
                /**
                 * Get the printer instance and the printer language, then print image
                 * **/
                try
                {
                    updateGuiFromWorkerThread("Getting printer...", Color.Goldenrod);
                    Thread.Sleep(1000);
                    printer = ZebraPrinterFactory.GetInstance(connection);
                    updateGuiFromWorkerThread("Got Printer, getting Language...", Color.LemonChiffon);
                    Thread.Sleep(1000);
                    PrinterLanguage pl = printer.GetPrinterControlLanguage();
                    updateGuiFromWorkerThread("Printer Language " + pl.ToString(), Color.LemonChiffon);
                    Thread.Sleep(1000);
                    updateGuiFromWorkerThread("Formatting Image", Color.AliceBlue);
                    printer.GetGraphicsUtil().PrintImage(image, 0, 0, 550, 412, false);
                    updateGuiFromWorkerThread("Printing To " + addressName, Color.Green);
                    Thread.Sleep(2000);
                    disconnect();
                }
                catch (ZebraPrinterConnectionException)
                {
                    updateGuiFromWorkerThread("Unknown Printer Language", Color.Red);
                    printer = null;
                    Thread.Sleep(1000);
                    disconnect();
                }
                catch (ZebraPrinterLanguageUnknownException)
                {
                    updateGuiFromWorkerThread("Unknown Printer Language", Color.Red);
                    printer = null;
                    Thread.Sleep(1000);
                    disconnect();
                }
            }
            updateButtonFromWorkerThread(true);
        }
Ejemplo n.º 2
0
            public void enumerateSupportedControlLanguages(IMethodResult oResult)
            {
                Logger.Write("enumerateSupportedControlLanguages call");

                if (m_printer != null)
                {
                    IReadOnlyDictionary <string, string> controlLanguage = new IReadOnlyDictionary <string, string>();

                    switch (m_printer.GetPrinterControlLanguage())
                    {
                    case PrinterLanguage.CPCL:
                        controlLanguage.Add(ZebraConstants.PRINTER_LANGUAGE_CPCL, "");
                        break;

                    case PrinterLanguage.ZPL:
                        controlLanguage.Add(ZebraConstants.PRINTER_LANGUAGE_ZPL, "");
                        controlLanguage.Add(ZebraConstants.PRINTER_LANGUAGE_CPCL, "");
                        break;
                    }

                    oResult.set(controlLanguage);
                    return;
                }

                oResult.set(ZebraConstants.PRINTER_STATUS_ERR_NOT_CONNECTED);
            }
Ejemplo n.º 3
0
        private void createFile(string filePath)
        {
            ZebraPrinter    printer     = getPrinter();
            PrinterLanguage printerLang = printer.GetPrinterControlLanguage();

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            using (FileStream fileStream = File.Open(filePath, FileMode.OpenOrCreate)) {
                if (printerLang.Equals(PrinterLanguage.ZPL))
                {
                    Byte[] zplLabel = Encoding.Default.GetBytes("^XA^FO17,16^GB379,371,8^FS^FT65,255^A0N,135,134^FDTEST^FS^XZ");
                    fileStream.Write(zplLabel, 0, zplLabel.Length);
                }
                else if (printerLang.Equals(PrinterLanguage.CPCL))
                {
                    Byte[] cpclLabel = Encoding.Default.GetBytes("! 0 200 200 406 1\r\n" + "ON-FEED IGNORE\r\n"
                                                                 + "BOX 20 20 380 380 8\r\n"
                                                                 + "T 0 6 137 177 TEST\r\n"
                                                                 + "PRINT\r\n");
                    fileStream.Write(cpclLabel, 0, cpclLabel.Length);
                }
                fileStream.Close();
            }
        }
Ejemplo n.º 4
0
        private void getListOfAllFormats()
        {
            Invoke(new ButtonEnablingEventHandler(toggleButtonEnabled), false);
            updateGuiFromWorkerThread("Retrieving Formats...", Color.Gold);
            ZebraPrinter printer = getPrinter();

            try {
                String[]        formats;
                PrinterLanguage pl = printer.GetPrinterControlLanguage();
                if (pl == PrinterLanguage.ZPL)
                {
                    formats = new String[] { "ZPL" };
                }
                else
                {
                    formats = new String[] { "FMT", "LBL" };
                }
                String[]      formatNames = printer.GetFileUtil().RetrieveFileNames(formats);
                StringBuilder sb          = new StringBuilder();
                sb.Append("Printer Format Files:\r\n");
                foreach (String formatName in formatNames)
                {
                    sb.Append("\r\n" + formatName);
                }
                updateGuiFromWorkerThread("Done Retrieving Formats...", Color.Lime);
                Thread.Sleep(500);
                Invoke(new ListBoxEventHandler(displayNames), sb.ToString());
            } catch (ZebraException) {
                updateGuiFromWorkerThread("Error Retrieving Formats", Color.Red);
            }
            Invoke(new ButtonEnablingEventHandler(toggleButtonEnabled), true);
        }
        /**
         * When a ZebraPrinterConnection has been established, this method
         * gets the printer and gathers information from the printer such as
         * the printer language.  ToolsUtil will then be used to default the printer.
         * **/

        private void threadedConnect(String addressName)
        {
            try
            {
                /**
                 * Open the connection
                 * **/
                connection.Open();
                Thread.Sleep(1000);
            }
            catch (ZebraPrinterConnectionException)
            {
                updateGuiFromWorkerThread("Unable to connect with printer", Color.Red);
                disconnect();
            }
            catch (Exception)
            {
                updateGuiFromWorkerThread("Error communicating with printer", Color.Red);
                disconnect();
            }

            printer = null;
            if (connection != null && connection.IsConnected())
            {
                /**
                 * Get the printer instance and the printer language, then do a factory default on the printer.
                 * **/
                try
                {
                    updateGuiFromWorkerThread("Getting printer...", Color.Goldenrod);
                    Thread.Sleep(1000);
                    printer = ZebraPrinterFactory.GetInstance(connection);
                    updateGuiFromWorkerThread("Got Printer, getting Language...", Color.LemonChiffon);
                    Thread.Sleep(1000);
                    PrinterLanguage pl = printer.GetPrinterControlLanguage();
                    updateGuiFromWorkerThread("Printer Language " + pl.ToString(), Color.LemonChiffon);
                    ToolsUtil printer_default = printer.GetToolsUtil();
                    printer_default.RestoreDefaults();
                    updateGuiFromWorkerThread("Restoring Defaults", Color.Aqua);
                    Thread.Sleep(1000);
                    disconnect();
                }
                catch (ZebraPrinterConnectionException)
                {
                    updateGuiFromWorkerThread("Unknown Printer Language", Color.Red);
                    printer = null;
                    Thread.Sleep(1000);
                    disconnect();
                }
                catch (ZebraPrinterLanguageUnknownException)
                {
                    updateGuiFromWorkerThread("Unknown Printer Language", Color.Red);
                    printer = null;
                    Thread.Sleep(1000);
                    disconnect();
                }
            }
        }
Ejemplo n.º 6
0
        /**
         * Common function used to open the connection depending on connection
         * type such as IP/DNS, Serial and Bluetooth(R). Sends a sample label
         * to print for checking connectivity and then close the connection.
         **/
        private void threadedConnect(String addressName)
        {
            // Open the connection
            try
            {
                connection.Open();
                Thread.Sleep(1000);
            }
            catch (ZebraPrinterConnectionException)
            {
                updateGuiFromWorkerThread("Unable to connect with printer", Color.Red);
                disconnect();
            }
            catch (Exception)
            {
                updateGuiFromWorkerThread("Error communicating with printer", Color.Red);
                disconnect();
            }

            printer = null;

            // If connection opened successfully than get the printer language and display it.
            // Also sends a sample lable to print and than close the connection.
            if (connection != null && connection.IsConnected())
            {
                try
                {
                    updateGuiFromWorkerThread("Getting printer...", Color.Goldenrod);
                    Thread.Sleep(1000);
                    printer = ZebraPrinterFactory.GetInstance(connection);
                    updateGuiFromWorkerThread("Got Printer, getting Language...", Color.LemonChiffon);
                    Thread.Sleep(1000);
                    PrinterLanguage pl = printer.GetPrinterControlLanguage();
                    updateGuiFromWorkerThread("Printer Language " + pl.ToString(), Color.LemonChiffon);
                    Thread.Sleep(1000);
                    updateGuiFromWorkerThread("Connected to " + addressName, Color.Green);
                    Thread.Sleep(1000);
                    sendLabel();
                    Thread.Sleep(1000);
                    disconnect();
                }
                catch (ZebraPrinterConnectionException)
                {
                    updateGuiFromWorkerThread("Unknown Printer Language", Color.Red);
                    printer = null;
                    Thread.Sleep(1000);
                    disconnect();
                }
                catch (ZebraPrinterLanguageUnknownException)
                {
                    updateGuiFromWorkerThread("Unknown Printer Language", Color.Red);
                    printer = null;
                    Thread.Sleep(1000);
                    disconnect();
                }
            }
        }
Ejemplo n.º 7
0
 /**
  * Once connected, automatically generates a small test command and send
  * it to the printer for printing to demonstrate that a connection exists.
  * */
 public void sendLabel()
 {
     // Get the bytes data and send it to printer.
     if (printer != null)
     {
         byte[] configLabel = getConfigLabel(printer.GetPrinterControlLanguage());
         connection.Write(configLabel);
         updateGuiFromWorkerThread("Sending Data", Color.CornflowerBlue);
         Thread.Sleep(2000);
     }
     disconnect();
 }
        private void threadedConnect(String addressName)
        {
            try
            {
                connection.Open();
                Thread.Sleep(1000);
            }
            catch (ZebraPrinterConnectionException)
            {
                updateGuiFromWorkerThread("Unable to connect with printer", Color.Red);
                disconnect();
            }
            catch (Exception)
            {
                updateGuiFromWorkerThread("Error communicating with printer", Color.Red);
                disconnect();
            }

            printer = null;
            if (connection != null && connection.IsConnected())
            {
                try
                {
                    updateGuiFromWorkerThread("Getting printer...", Color.Goldenrod);
                    Thread.Sleep(1000);
                    printer = ZebraPrinterFactory.GetInstance(connection);
                    updateGuiFromWorkerThread("Got Printer, getting Language...", Color.LemonChiffon);
                    Thread.Sleep(1000);
                    PrinterLanguage pl = printer.GetPrinterControlLanguage();
                    updateGuiFromWorkerThread("Printer Language " + pl.ToString(), Color.LemonChiffon);
                    Thread.Sleep(1000);
                    updateGuiFromWorkerThread("Connected to " + addressName, Color.Green);
                    Thread.Sleep(1000);
                    //disconnect();
                }
                catch (ZebraPrinterConnectionException)
                {
                    updateGuiFromWorkerThread("Unknown Printer Language", Color.Red);
                    printer = null;
                    Thread.Sleep(1000);
                    disconnect();
                }
                catch (ZebraPrinterLanguageUnknownException)
                {
                    updateGuiFromWorkerThread("Unknown Printer Language", Color.Red);
                    printer = null;
                    Thread.Sleep(1000);
                    disconnect();
                }
            }
            updateButtonFromWorkerThread(true);
        }
        /**
         * Handle configuring and sending a test label to the currently connected printer
         * **/
        public void sendLabel()
        {
            ZebraPrinter printer = getPrinter();

            if (printer != null)
            {
                byte[] configLabel = getConfigLabel(printer.GetPrinterControlLanguage());
                getConnection().Write(configLabel);
                updateGuiFromWorkerThread("Sending Data", Color.CornflowerBlue);
                Thread.Sleep(2000);
            }
            disconnect();
        }
        private void GetListOfFormats()
        {
            ZebraPrinterConnection connection = getConnection();
            ZebraPrinter           printer    = ZebraPrinterFactory.GetInstance(connection);

            String[] zplFormatExtensions  = new String[] { "ZPL" };
            String[] cpclFormatExtensions = new String[] { "FMT", "LBL" };
            String[] extensions           = printer.GetPrinterControlLanguage() == PrinterLanguage.ZPL ? zplFormatExtensions : cpclFormatExtensions;

            List <String> formatList = new List <String>();

            foreach (String format in printer.GetFileUtil().RetrieveFileNames(extensions))
            {
                formatList.Add(format);
            }
            Invoke(new FormatListEventHandler(DisplayNames), new object[] { formatList });
        }
Ejemplo n.º 11
0
        private void threadedConnect(String addressName)
        {
            try {
                connection.Open();
                Thread.Sleep(1000);
            } catch (ZebraPrinterConnectionException) {
                updateGuiFromWorkerThread("Unable to connect with printer", Color.Red);
                disconnect();
            } catch (ZebraGeneralException e) {
                updateGuiFromWorkerThread(e.Message, Color.Red);
                disconnect();
            } catch (Exception) {
                updateGuiFromWorkerThread("Error communicating with printer", Color.Red);
                disconnect();
            }

            printer = null;
            if (connection != null && connection.IsConnected())
            {
                try {
                    printer = ZebraPrinterFactory.GetInstance(connection);
                    PrinterLanguage pl = printer.GetPrinterControlLanguage();
                    updateGuiFromWorkerThread("Printer Language " + pl.ToString(), Color.LemonChiffon);
                    Thread.Sleep(1000);
                    updateGuiFromWorkerThread("Connected to " + addressName, Color.Green);
                    Thread.Sleep(1000);
                    this.connectionEstablished();
                } catch (ZebraPrinterConnectionException) {
                    updateGuiFromWorkerThread("Unknown Printer Language", Color.Red);
                    printer = null;
                    Thread.Sleep(1000);
                    disconnect();
                } catch (ZebraPrinterLanguageUnknownException) {
                    updateGuiFromWorkerThread("Unknown Printer Language", Color.Red);
                    printer = null;
                    Thread.Sleep(1000);
                    disconnect();
                }
            }
        }
Ejemplo n.º 12
0
        /*****************************************************************************************************
        Desc: This function is called when Retrieve button is clicked. Gets the list of label formats stored 
         * at printer and display that list on UI using combobox.
        ******************************************************************************************************/
        private void getListOfAllFormats()
        {
            //Get the instance of ZebraPrinter to obtain properties of Zebra printer
            if (zebraPrinterConnection != null)
                printer = ZebraPrinterFactory.GetInstance(zebraPrinterConnection);
            else
            {
                MessageBox.Show("Device isn't Connected.");
                return;
            }
            try
            {
                if (printer != null && isConnected)
                {
                    String[] formats;

                    /**
                     * MADE CHANGES HERE!!!!!!!****************************
                     * 
                     * **/


                    //String printerLanguage = SGD.GET("device.languages", zebraPrinterConnection);
                    PrinterLanguage lang = printer.GetPrinterControlLanguage();

                    // select the format type according to printer language
                    // if ( printerLanguage == "zpl" )
                    if(lang == PrinterLanguage.ZPL)
                    {
                        formats = new String[] { "ZPL" };
                    }
                    else
                    {
                        formats = new String[] { "FMT", "LBL" };
                    }
                    /**
                     * END CHANGES
                     * **/


                    // Retrieve the list of format files store at printer and display it in combobox
                    String[] formatNames = printer.GetFileUtil().RetrieveFileNames(formats);
                    cbFormatList.DataSource = formatNames;
                }
                else
                {
                    MessageBox.Show("Device isn't Connected.");
                    return;
                }

            }
            catch (ZebraPrinterLanguageUnknownException)
            {
                MessageBox.Show("Printer Control Language Error: \r\n Make sure that printer has supported control language.");
                return;
            }
            catch (ZebraPrinterConnectionException)
            {
                MessageBox.Show("Communication Error:\r\n Check Printer is on Or Connection has been established.\r\n");
                return;
            }
            catch (ZebraException)
            {
                MessageBox.Show("Zebra Printer Error: Can't retrieve formats stored at printer");
                return;
            }
            catch (Exception)
            {
                MessageBox.Show("Error in Retrieving Formats");
                return;
            }
            
        }
Ejemplo n.º 13
0
        /**
         * Check that macAddress is valid
         * Connect to device using BluetoothPrinterConnection class
         * **/

        private void doConnectBT()
        {
            if (connection != null)
            {
                doDisconnect();
            }
            updateButtonFromWorkerThread(false);
            if (this.macAddress == null || this.macAddress.Length != 12)
            {
                updateGuiFromWorkerThread("Invalid MAC Address", Color.Red);
                disconnect();
            }
            else
            {
                updateGuiFromWorkerThread("Connecting... Please wait...", Color.Goldenrod);
                try
                {
                    connection = new BluetoothPrinterConnection(this.macAddress);
                    connection.Open();
                    Thread.Sleep(1000);
                }
                catch (ZebraPrinterConnectionException)
                {
                    updateGuiFromWorkerThread("Unable to connect with printer", Color.Red);
                    disconnect();
                }
                catch (ZebraException)
                {
                    updateGuiFromWorkerThread("COMM Error! Disconnected", Color.Red);
                    disconnect();
                }

                catch (Exception)
                {
                    updateGuiFromWorkerThread("Error communicating with printer", Color.Red);
                    disconnect();
                }


                /**
                 * Get printer from ZebraPrinterFactory
                 * Get printer language
                 * Thread.Sleep allow statusBar updates to be seen before they change
                 * **/

                printer = null;
                if (connection != null && connection.IsConnected())
                {
                    try
                    {
                        updateGuiFromWorkerThread("Getting printer...", Color.Goldenrod);
                        Thread.Sleep(1000);

                        printer = ZebraPrinterFactory.GetInstance(connection);
                        updateGuiFromWorkerThread("Got Printer, getting Language...", Color.LemonChiffon);
                        Thread.Sleep(1000);

                        PrinterLanguage pl = printer.GetPrinterControlLanguage();
                        updateGuiFromWorkerThread("Printer Language " + pl.ToString(), Color.LemonChiffon);
                        Thread.Sleep(1000);

                        updateGuiFromWorkerThread("Connected to " + macAddress, Color.Green);
                        Thread.Sleep(1000);
                    }
                    catch (ZebraPrinterConnectionException)
                    {
                        updateGuiFromWorkerThread("Unknown Printer Language", Color.Red);
                        printer = null;
                        Thread.Sleep(1000);
                        disconnect();
                    }
                    catch (ZebraPrinterLanguageUnknownException)
                    {
                        updateGuiFromWorkerThread("Unknown Printer Language", Color.Red);
                        printer = null;
                        Thread.Sleep(1000);
                        disconnect();
                    }
                    updateButtonFromWorkerThread(true);
                }
            }
        }