public IDScanner() { explorer = new PosExplorer(); var deviceCollection = explorer.GetDevices("Scanner"); foreach (DeviceInfo deviceInfo in deviceCollection) { if (deviceInfo.ServiceObjectName != "Honeywell3310g") continue; scanner = (Scanner)explorer.CreateInstance(deviceInfo); break; } }
private void ScannerLab1_Load(object sender, EventArgs e) { explorer = new PosExplorer(); scannerList1 = explorer.GetDevices(); bsDevices.DataSource = scannerList1; cboDevices.DisplayMember = scannerList1.ToString(); scannerList = explorer.GetDevices(DeviceType.Scanner); devicesBindingSource.DataSource = scannerList; cboDevices.DisplayMember = scannerList.ToString(); }
static DeviceInfo Find(string DeviceClass, string SONameMatch) { InitPosCheck(); ArrayList deviceDisplayList; DeviceInfo selectedDevice = null; WriteLog("Looking for POS class = {0}", DeviceClass); deviceDisplayList = new ArrayList(explorer.GetDevices(DeviceClass)); foreach (DeviceInfo di in deviceDisplayList) { WriteLog("ServiceObjectNAme: {0}", di.ServiceObjectName); WriteLog(" Desc: {0}", di.Description); if (di.LogicalNames.Count() >= 1) { int ix = 0; foreach (string lname in di.LogicalNames) { WriteLog(" Logical[{0}]: {1}", ix++, lname); } } if (!string.IsNullOrEmpty(SONameMatch) && di.ServiceObjectName.ToLower().Contains(SONameMatch.ToLower())) { selectedDevice = di; } } if (selectedDevice == null && deviceDisplayList.Count > 0) { selectedDevice = (DeviceInfo)(deviceDisplayList[0]); } return(selectedDevice); }
private void backgroundWorker_LightsOff(object sender, DoWorkEventArgs e) { PosExplorer explorer = new PosExplorer(); PosCommon doorhub = null; var commonCollection = explorer.GetDevices("PosCommon"); foreach (DeviceInfo deviceInfo in commonCollection) { if (deviceInfo.ServiceObjectName != "DoorHub") continue; doorhub = (PosCommon)explorer.CreateInstance(deviceInfo); break; } if (doorhub == null) { MessageBox.Show("Doorhub not activated"); return; } doorhub.Open(); doorhub.Claim(1000); doorhub.DeviceEnabled = true; DirectIOData data = doorhub.DirectIO(1, 0, new string[] { "HexMaskGPB", "00" }); doorhub.DeviceEnabled = false; doorhub.Release(); doorhub.Close(); }
void LoadBarcodes() { try { _posexplorer = new PosExplorer(); _barcodescannerList = _posexplorer.GetDevices(DeviceType.Scanner); IEnumerable <PosDeviceInfo> posdevinfo = PosDeviceInfo.CreatePosDeviceInfoCollection(_barcodescannerList); foreach (PosDeviceInfo item in posdevinfo) { if (this.InvokeRequired) { this.Invoke(new Action(() => lbBarcodeDevs.Items.Add(item))); } } } catch (PosControlException ex) { _logger.LogError(ex, "The application received an error ", "frmHardwaresetup", "ActivateScanner"); Helper.ShowMessage("The application received an error \n" + ex.Message, "Test Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { _logger.LogError(ex, "The application received an error ", "frmHardwaresetup", "ActivateScanner"); Helper.ShowMessage("The application received an error \n" + ex.Message, "Test Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private PosPrinter FindPrinter(string objectName) { PosExplorer myPosExplorer = new PosExplorer(); DeviceCollection myDevices = myPosExplorer.GetDevices(DeviceType.PosPrinter, DeviceCompatibilities.Opos); //find the printer by expected service object name foreach (DeviceInfo devInfo in myDevices) { if (devInfo.ServiceObjectName == objectName) { try { var p = myPosExplorer.CreateInstance(devInfo) as PosPrinter; //open p.Open(); //claim the printer for use p.Claim(CLAIM_TIMEOUT_MS); //make sure it is enabled p.DeviceEnabled = true; return(p); } catch (Exception) { // Eating exception for other printers may be connected } } } return(null); }
public OPOSLineDisplayServer(string deviceName) { PosExplorer myPosExplorer = new PosExplorer(); DeviceCollection myDevices = myPosExplorer.GetDevices(DeviceType.LineDisplay); foreach (DeviceInfo devInfo in myDevices) { if (devInfo.ServiceObjectName == deviceName) { _lineDisplay = myPosExplorer.CreateInstance(devInfo) as LineDisplay; //open _lineDisplay.Open(); //claim the printer for use _lineDisplay.Claim(CLAIM_TIMEOUT_MS); //make sure it is enabled _lineDisplay.DeviceEnabled = true; } } if (_lineDisplay == null) { throw new Exception("No Customer Display Available!"); } }
public OPOSCashDrawerServer(string deviceName) { PosExplorer myPosExplorer = new PosExplorer(); DeviceCollection myDevices = myPosExplorer.GetDevices(DeviceType.CashDrawer); try { foreach (DeviceInfo devInfo in myDevices) { if (devInfo.ServiceObjectName == deviceName) { _cashDrawer = myPosExplorer.CreateInstance(devInfo) as CashDrawer; //open _cashDrawer.Open(); //claim the printer for use _cashDrawer.Claim(CLAIM_TIMEOUT_MS); //make sure it is enabled _cashDrawer.DeviceEnabled = true; } } if (_cashDrawer == null) { throw new Exception("No Cash Drawer Available!"); } } catch (Exception ex) { throw new Exception("No Cash Drawer Available!"); } }
//public void printReceipt(InvoiceLine[] giftCards) //{ // try // { // // return; // setupPrinter(); // try // { // m_Printer.Open(); // //Get the exclusive control right for the opened device. // //Then the device is disable from other application. // m_Printer.Claim(1000); // //Enable the device. // bool result = m_Printer.DeviceEnabled = true; // // this call also causes the "It is not initialized" error // //string health = m_Printer.CheckHealth(HealthCheckLevel.External); // } // catch (PosControlException) // { // // ChangeButtonStatus(); // } // foreach (var invoiceLine in giftCards) // { // string receiptString = Receipt40Col.GetStandardReceipt(invoiceLine); // // int test = m_Printer.JrnLineChars // var file = Path.GetFullPath("Resources/logo.bmp"); // // m_Printer.PrintNormal(PrinterStation.Receipt,((char)27).ToString() + "|cA" + receiptString); // m_Printer.PrintBitmap(PrinterStation.Receipt, file, 300, PosPrinter.PrinterBitmapCenter); // m_Printer.PrintNormal(PrinterStation.Receipt, receiptString); // m_Printer.PrintNormal(PrinterStation.Receipt, Receipt40Col.extraLines(8)); // Thread.Sleep(3000); // } // } // catch (Exception ex) // { // ErrorLogging.logError(ex); // } //} //public void printReceipt(Buyback buyback, bool openDrawer = false) //{ // //return; // setupPrinter(); // try // { // m_Printer.Open(); // //Get the exclusive control right for the opened device. // //Then the device is disable from other application. // m_Printer.Claim(1000); // //Enable the device. // bool result = m_Printer.DeviceEnabled = true; // // this call also causes the "It is not initialized" error // //string health = m_Printer.CheckHealth(HealthCheckLevel.External); // string receiptString = Receipt40Col.GetStandardReceipt(buyback); // string barcodeString = buyback.Id.ToString(); // while (barcodeString.Length < 8) // { // barcodeString = " " + barcodeString; // } // // int test = m_Printer.JrnLineChars // var file = Path.GetFullPath("Resources/logo.bmp"); // // m_Printer.PrintNormal(PrinterStation.Receipt,((char)27).ToString() + "|cA" + receiptString); // m_Printer.PrintBitmap(PrinterStation.Receipt, file, 300, PosPrinter.PrinterBitmapCenter); // m_Printer.PrintNormal(PrinterStation.Receipt, receiptString); // m_Printer.PrintNormal(PrinterStation.Receipt, Receipt40Col.extraLines(8)); // if (openDrawer) // m_Printer.PrintNormal(PrinterStation.Receipt, ((char)27).ToString() + "|\x07"); // } // catch (Exception ex) // { // ErrorLogging.logError(ex); // } //} void setupPrinter() { //Create PosExplorer var posExplorer = new PosExplorer(); var devices = posExplorer.GetDevices("PosPrinter"); DeviceInfo deviceInfo = null; try { var printerName = ConfigurationManager.AppSettings["ReceiptPrinter"]; deviceInfo = devices.OfType <DeviceInfo>().FirstOrDefault(x => x.ServiceObjectName.Contains(printerName)) ?? devices.OfType <DeviceInfo>().FirstOrDefault(x => x.ServiceObjectName.Contains("Star")); // this call returns a valid object var p = posExplorer.CreateInstance(deviceInfo); m_Printer = (PosPrinter)p; // posExplorer.CreateInstance(deviceInfo); } catch (Exception exception) { Console.WriteLine(exception); // ChangeButtonStatus(); return; } }
private void SetUpPrinter() { string strLogicalName = "PosPrinter"; try { PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; myDevices = posExplorer.GetDevices(DeviceType.PosPrinter); try { deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName); m_Printer = (PosPrinter)posExplorer.CreateInstance(deviceInfo); } catch (Exception) { } m_Printer.Open(); } catch (PosControlException) { Console.WriteLine("Failed to load printer: " + strLogicalName); } }
public Printer() { explorer = new PosExplorer(); var deviceCollection = explorer.GetDevices("PosPrinter"); foreach (DeviceInfo deviceInfo in deviceCollection) { if (deviceInfo.ServiceObjectName != "VoRiMTD300Printer") continue; printer = (PosPrinter)explorer.CreateInstance(deviceInfo); break; } }
public IDNFC() { explorer = new PosExplorer(); var deviceCollection = explorer.GetDevices("RFIDScanner"); foreach (DeviceInfo deviceInfo in deviceCollection) { if (deviceInfo.ServiceObjectName != "FeigRFID") continue; nfc = (RFIDScanner)explorer.CreateInstance(deviceInfo); break; } }
private void InitializeScanner() { if (activeScanner != null) { if (activeScanner.DeviceEnabled || activeScanner.DataEventEnabled) { MessageBox.Show("USB Bar Scanner already enabled."); return; } } try { devExplorer = new PosExplorer(); try { DeviceCollection lUSBScanners = devExplorer.GetDevices(DeviceType.Scanner); foreach (DeviceInfo devInfo in lUSBScanners) { if (devInfo.ServiceObjectName == "USBHHScanner") { if (activeScanner == null) { activeScanner = devExplorer.CreateInstance(devInfo) as Scanner; } activeScanner.Open(); activeScanner.AutoDisable = true; activeScanner.DecodeData = true; activeScanner.Claim(1000); activeScanner.DataEvent += new DataEventHandler(activeScanner_DataEvent); activeScanner.ErrorEvent += new DeviceErrorEventHandler(activeScanner_ErrorDataEvent); activeScanner.DataEventEnabled = true; activeScanner.DeviceEnabled = true; } } } catch (Exception ex) { if (activeScanner.DataEventEnabled) { activeScanner.Release(); activeScanner.DeviceEnabled = true; } MessageBox.Show("Failed to find USB Scanner : " + ex.Message); } } catch (Exception ex) { MessageBox.Show("Pos Explorer : " + ex.Message); } }
public Printer() { explorer = new PosExplorer(); var deviceCollection = explorer.GetDevices(); Console.WriteLine("DeViCe count: " + deviceCollection.Count); foreach (DeviceInfo deviceInfo in deviceCollection) { Console.WriteLine("devvv: " + deviceInfo.ServiceObjectName + deviceInfo.ManufacturerName); if (deviceInfo.ServiceObjectName != "VoRiMTD300Printer") continue; printer = (PosPrinter)explorer.CreateInstance(deviceInfo); break; } }
public CashUnit() { explorer = new PosExplorer(); if (cashUnit == null) { var deviceCollection = explorer.GetDevices("CashChanger"); foreach (DeviceInfo deviceInfo in deviceCollection) { if (deviceInfo.ServiceObjectName != "Hoeft & Wessel Cash Unit") continue; cashUnit = (CashChanger)explorer.CreateInstance(deviceInfo); break; } } }
private async void Foo() { var explorer = new PosExplorer(new DispatcherThunk(this.Dispatcher)); var devices = explorer.GetDevices(DeviceType.Scanner); var scanner = (Scanner)explorer.CreateInstance(devices[1]); scanner.Open(); scanner.Claim(0); scanner.DeviceEnabled = true; scanner.DataEvent += Scanner_DataEvent; scanner.DataEventEnabled = true; scanner.DecodeData = true; this.OpenScanner = scanner; }
private void init_scanner_and_printer() { PosExplorer exp = new PosExplorer(); DeviceInfo scanner_info = null, printer_info = null; string scanner_so_name = "SYMBOL_SCANNER"; string printer_so_name = "Star TSP100 Cutter (TSP143)_1"; DeviceCollection devices = exp.GetDevices(DeviceCompatibilities.OposAndCompatibilityLevel1); foreach (DeviceInfo info in devices) { Debug.WriteLine(info.Type + " \"" + info.ServiceObjectName + "\""); if (info.ServiceObjectName == scanner_so_name) { scanner_info = info; } else if (info.ServiceObjectName == printer_so_name) { printer_info = info; } } if (scanner_info == null) { Debug.WriteLine("Scanner \"" + scanner_so_name + "\" NOT found."); } else { Debug.WriteLine("Scanner \"" + scanner_so_name + "\" found."); s = (Scanner)exp.CreateInstance(scanner_info); test_scanner(s); } if (printer_info == null) { Debug.WriteLine("Printer \"" + printer_so_name + "\" NOT found."); } else { Debug.WriteLine("Printer \"" + printer_so_name + "\" found."); p = (PosPrinter)exp.CreateInstance(printer_info); open_claim_enable_printer(p); } }
void InitializePrinter() { //<<<step1>>>--Start //Use a Logical Device Name which has been set on the SetupPOS. //string strLogicalName = "PosPrinter"; string printerName = Properties.Settings.Default.DefaultPrinterName; try { //Create PosExplorer PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = PosDeviceInfo.CreatePosDeviceInfoCollection(posExplorer.GetDevices(DeviceType.PosPrinter)) .Where(d => d.Description == printerName) .FirstOrDefault().DeviceInfo; SetStatusMessage("Checking if device drivers are installed..."); try { //deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter); m_Printer = (PosPrinter)posExplorer.CreateInstance(deviceInfo); } catch (Exception ex) { _logger.LogError(ex, "Application received an error while trying to initialize device.", "frmStartUp", "InitializePrinter"); SetStatusMessage("Application received an error while trying to initialize device."); return; } } catch (PosControlException ex) { _logger.LogError(ex, "Application received an error while trying to initialize device...", "frmStartUp", "InitializePrinter"); SetStatusMessage("Application received an error while trying to initialize device..."); } catch (Exception ex) { _logger.LogError(ex, "Application received an error while trying to initialize device...", "frmStartUp", "InitializePrinter"); SetStatusMessage("Application received an error while trying to initialize device..."); } //<<<step1>>>--End }
public FeigRFID() { PosExplorer explorer = new PosExplorer(); var deviceCollection = explorer.GetDevices("RFIDScanner"); FeigRFID rfid = null; foreach (DeviceInfo deviceInfo in deviceCollection) { if (deviceInfo.ServiceObjectName != "FeigRFID") continue; rfid = (FeigRFID)explorer.CreateInstance(deviceInfo); break; } }
private bool Imprimir(ArrayList lista) { bool impreso = false; try { PosExplorer explorer = new PosExplorer(); PosPrinter MiImpresora; IEnumerator unidades = explorer.GetDevices(DeviceType.PosPrinter).GetEnumerator(); while (unidades.MoveNext()) { DeviceInfo inf = (DeviceInfo)unidades.Current; IEnumerator nombres = inf.LogicalNames.GetEnumerator(); while (nombres.MoveNext()) { string logico = (string)nombres.Current; MessageBox.Show("" + logico); } } DeviceInfo unidadEpson = explorer.GetDevice(DeviceType.PosPrinter, "PosPrinter"); MiImpresora = (PosPrinter)explorer.CreateInstance(unidadEpson); MiImpresora.Open(); MiImpresora.Claim(1000); MiImpresora.DeviceEnabled = true; foreach (string item in lista) { MiImpresora.PrintNormal(PrinterStation.Receipt, item); } MiImpresora.PrintNormal(PrinterStation.Receipt, "\n\n\n\n\n\n\n\n\n"); MiImpresora.CutPaper(90); MiImpresora.Close(); impreso = true; } catch { impreso = false; } return(impreso); }
private void frmMain_Load(object sender, EventArgs e) { if (new GenericService <Company>().GetAll().ToList().Count == 0) { new frmAddCompany().ShowDialog(); } SetUserName(); try { this.BeginInvoke(new Action(() => { try { posExplorer = new PosExplorer(this); string barocodename = Properties.Settings.Default.DefaultScannerName; DeviceInfo deviceInfo = PosDeviceInfo.CreatePosDeviceInfoCollection(posExplorer.GetDevices(DeviceType.Scanner)) .Where(d => d.Description == barocodename) .FirstOrDefault().DeviceInfo; ActivateScanner(deviceInfo); } catch (PosControlException ex) { _logger.LogError(ex, "The application received an error ", "frmMain", "ActivateScanner"); Helper.ShowMessage("The application received an error \n" + ex.Message, "Test Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { Helper.ShowMessage(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); _logger.LogError(ex, "An error occurred", "frmMain", "scanner initialization"); } })); } catch (Exception ex) { Helper.ShowMessage(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); _logger.LogError(ex, "An error occurred", "frmMain", "scanner initialization"); } }
private string FindScanner() { string name = string.Empty; DeviceCollection scanners = _explorer.GetDevices(DeviceType.Scanner); foreach (DeviceInfo s in scanners) { Console.WriteLine(s.Description); if (string.IsNullOrEmpty(s.ManufacturerName)) { name = s.ServiceObjectName; _scanner = (Scanner)_explorer.CreateInstance(s); break; } } Console.Read(); return(name); }
public FeigRFID() { explorer = new PosExplorer(); if (rfid == null) { var deviceCollection = explorer.GetDevices("RFIDScanner"); foreach (DeviceInfo deviceInfo in deviceCollection) { if (deviceInfo.ServiceObjectName != "FeigRFID") continue; rfid = (RFIDScanner)explorer.CreateInstance(deviceInfo); log.Info(deviceInfo.ToString()); break; } } }
public static Boolean checkForScanner() { Boolean check = false; PosExplorer explorer = new PosExplorer(); var deviceCollection = explorer.GetDevices("Scanner"); foreach (DeviceInfo deviceInfo in deviceCollection) { if (deviceInfo.ServiceObjectName != "Honeywell3310g") { continue; } else { check = true; } } return check; }
public ScannerManager() { checkTimer = new System.Windows.Threading.DispatcherTimer(); checkTimer.Interval = new TimeSpan(0, 0, 2); checkTimer.Tick += checkTimer_Tick; explorer = new PosExplorer(); scannerList = explorer.GetDevices(DeviceType.Scanner); try { foreach (DeviceInfo di in scannerList) { if (di.ServiceObjectName == "USBHHScanner") { activeScanner = (Scanner)explorer.CreateInstance(di); break; } } } catch (PosException) { } }
private void OpenDevice(ref PosCommon posCommon, string strDeviceName, string strDeviceLevel) { if (string.IsNullOrEmpty(strDeviceLevel) || string.IsNullOrEmpty(strDeviceName)) { return; } DeviceCollection devices = _posExplorer.GetDevices((DeviceCompatibilities)Enum.Parse(typeof(DeviceCompatibilities), strDeviceLevel, false)); DeviceInfo drv = devices.Cast <DeviceInfo>().Where(x => x.ServiceObjectName.Equals(strDeviceName)).FirstOrDefault(); try { posCommon = (PosCommon)_posExplorer.CreateInstance(drv); posCommon.Open(); SetDataEventEnabledPosCommon(ref posCommon, true); HookUpEvents(posCommon, true); } catch (Exception ex) { //sMessengeError = ex.Message; throw ex; } }
/// <summary> /// Opens the scanner. /// </summary> /// <param name="name">The name of the scanner.</param> /// <exception cref="Microsoft.PointOfService.PosControlException"></exception> void OpenScanner(string name) { PosExplorer exp = new PosExplorer(); foreach (DeviceInfo dev in exp.GetDevices(DeviceType.Scanner)) { if (dev.LogicalNames.Contains <string>(name)) { s_objScanner = exp.CreateInstance(dev) as Scanner; break; } } if (s_objScanner != null) { lock (s_objScanner) { s_objScanner.ErrorEvent += new DeviceErrorEventHandler(OnErrorEvent); s_objScanner.DataEvent += new DataEventHandler(OnDataEvent); s_objScanner.Open(); //configuration dependent setting! if (bDecodeData) { s_objScanner.DecodeData = true; } } scannerData = string.Empty; evtWaitScannerData.Reset(); } else { throw new PosControlException(String.Format("The scanner {0} is not available!", name), ErrorCode.NoHardware); } }
//public void printReceipt(InvoiceLine[] giftCards) //{ // try // { // // return; // setupPrinter(); // try // { // m_Printer.Open(); // //Get the exclusive control right for the opened device. // //Then the device is disable from other application. // m_Printer.Claim(1000); // //Enable the device. // bool result = m_Printer.DeviceEnabled = true; // // this call also causes the "It is not initialized" error // //string health = m_Printer.CheckHealth(HealthCheckLevel.External); // } // catch (PosControlException) // { // // ChangeButtonStatus(); // } // foreach (var invoiceLine in giftCards) // { // string receiptString = Receipt40Col.GetStandardReceipt(invoiceLine); // // int test = m_Printer.JrnLineChars // var file = Path.GetFullPath("Resources/logo.bmp"); // // m_Printer.PrintNormal(PrinterStation.Receipt,((char)27).ToString() + "|cA" + receiptString); // m_Printer.PrintBitmap(PrinterStation.Receipt, file, 300, PosPrinter.PrinterBitmapCenter); // m_Printer.PrintNormal(PrinterStation.Receipt, receiptString); // m_Printer.PrintNormal(PrinterStation.Receipt, Receipt40Col.extraLines(8)); // Thread.Sleep(3000); // } // } // catch (Exception ex) // { // ErrorLogging.logError(ex); // } //} //public void printReceipt(Buyback buyback, bool openDrawer = false) //{ // //return; // setupPrinter(); // try // { // m_Printer.Open(); // //Get the exclusive control right for the opened device. // //Then the device is disable from other application. // m_Printer.Claim(1000); // //Enable the device. // bool result = m_Printer.DeviceEnabled = true; // // this call also causes the "It is not initialized" error // //string health = m_Printer.CheckHealth(HealthCheckLevel.External); // string receiptString = Receipt40Col.GetStandardReceipt(buyback); // string barcodeString = buyback.Id.ToString(); // while (barcodeString.Length < 8) // { // barcodeString = " " + barcodeString; // } // // int test = m_Printer.JrnLineChars // var file = Path.GetFullPath("Resources/logo.bmp"); // // m_Printer.PrintNormal(PrinterStation.Receipt,((char)27).ToString() + "|cA" + receiptString); // m_Printer.PrintBitmap(PrinterStation.Receipt, file, 300, PosPrinter.PrinterBitmapCenter); // m_Printer.PrintNormal(PrinterStation.Receipt, receiptString); // m_Printer.PrintNormal(PrinterStation.Receipt, Receipt40Col.extraLines(8)); // if (openDrawer) // m_Printer.PrintNormal(PrinterStation.Receipt, ((char)27).ToString() + "|\x07"); // } // catch (Exception ex) // { // ErrorLogging.logError(ex); // } //} void setupPrinter() { //Create PosExplorer var posExplorer = new PosExplorer(); var devices = posExplorer.GetDevices("PosPrinter"); DeviceInfo deviceInfo = null; try { var printerName = ConfigurationManager.AppSettings["ReceiptPrinter"]; deviceInfo = devices.OfType<DeviceInfo>().FirstOrDefault(x => x.ServiceObjectName.Contains(printerName)) ?? devices.OfType<DeviceInfo>().FirstOrDefault(x => x.ServiceObjectName.Contains("Star")); // this call returns a valid object var p = posExplorer.CreateInstance(deviceInfo); m_Printer = (PosPrinter) p; // posExplorer.CreateInstance(deviceInfo); } catch (Exception exception) { Console.WriteLine(exception); // ChangeButtonStatus(); return; } }
/// <summary> /// How to use "PosExplorer" sample2. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnExample2_Click(object sender, System.EventArgs e) { try { //Create PosExplorer PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; DeviceCollection deviceCollection; //Get DeviceCollection use device categoly deviceCollection = posExplorer.GetDevices(DeviceType.PosPrinter); string[] astrLogicalNames; Hashtable hashDevice = new Hashtable(0); foreach (DeviceInfo devInfo in deviceCollection) { //if the device name is registered. if (devInfo.LogicalNames.Length > 0) { astrLogicalNames = devInfo.LogicalNames; for (int i = 0; i < astrLogicalNames.Length; i++) { if (!hashDevice.ContainsKey(astrLogicalNames[i])) { m_PosCommon = (PosCommon)posExplorer.CreateInstance(devInfo); //Use Legacy Opos //if(m_PosCommon.Compatibility.Equals(DeviceCompatibilities.Opos)) //Use Opos for .Net if (m_PosCommon.Compatibility.Equals (DeviceCompatibilities.CompatibilityLevel1)) { try { //Register hashtable key:LogicalName,Value:DeviceInfo hashDevice.Add(astrLogicalNames[i], devInfo); } catch (Exception) { } } } } } } deviceInfo = (DeviceInfo)hashDevice[m_strLogicalName]; m_PosCommon = (PosCommon)posExplorer.CreateInstance(deviceInfo); //Open the device m_PosCommon.Open(); //Get the exclusive control right for the opened device. //Then the device is disable from other application. m_PosCommon.Claim(1000); //Enable the device. m_PosCommon.DeviceEnabled = true; //CheckHealth. m_PosCommon.CheckHealth(Microsoft.PointOfService.HealthCheckLevel.Interactive); //Close device m_PosCommon.Close(); } catch (Exception) { } }
public static Boolean checkForPrinter() { Boolean check = false; PosExplorer explorer = new PosExplorer(); var deviceCollection = explorer.GetDevices("PosPrinter"); foreach (DeviceInfo deviceInfo in deviceCollection) { if (deviceInfo.ServiceObjectName != "VoRiMTD300Printer") { continue; } else { check = true; } } return check; }
/// <summary> /// Gets a list of the OPOS printers and loads any saved settings. /// </summary> public FormMain() { // // Required for Windows Form Designer support // InitializeComponent(); //Load Connection settings StoreIDtextBox.Text = Properties.Settings.Default.store_id; PasswordTextBox.Text = Properties.Settings.Default.password; WebServiceTextBox.Text = Properties.Settings.Default.WebService; //Load printer settings. RegistryKey rKey = Registry.LocalMachine; try { rKey = rKey.OpenSubKey("HARDWARE\\DEVICEMAP\\SERIALCOMM"); string[] values; values = rKey.GetValueNames(); for (int i = 0; i < values.GetLength(0); i++) { string comValue = rKey.GetValue(values[i]).ToString(); cbPort.Items.Add(comValue); if (comValue == Properties.Settings.Default.COMPort) { cbPort.SelectedItem = comValue; //Start sniffing as well; SniffSwitch(); // Hide the form to the system tray. this.WindowState = FormWindowState.Minimized; this.ShowInTaskbar = false; } else { cbPort.SelectedIndex = 0; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } try { posExplorer = new PosExplorer(this); DeviceCollection devices = posExplorer.GetDevices(DeviceType.PosPrinter, DeviceCompatibilities.Opos); foreach (DeviceInfo deviceInfo in devices) { printerList.Add(deviceInfo); OPOSListcomboBox.Items.Add(deviceInfo.ServiceObjectName); } for (int i = 0; i < OPOSListcomboBox.Items.Count; i++) { object o = OPOSListcomboBox.Items[i]; string displayText = o.ToString(); if (displayText == Properties.Settings.Default.OPOSPrinter) { OPOSListcomboBox.SelectedItem = displayText; } else { OPOSListcomboBox.SelectedIndex = 0; } } } catch (Exception ex) { throw ex; } //Default Ad DefaultAdTextBox.Text = Properties.Settings.Default.DefaultAd; //Load Loyalty Settings SendSalesDataCheckBox.Checked = Properties.Settings.Default.sendSalesData; DPDBTextBox.Text = Properties.Settings.Default.DPDBLocation; syncCustomersCheckBox.Checked = Properties.Settings.Default.syncCustomersOnStartup; if (Properties.Settings.Default.POSSoftware == "MYOB") { MYOBRadioButton.Checked = true; MicrosoftRMSRadioButton.Checked = false; ToggleSoftwarePanels(true); RMDBTextBox.Text = Properties.Settings.Default.RMDBLocation; if (!String.IsNullOrEmpty(RMDBTextBox.Text) && !String.IsNullOrEmpty(DPDBTextBox.Text)) { if (syncCustomersCheckBox.Checked) { SyncCustomers(); } if (SendSalesDataCheckBox.Checked) { ProcessUnsentDockets(); } } else { RewardsErrorLabel.Text = "Check RetailManager database location"; } Cat1Cat2RadioButton.Checked = Properties.Settings.Default.CategoriesOnly; DepCat1RadioButton.Checked = !Properties.Settings.Default.CategoriesOnly; } else if (Properties.Settings.Default.POSSoftware == "Microsoft") { MYOBRadioButton.Checked = false; MicrosoftRMSRadioButton.Checked = true; ToggleSoftwarePanels(false); MicrosoftLocationTextBox.Text = Properties.Settings.Default.POSServerLocation; MicrosoftDBTextBox.Text = Properties.Settings.Default.POSServerDBName; MicrosoftUserTextBox.Text = Properties.Settings.Default.POSServerUser; MicrosoftPasswordTextBox.Text = Properties.Settings.Default.POSServerPassword; ReceiptIdentifiersTextBox.Text = Properties.Settings.Default.ReceiptIdentifiers; TransactionCaptionTextBox.Text = Properties.Settings.Default.TransactionCaption; if (TestSQLConnection(MicrosoftLocationTextBox.Text, MicrosoftDBTextBox.Text ,MicrosoftUserTextBox.Text, MicrosoftPasswordTextBox.Text) && !String.IsNullOrEmpty(DPDBTextBox.Text)) { if (syncCustomersCheckBox.Checked) { SyncCustomers(); } if (SendSalesDataCheckBox.Checked) { ProcessUnsentDockets(); } } else { RewardsErrorLabel.Text = "Check SQL Server database connection"; } } }