Exemple #1
0
        /* Returns the connection to the zebra printer after finding it through the Usb Discoverer */
        public static Connection FindConnection()
        {
            Debug.WriteLine("START: FindConnection()");
            //Finds all the USB connected Zebra printer drivers
            List <DiscoveredPrinterDriver> discoveredPrinterDrivers = UsbDiscoverer.GetZebraDriverPrinters();

            if (discoveredPrinterDrivers == null)
            {
                Debug.WriteLine("Error: No USB printers detected");
                return(null);
            }

            if (discoveredPrinterDrivers.Count == 0)
            {
                return(null);
            }
            //Gets the instance to the Zebra Printer driver
            DiscoveredPrinterDriver printerDriver = discoveredPrinterDrivers[0];

            Debug.WriteLine(printerDriver);

            Debug.WriteLine("END: FindConnection()");
            //Get the connection to the printer driver
            return(printerDriver.GetConnection());
        }
Exemple #2
0
        public override ConnectionA GetConnection()
        {
            DiscoveredPrinterDriver        driverPrinter = null;
            List <DiscoveredPrinterDriver> printers      = UsbDiscoverer.GetZebraDriverPrinters();

            if (printers == null || printers.Count <= 0)
            {
                //MessageBox.Show("没有检测到打印机,请检查打印机是否开启!");
                myEventLog.LogInfo("没有检测到打印机,请检查打印机是否开启!");
                return(null);
            }
            driverPrinter = printers[0];

            var connection = new DriverPrinterConnection(driverPrinter.Address);

            connection.Open();
            try
            {
                ZebraPrinterFactory.GetInstance(connection);
            }
            catch (Exception ex)
            {
            }
            try
            {
                ZebraPrinterFactory.GetLinkOsPrinter(connection);
            }
            catch (Exception ex)
            {
            }



            return(connection);
        }