public PrinterStatus getPrinterStatus(rho.PrinterZebraImpl.PrinterZebra.EPrinterConnectionType connType, string address, Int32 port) { Logger.Write("MainWindow.getPrinterStatus call, address=" + address + " port=" + port.ToString()); PrinterStatus status = null; ZebraPrinterConnection connection = null; ZebraPrinter printer = null; if (connType == rho.PrinterZebraImpl.PrinterZebra.EPrinterConnectionType.eTCP) { connection = new TcpPrinterConnection(address, port); } else if (connType == rho.PrinterZebraImpl.PrinterZebra.EPrinterConnectionType.eBluetooth) { connection = new BluetoothPrinterConnection(address); } else if (connType == rho.PrinterZebraImpl.PrinterZebra.EPrinterConnectionType.eUSB) { connection = new UsbPrinterConnection(address); } else { Logger.Write("MainWindow.getPrinterStatus undifined connection type"); return(null); } connection.Open(); if (connection.IsConnected()) { printer = ZebraPrinterFactory.GetInstance(PrinterLanguage.ZPL, connection); status = printer.GetCurrentStatus(); } connection.Close(); Logger.Write("MainWindow.getPrinterStatus call finished"); return(status); }
public PrinterStatus getPrinterStatus(rho.PrinterZebraImpl.PrinterZebra.EPrinterConnectionType connType, string address, Int32 port) { Logger.Write("MainWindow.getPrinterStatus call, address=" + address + " port=" + port.ToString()); PrinterStatus status = null; ZebraPrinterConnection connection = null; ZebraPrinter printer = null; if (connType == rho.PrinterZebraImpl.PrinterZebra.EPrinterConnectionType.eTCP) { connection = new TcpPrinterConnection(address, port); } else if (connType == rho.PrinterZebraImpl.PrinterZebra.EPrinterConnectionType.eBluetooth) { connection = new BluetoothPrinterConnection(address); } else if (connType == rho.PrinterZebraImpl.PrinterZebra.EPrinterConnectionType.eUSB) { connection = new UsbPrinterConnection(address); } else { Logger.Write("MainWindow.getPrinterStatus undifined connection type"); return null; } connection.Open(); if (connection.IsConnected()) { printer = ZebraPrinterFactory.GetInstance(PrinterLanguage.ZPL, connection); status = printer.GetCurrentStatus(); } connection.Close(); Logger.Write("MainWindow.getPrinterStatus call finished"); return status; }
private void Run() { try { if (ConnectionType == PrinterZebra.EPrinterConnectionType.eTCP) { Connection = new TcpPrinterConnection(Address, Port, MaxTimeoutForRead, TimeToWaitForMoreData); } else if (ConnectionType == PrinterZebra.EPrinterConnectionType.eBluetooth) { Connection = new BluetoothPrinterConnection(Address, MaxTimeoutForRead, TimeToWaitForMoreData); } else if (ConnectionType == PrinterZebra.EPrinterConnectionType.eUSB) { Connection = new UsbPrinterConnection(Address); } if (Connection == null) { return; } Connection.Open(); if (Connection != null && !Connection.IsConnected()) { Close(); return; } if (Connection != null) { if (ConnectionType != PrinterZebra.EPrinterConnectionType.eUSB) { SGD.SET("device.languages", "ZPL", Connection); } else { //Do nothing for USB } Printer = ZebraPrinterFactory.GetInstance(PrinterLanguage.ZPL, Connection); if (ConnectionType != PrinterZebra.EPrinterConnectionType.eUSB) { FriendlyName = SGD.GET("device.friendly_name", Connection); } else { FriendlyName = "USB Printer"; } if (FriendlyName.Length == 0) { Logger.Write("friendly name is empty, return device name"); FriendlyName = Address; } } } catch (ZebraPrinterConnectionException e) { Logger.Write("Connect exception [connection]: " + e.Message); Close(); } catch (ZebraGeneralException e) { Logger.Write("Connect exception [general]: " + e.Message); Close(); } catch (Exception e) { Logger.Write("Connect exception [system]: " + e.Message); Close(); } }