Example #1
0
            private void searchUsb()
            {
                Logger.Write("Start search Usb printers");

                // process connection to Usb
                PrinterZebra.EPrinterConnectionType connType = PrinterZebra.EPrinterConnectionType.eUSB;

                if (deviceAdress != null && !PrinterManager.Instance.hasPrinter(deviceAdress))
                {
                    Logger.Write("Start search in address: " + deviceAdress);

                    ConnecttionJob job = zebraSingleton.tryToConnect(0, deviceAdress, ZebraConstants.connectionTimeout, connType);

                    if (job.Connection != null)
                    {
                        PrinterManager.Instance.addPrinterWithID(deviceAdress, 0, connType);

                        if (!isSearchStopped)
                        {
                            zebraSingleton.sendConnectResult(job.FriendlyName, deviceAdress, 0, connType, oResult);
                        }

                        job.Close();
                    }
                }
                else
                {
                    List <String> usbPrinterAddresses = new List <String>();

                    usbPrinterAddresses.Add("LPT1:");
                    usbPrinterAddresses.Add("LPT2:");

                    foreach (String printerAddress in usbPrinterAddresses)
                    {
                        if (isSearchStopped)
                        {
                            break;
                        }

                        Logger.Write("searching in address: " + printerAddress);

                        if (!PrinterManager.Instance.hasPrinter(printerAddress))
                        {
                            ConnecttionJob job = zebraSingleton.tryToConnect(0, printerAddress, ZebraConstants.connectionTimeout, connType);

                            if (job.Connection != null)
                            {
                                Logger.Write("Found printer on address: " + printerAddress);

                                PrinterManager.Instance.addPrinterWithID(printerAddress, 0, connType);

                                zebraSingleton.sendConnectResult(job.FriendlyName, printerAddress, 0, connType, oResult);

                                job.Close();
                            }
                        }
                    }
                }
            }
Example #2
0
        public PrinterZebra addPrinterWithID(string ID, Int32 port, PrinterZebra.EPrinterConnectionType type)
        {
            if (m_printersCache.ContainsKey(ID))
            {
                return(m_printersCache[ID]);
            }

            PrinterZebraImpl.PrinterZebra newPrinter = new PrinterZebraImpl.PrinterZebra();

            newPrinter.ID             = ID;
            newPrinter.Port           = port;
            newPrinter.connectionType = type;

            m_printersCache.Add(ID, newPrinter);

            return(newPrinter);
        }
Example #3
0
            public ConnecttionJob tryToConnect(Int32 port, string deviceAdress, int timeout, PrinterZebra.EPrinterConnectionType connType)
            {
                Logger.Write("tryToConnect: " + port.ToString() + ", " + deviceAdress + ", " + timeout.ToString());

                ConnecttionJob job = new ConnecttionJob();

                job.MaxTimeoutForRead     = 0;
                job.TimeToWaitForMoreData = 0;
                job.Port           = port;
                job.Address        = deviceAdress;
                job.ConnectionType = connType;

                job.Connect(timeout);

                return(job);
            }
Example #4
0
            public void sendConnectResult(string deviceName, string deviceAdress, Int32 devicePort, PrinterZebra.EPrinterConnectionType connType, IMethodResult oResult)
            {
                IReadOnlyDictionary <string, string> printerResult = new IReadOnlyDictionary <string, string>();

                printerResult[ZebraConstants.HK_STATUS]               = ZebraConstants.PRINTER_STATUS_SUCCESS;
                printerResult[ZebraConstants.HK_PRINTER_ID]           = deviceAdress;
                printerResult[ZebraConstants.PROPERTY_DEVICE_ADDRESS] = deviceAdress;
                printerResult[ZebraConstants.PROPERTY_DEVICE_PORT]    = devicePort.ToString();
                printerResult[ZebraConstants.PROPERTY_PRINTER_TYPE]   = ZebraConstants.PRINTER_TYPE_ZEBRA;
                printerResult[ZebraConstants.PROPERTY_DEVICE_NAME]    = deviceName;

                if (connType == PrinterZebra.EPrinterConnectionType.eBluetooth)
                {
                    printerResult[ZebraConstants.PROPERTY_CONNECTION_TYPE] = ZebraConstants.CONNECTION_TYPE_BLUETOOTH;
                }
                else if (connType == PrinterZebra.EPrinterConnectionType.eTCP)
                {
                    printerResult[ZebraConstants.PROPERTY_CONNECTION_TYPE] = ZebraConstants.CONNECTION_TYPE_TCP;
                }
                else if (connType == PrinterZebra.EPrinterConnectionType.eOnBoard)
                {
                    printerResult[ZebraConstants.PROPERTY_CONNECTION_TYPE] = ZebraConstants.CONNECTION_TYPE_ON_BOARD;
                }
                else if (connType == PrinterZebra.EPrinterConnectionType.eUSB)
                {
                    printerResult[ZebraConstants.PROPERTY_CONNECTION_TYPE] = ZebraConstants.CONNECTION_TYPE_USB;
                }

                oResult.set(printerResult);
            }
Example #5
0
            private void searchBluetooth()
            {
                Logger.Write("Start search Bluetooth printers");

                // process connection to Bluetooth
                PrinterZebra.EPrinterConnectionType connType = PrinterZebra.EPrinterConnectionType.eBluetooth;

                if (deviceAdress != null && !PrinterManager.Instance.hasPrinter(deviceAdress))
                {
                    Logger.Write("Start search in address: " + deviceAdress);

                    ConnecttionJob job = zebraSingleton.tryToConnect(0, deviceAdress, ZebraConstants.connectionTimeout, connType);

                    if (job.Connection != null)
                    {
                        PrinterManager.Instance.addPrinterWithID(deviceAdress, 0, connType);

                        if (!isSearchStopped)
                        {
                            zebraSingleton.sendConnectResult(job.FriendlyName, deviceAdress, 0, connType, oResult);
                        }

                        job.Close();
                    }
                }
                else
                {
                    DiscoveredPrinter[] printers = null;

                    for (int attempt = 0; attempt < connettionAttempts; attempt++)
                    {
                        printers = BluetoothDiscoverer.FindPrinters();

                        if (printers.Length > 0)
                        {
                            break;
                        }

                        Thread.Sleep(500);
                    }

                    LogDiscoveryPrinters(printers);

                    foreach (DiscoveredPrinter printer in printers)
                    {
                        Logger.Write("searching in address: " + printer.Address);

                        if (PrinterManager.Instance.hasPrinter(printer.Address))
                        {
                            continue;
                        }

                        if (isSearchStopped == true)
                        {
                            return;
                        }

                        Logger.Write("Found printer on address: " + printer.Address);

                        //zebraSingleton.sendConnectResult(job.FriendlyName, printer.Address, 0, connType, oResult);
                        zebraSingleton.sendConnectResult(printer.Address, printer.Address, 0, connType, oResult);
                    }
                }
            }
Example #6
0
            private void searchWiFi()
            {
                Logger.Write("Start search TCP printers");

                // process connection to TCP address
                PrinterZebra.EPrinterConnectionType connType = PrinterZebra.EPrinterConnectionType.eTCP;

                if (deviceAdress != null && devicePort > 0 && !PrinterManager.Instance.hasPrinter(deviceAdress))
                {
                    Logger.Write("searching in address: " + deviceAdress);

                    ConnecttionJob job = zebraSingleton.tryToConnect(devicePort, deviceAdress, ZebraConstants.connectionTimeout, connType);

                    if (job.Connection != null)
                    {
                        Logger.Write("Found printer on address: " + deviceAdress);

                        PrinterManager.Instance.addPrinterWithID(deviceAdress, devicePort, connType);

                        if (!isSearchStopped)
                        {
                            zebraSingleton.sendConnectResult(job.FriendlyName, deviceAdress, devicePort, connType, oResult);
                        }

                        job.Close();
                    }
                }
                else
                {
                    Logger.Write("Start search in TCP network");

                    DiscoveredPrinter[] printers = null;

                    for (int attempt = 0; attempt < connettionAttempts; attempt++)
                    {
                        printers = NetworkDiscoverer.LocalBroadcast();

                        if (printers.Length > 0)
                        {
                            break;
                        }

                        Thread.Sleep(500);
                    }

                    if (printers.Length == 0)
                    {
                        for (int attempt = 0; attempt < connettionAttempts; attempt++)
                        {
                            printers = NetworkDiscoverer.Multicast(5);

                            if (printers.Length > 0)
                            {
                                break;
                            }

                            Thread.Sleep(500);
                        }
                    }

                    LogDiscoveryPrinters(printers);

                    foreach (DiscoveredPrinter printer in printers)
                    {
                        if (isSearchStopped)
                        {
                            break;
                        }

                        Logger.Write("searching in address: " + printer.Address);

                        if ((printer is DiscoveredPrinterNetwork) && !PrinterManager.Instance.hasPrinter(printer.Address))
                        {
                            DiscoveredPrinterNetwork networkPrinter = (DiscoveredPrinterNetwork)printer;

                            ConnecttionJob job = zebraSingleton.tryToConnect(networkPrinter.Port, networkPrinter.Address, ZebraConstants.connectionTimeout, connType);

                            if (job.Connection != null)
                            {
                                Logger.Write("Found printer on address: " + printer.Address);

                                PrinterManager.Instance.addPrinterWithID(networkPrinter.Address, networkPrinter.Port, connType);

                                zebraSingleton.sendConnectResult(job.FriendlyName, networkPrinter.Address, networkPrinter.Port, connType, oResult);

                                job.Close();
                            }
                        }
                    }
                }
            }