public Printer(string deviceName = "PosPrinter") { var posExplorer = new PosExplorer(); var deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, deviceName); m_Printer = (PosPrinter)posExplorer.CreateInstance(deviceInfo); m_Printer.Open(); m_Printer.Claim(500); m_Printer.DeviceEnabled = true; m_Printer.RecLetterQuality = true; m_Printer.MapMode = MapMode.Metric; m_Printer.ClearOutput(); }
public ICashDrawer GetCashDrawer() { if (_drawer == null) { DeviceInfo drawerDeviceInfo = _exp.GetDevice("CashDrawer"); CashDrawer drawer = (CashDrawer)_exp.CreateInstance(drawerDeviceInfo); _drawer = new DrawerWrapper(drawer, _messageBus); drawer.Open(); } return(_drawer); }
private PosPrinter GetReceiptPrinter() { //PosExplorer explorer = new PosExplorer(); //return explorer.GetDevices(DeviceType.PosPrinter, DeviceCompatibilities.OposAndCompatibilityLevel1); PosExplorer posExplorer = null; try { posExplorer = new PosExplorer(); } catch (Exception) { //posExplorer = new PosExplorer(this); } //var ppp = posExplorer.GetDevices(DeviceType.PosPrinter, DeviceCompatibilities.OposAndCompatibilityLevel1); // var pp = posExplorer.GetDevices(); // DeviceInfo receiptPrinterDevice = posExplorer.GetDevice("EPSON TM-T20II Receipt", "EPSON TM-T20II Receipt"); //May need to change this if you don't use a logicial name or //use a different one. DeviceInfo receiptPrinterDevice = posExplorer.GetDevice(DeviceType.PosPrinter, "POSPrinter"); //May need to change this if you don't use a logicial name or//my_device //DeviceInfo receiptPrinterDevice1 = posExplorer.GetDevice(DeviceType.LineDisplay, "my_device"); //May need to change this if you don't use a logicial name or//my_device // receiptPrinterDevice. return((PosPrinter)posExplorer.CreateInstance(receiptPrinterDevice)); }
public void OpenCashDrawer(bool IsWaited = false) { try { string strLogicalName = "CashDrawer"; //PosExplorerを生成します。 PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; deviceInfo = posExplorer.GetDevice(DeviceType.CashDrawer, strLogicalName); m_Drawer = (CashDrawer)posExplorer.CreateInstance(deviceInfo); try { // m_Drawer.DeviceEnabled = true; } catch { } m_Drawer.Open(); m_Drawer.Claim(1000); //デバイスを使用可能(動作できる状態)にします。 m_Drawer.DeviceEnabled = true; } catch (PosControlException) { } m_Drawer.OpenDrawer(); // ドロワーが開いている間、待ちます。 while (m_Drawer.DrawerOpened == false) { System.Threading.Thread.Sleep(100); } //開いてから10秒間経っても閉じられない場合はビープ音を断続的に鳴らします。 //このメソッドを実行すると、ドロワーが閉じられるまで処理が戻ってこないので注意してください。 if (IsWaited) { m_Drawer.WaitForDrawerClose(10000, 2000, 100, 1000); } try { CloseCashDrawer(); } catch { try { m_Drawer = null; } catch { } } }
private PosPrinter GetReceiptPrinter() { PosExplorer posExplorer = new PosExplorer(this); DeviceInfo receiptPrinterDevice = posExplorer.GetDevice("PosPrinter", "ReceiptPrinter"); //May need to change this if you don't use a logicial name or use a different one. return((PosPrinter)posExplorer.CreateInstance(receiptPrinterDevice)); }
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); } }
private void Connect() { if (string.IsNullOrEmpty(txtLogicalName.Text)) { SetStatus(Level.Warning, "Enter a logical name to connect to the scanner"); return; } txtLogicalName.Enabled = false; txtConnectScanner.Text = "Disconnect Scanner"; try { var explorer = new PosExplorer(); _scanner = explorer.CreateInstance(explorer.GetDevice(DeviceType.Scanner, txtLogicalName.Text)) as Scanner; AddDataEvent(_scanner); SetStatus(Level.Info, "Opening " + txtLogicalName.Text); _scanner.Open(); SetStatus(Level.Info, "Claiming scanner"); _scanner.Claim(1000); SetStatus(Level.Info, "Enabling scanner"); _scanner.DeviceEnabled = true; _scanner.DataEventEnabled = true; _scanner.DecodeData = true; SetStatus(Level.Success, "Ready"); } catch (PosControlException ex) { SetStatus(Level.Error, "Failed to connect to scanner. " + ex.Message); } }
/// <summary> /// How to use "PosExplorer" sample1. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnExample1_Click(object sender, System.EventArgs e) { //Use a Logical Device Name which has been set on the SetupPOS. try { //Create PosExplorer PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; //Get DeviceInfo use devicecategory and logicalname. deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, 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 Printer(string logicalName) { var explorer = new PosExplorer(); var device = explorer.GetDevice(DeviceType.PosPrinter, logicalName); Device = explorer.CreateInstance(device) as PosPrinter; }
public CashDrawerClass() { explorer = new PosExplorer(this); DeviceInfo ObjDevicesInfo = explorer.GetDevice("CashDrawer"); myCashDrawer = explorer.CreateInstance(ObjDevicesInfo); }
private void Panel_Empleados_Load(object sender, EventArgs e) { //<<< step1 >>> --Start //Use a Logical Device Name which has been set on the SetupPOS. string strLogicalName = "CashDrawer"; try { //Create PosExplorer PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; try { deviceInfo = posExplorer.GetDevice(DeviceType.CashDrawer, strLogicalName); m_Drawer = (CashDrawer)posExplorer.CreateInstance(deviceInfo); } catch (Exception) { //Nothing can be used. return; } } catch (PosControlException) { //Nothing can be used. //Nothing can be used. } //<<<step1>>>--End }
public cImpresora(string nombreLogico) { try { _nombreLogico = nombreLogico; PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, _nombreLogico); _oPrinter = (PosPrinter)posExplorer.CreateInstance(deviceInfo); _oPrinter.Open(); _oPrinter.Claim(1000); _oPrinter.DeviceEnabled = true; //Output by the high quality mode _oPrinter.RecLetterQuality = true; // Even if using any printers, 0.01mm unit makes it possible to print neatly. _oPrinter.MapMode = MapMode.Metric; } catch (PosControlException ex) { throw new Exception("Error al abrir la impresora fiscal. " + ex.Message); } catch (Exception ex) { throw new Exception("Error al abrir la impresora fiscal. " + ex.Message); } }
public Scanner(string logicalName) { var explorer = new PosExplorer(); var device = explorer.GetDevice(DeviceType.Scanner, logicalName); Device = explorer.CreateInstance(device) as Microsoft.PointOfService.Scanner; }
private void GunlukRapor_Click(object sender, EventArgs e) { string zaman = DateTime.Now.ToShortDateString(); DialogResult Uyari = new DialogResult(); Uyari = MessageBox.Show("TÜM GİDERLERİN RAPORU BASILACAK BU RAPOR UZUNLUĞU GİDERLERİNİZİN UZUNLUĞU KADAR OLACAKTIR. ESKİ GİDERLERİNİZİ SİLERSENİZ RAPOR DAHA KISA OLABİLİR. DEVAM EDİLSİN Mİ?", "UYARI!", MessageBoxButtons.YesNo); if (Uyari == DialogResult.Yes) { try { var explorer = new PosExplorer(); var deviceInfo = explorer.GetDevice(DeviceType.PosPrinter); if (deviceInfo == null) { MessageBox.Show("BİLGİSAYARA BAĞLI YAZICI YOK YADA BAĞLANTI KURULAMADI", "ÇEKİRDEK KOD TERS MÜHENDİSLİK KORUMASI!"); return; } Yazici = (PosPrinter)explorer.CreateInstance(deviceInfo); Yazici.Open(); Yazici.Claim(500); Yazici.DeviceEnabled = true; Yazici.StatusUpdateEvent += (s, evt) => { if (evt.Status == PosPrinter.StatusCoverOpen) { MessageBox.Show("Yazıcının kağıt kapağı açıldı"); } if (evt.Status == PosPrinter.StatusCoverOK) { MessageBox.Show("Yazıcının kağıt kapağı kapandı"); } if (evt.Status == PosPrinter.StatusJournalCartridgeEmpty) { MessageBox.Show("Yazıcının kartuşu bitmek üzere"); } }; Yazici.PrintNormal(PrinterStation.Slip, " PRESTIGE CAFE " + Environment.NewLine); Yazici.PrintNormal(PrinterStation.Slip, "GÜnlük Gider Raporu" + " TARİH: " + DateTime.Now.ToShortDateString() + Environment.NewLine); Yazici.PrintNormal(PrinterStation.Slip, "**************************************************************" + Environment.NewLine); VeriEntities3 context = new VeriEntities3(); foreach (var bul in context.Giderler.Where(p => p.Tarih == zaman)) { Yazici.PrintNormal(PrinterStation.Slip, "Gider adı: " + bul.GiderAdi + " Gider Tutarı: " + bul.GiderTutari + " Tarih: " + bul.Tarih + Environment.NewLine); } Yazici.PrintNormal(PrinterStation.Slip, "**************************************************************" + Environment.NewLine); Yazici.PrintNormal(PrinterStation.Slip, "MARKETMATİK BETA V.1.0.2 [email protected]" + Environment.NewLine); Yazici.CutPaper(100); MessageBox.Show("Gider Yazdırıldı.", "Kullanıcı İşlemleri"); this.Close(); formdd1.Visible = true; } catch { MessageBox.Show("DÖNGÜSEL VERİTABANI HATASI. DATA BULUNAMADI YADA VERİTABANI BAĞLANTISI KESİLDİ.", "ÇEKİRDEK KOD ÖLÜMCÜL HATA!"); MessageBox.Show("LÜTFEN GELİŞTİRİCİ İLE İRTİBAT KURUN. PROGRAM SONLANICAK", "ÇEKİRDEK KOD TERS MÜHENDİSLİK KORUMASI"); Application.Exit(); } } }
private void cariodetamaminiode_Click(object sender, EventArgs e) { Musteriler musteriler = new Musteriler(); var MusteriCariOde = db.Musteriler.Where(w => w.MusteriAdi == cariodemusteriadi.Text).FirstOrDefault(); try { String Odeme = MusteriCariOde.MusteriBakiyesi; MusteriCariOde.MusteriBakiyesi = "0"; db.SaveChanges(); var explorer = new PosExplorer(); var deviceInfo = explorer.GetDevice(DeviceType.PosPrinter); if (deviceInfo == null) { MessageBox.Show("BİLGİSAYARA BAĞLI YAZICI YOK YADA BAĞLANTI KURULAMADI", "ÇEKİRDEK KOD TERS MÜHENDİSLİK KORUMASI!"); return; } Yazici = (PosPrinter)explorer.CreateInstance(deviceInfo); Yazici.Open(); Yazici.Claim(500); Yazici.DeviceEnabled = true; Yazici.StatusUpdateEvent += (s, evt) => { if (evt.Status == PosPrinter.StatusCoverOpen) { MessageBox.Show("Yazıcının kağıt kapağı açıldı"); } if (evt.Status == PosPrinter.StatusCoverOK) { MessageBox.Show("Yazıcının kağıt kapağı kapandı"); } if (evt.Status == PosPrinter.StatusJournalCartridgeEmpty) { MessageBox.Show("Yazıcının kartuşu bitmek üzere"); } }; Yazici.PrintNormal(PrinterStation.Slip, " PRESTIGE CAFE " + Environment.NewLine); Yazici.PrintNormal(PrinterStation.Slip, "CARİ ÖDEME BİLGİ FİŞİ" + " TARİH: " + DateTime.Now.ToShortDateString() + Environment.NewLine); Yazici.PrintNormal(PrinterStation.Slip, "**************************************************************" + Environment.NewLine); Yazici.PrintNormal(PrinterStation.Slip, "MÜŞTERİ ADI : " + MusteriCariOde.MusteriAdi + Environment.NewLine); Yazici.PrintNormal(PrinterStation.Slip, "--------------------------------------------------------------" + Environment.NewLine); Yazici.PrintNormal(PrinterStation.Slip, "MÜŞTERİ CARİSİ: " + Odeme + Environment.NewLine); Yazici.PrintNormal(PrinterStation.Slip, "--------------------------------------------------------------" + Environment.NewLine); Yazici.PrintNormal(PrinterStation.Slip, "ÖDENEN MİKTAR : " + Odeme + Environment.NewLine); Yazici.PrintNormal(PrinterStation.Slip, "**************************************************************" + Environment.NewLine); Yazici.PrintNormal(PrinterStation.Slip, " TEŞEKKÜR EDERİZ " + Environment.NewLine); Yazici.PrintNormal(PrinterStation.Slip, "MARKETMATİK BETA V.1.0.2 [email protected]" + Environment.NewLine); Yazici.CutPaper(100); musteriyonetimformu = new MusteriYonetimFormu(); musteriyonetimformu.Show(); this.Close(); } catch { MessageBox.Show("DÖNGÜSEL VERİTABANI HATASI. DATA BULUNAMADI YADA VERİTABANI BAĞLANTISI KESİLDİ.", "ÇEKİRDEK KOD ÖLÜMCÜL HATA!"); MessageBox.Show("LÜTFEN GELİŞTİRİCİ İLE İRTİBAT KURUN. PROGRAM SONLANICAK", "ÇEKİRDEK KOD TERS MÜHENDİSLİK KORUMASI"); Application.Exit(); } }
private PosPrinter GetReceiptPrinter() { PosExplorer posExplorer = new PosExplorer(this); //May need to change this if you don't use a logical name or use a different one. // Since, I don't know what is the printer's logical name DeviceInfo receiptPrinterDevice = posExplorer.GetDevice(DeviceType.PosPrinter.ToString()); return((PosPrinter)posExplorer.CreateInstance(receiptPrinterDevice)); }
public static void createPos() { explorer = new PosExplorer(); DeviceInfo receiptPrinterDevice = explorer.GetDevice("PosPrinter", Properties.Settings.Default.KitchenPrinter); //May need to change this if you don't use a logicial name or use a different one. kitchenPrinter = (PosPrinter)explorer.CreateInstance(receiptPrinterDevice); kitchenPrinter.Open(); kitchenPrinter.Claim(10000); kitchenPrinter.DeviceEnabled = true; }
public Printer(string deviceName = "PosPrinter") { var posExplorer = new PosExplorer(); var deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, deviceName); m_Printer = (PosPrinter)posExplorer.CreateInstance(deviceInfo); m_Printer.Open(); m_Printer.Claim(500); m_Printer.DeviceEnabled = true; m_Printer.RecLetterQuality = true; m_Printer.MapMode = MapMode.Metric; m_Printer.ClearOutput(); }
private void Inventory_Searcher_Load(object sender, EventArgs e) { //pos try { DeviceInfo di = explorer.GetDevice(DeviceType.Scanner); activeScanner = (Scanner)explorer.CreateInstance(di); activeScanner.Open(); activeScanner.Claim(1000); activeScanner.DeviceEnabled = true; activeScanner.DataEvent += new DataEventHandler(activeScanner_DataEvent); activeScanner.ErrorEvent += new DeviceErrorEventHandler(activeScanner_ErrorEvent); activeScanner.DecodeData = true; activeScanner.DataEventEnabled = true; } catch (Exception erty) { } }
/// <summary> /// Connect to Msr Device and Get Card Data. /// </summary> public void Connect() { myExplorer = new PosExplorer(); DeviceInfo device = myExplorer.GetDevice("Msr", "MagTekMSR_Encrypted"); //device= myExplorer.GetDevices()[0]; /// <summary> /// To check if device found or not /// </summary> if (device != null) { Disconnect(); myMsr = (Msr)myExplorer.CreateInstance(device); try { myMsr.Open(); if (myMsr.Claimed == false) { myMsr.Claim(1000); } myMsr.DeviceEnabled = true; } catch { } myMsr.DataEventEnabled = true; myMsr.DecodeData = true; myMsr.DataEvent += new DataEventHandler(myMsr_DataEvent); } else { throw new Exception("pos device not founded"); //return; } myExplorer.DeviceAddedEvent += new DeviceChangedEventHandler(myExplorer_DeviceAddedEvent); myExplorer.DeviceRemovedEvent += new DeviceChangedEventHandler(myExplorer_DeviceRemovedEvent); //myMsr.DataEvent += new DataEventHandler(myMsr_DataEvent); }
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 InitPrinter() { string strLogicalName = "PosPrinter"; try { //Create PosExplorer PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; try { deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName); m_Printer = (PosPrinter)posExplorer.CreateInstance(deviceInfo); } catch (Exception) { PrinterReady = false; return; } //Open the device 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. m_Printer.DeviceEnabled = true; m_Printer.RecLetterQuality = false; m_Printer.MapMode = MapMode.Metric; PrinterReady = true; } catch (PosControlException) { PrinterReady = false; } }
private void InitCashDrawer() { //<<<step1>>>--Start //Use a Logical Device Name which has been set on the SetupPOS. string strLogicalName = "CashDrawer"; try { //Create PosExplorer PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; try { deviceInfo = posExplorer.GetDevice(DeviceType.CashDrawer, strLogicalName); m_Drawer = (CashDrawer)posExplorer.CreateInstance(deviceInfo); } catch (Exception) { //Nothing can be used. //ChangeButtonStatus(); return; } //Open the device //Use a Logical Device Name which has been set on the SetupPOS. m_Drawer.Open(); //Get the exclusive control right for the opened device. //Then the device is disable from other application. //m_Drawer.Claim(1000); //Enable the device. m_Drawer.DeviceEnabled = true; } catch (PosControlException) { //Nothing can be used. //Nothing can be used. //ChangeButtonStatus(); } //<<<step1>>>--End }
protected void SetDisplay() { string strLogicalName = "LineDisplay"; PosExplorer posExplorer = null; try { posExplorer = new PosExplorer(); } catch (Exception ex) { MessageBox.Show(ex.Message + " Cant call POSEXPLORE() function! " + Environment.NewLine + " Skipped if Epson TM - M30 have not been installed."); goto End; } deviceInfo = posExplorer.GetDevice(DeviceType.LineDisplay, strLogicalName); m_Display = (LineDisplay)posExplorer.CreateInstance(deviceInfo); m_Display.Open(); m_Display.Claim(1000); m_Display.DeviceEnabled = true; try { var val = GetMessages(); m_Display.CharacterSet = 932; m_Display.CreateWindow(1, 0, 1, 20, 1, Encoding.GetEncoding(932).GetByteCount(val)); m_Display.MarqueeFormat = DisplayMarqueeFormat.Walk; m_Display.MarqueeType = DisplayMarqueeType.Init; m_Display.MarqueeRepeatWait = 1000; m_Display.MarqueeUnitWait = 100; m_Display.DisplayText(val, DisplayTextMode.Normal); m_Display.MarqueeType = DisplayMarqueeType.Left; } catch (PosControlException pe) { MessageBox.Show(pe.Message); } End: { // } }
/// <summary> /// The processing code required in order to enable to use of service is written here. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frmStep1_Load(object sender, System.EventArgs e) { //<<<step1>>>--Start //Use a Logical Device Name which has been set on the SetupPOS. string strLogicalName = "PosPrinter"; try { //Create PosExplorer PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; try { deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName); m_Printer = (PosPrinter)posExplorer.CreateInstance(deviceInfo); } catch (Exception) { ChangeButtonStatus(); return; } //Open the device 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. m_Printer.DeviceEnabled = true; } catch (PosControlException) { ChangeButtonStatus(); } //<<<step1>>>--End }
public bool init(bool asasynchronous) //初始化 { async = asasynchronous; string strLogicalName = "PosPrinter"; try { PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; try { deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName); m_Printer = (PosPrinter)posExplorer.CreateInstance(deviceInfo); } catch (Exception) { //return false; } m_Printer.Open(); m_Printer.Claim(1000); m_Printer.DeviceEnabled = true; m_Printer.RecLetterQuality = true; m_Printer.MapMode = MapMode.Metric; } catch (Exception ex) { System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + ex.ToString() + "\r\n"); return(false); } return(true); }
private void SetPrinter(string strLogicalName) { try { //Create PosExplorer PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; try { //if (m_Printer != null || m_Printer.State == ControlState.Error) if (m_Printer != null) { ReleasePrinter(); } deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName); m_Printer = (PosPrinter)posExplorer.CreateInstance(deviceInfo); if (m_Printer != null) { ClaimPrinter(); HavePrinter = true; } //if (m_Printer.Claimed) m_Printer.Release(); } catch (Exception) { HavePrinter = false; m_Printer = null; //ChangeButtonStatus(); //return; } } catch (PosControlException) { HavePrinter = false; //ChangeButtonStatus(); } }
private void Panel_productos_Faltantes_Bodega_Load(object sender, EventArgs e) { this.dataGrid1.CurrentCell = (DataGridViewCell)null; this.dataGrid1.DataSource = (object)this.depot.MissingProducts().DefaultView; // setCheckAllBtn(); try { //Create PosExplorer PosExplorer posExplorer = new PosExplorer(); try { posPrinter = posExplorer.CreateInstance(posExplorer.GetDevice(DeviceType.PosPrinter, "PosPrinter")) as PosPrinter; posPrinter.Open(); } catch (Exception) { } } catch (PosControlException) { //Nothing can be used. MessageBox.Show("No se tuvo acceso a la impresora o al cajon"); } }
public void PrintToPos() { PosExplorer explorer = null; DeviceInfo _device; PosPrinter _oposPrinter; string LDN = ""; explorer = new PosExplorer(); _device = explorer.GetDevice(DeviceType.PosPrinter, LDN); _oposPrinter = (PosPrinter)explorer.CreateInstance(_device); _oposPrinter.Open(); _oposPrinter.Claim(10000); _oposPrinter.DeviceEnabled = true; // normal print //_oposPrinter.PrintNormal(PrinterStation.Receipt, "yourprintdata"); // pulse the cash drawer pin pulseLength-> 1 = 100ms, 2 = 200ms, pin-> 0 = pin2, 1 = pin5 // _oposPrinter.PrintNormal(PrinterStation.Receipt, (char)16 + (char)20 + (char)1 + (char)pin + (char)pulseLength); // cut the paper //_oposPrinter.PrintNormal(PrinterStation.Receipt, (char)29 + (char)86 + (char)66); // print stored bitmap //_oposPrinter.PrintNormal(PrinterStation.Receipt, (char)29 + (char)47 + (char)0); }
//prepare printer private void prepare() { string strLogicalName = "PosPrinter"; try { PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; try { deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName); m_Printer = (PosPrinter)posExplorer.CreateInstance(deviceInfo); } catch (Exception e) { Console.WriteLine("error2"); Console.WriteLine(e); } m_Printer.Open(); m_Printer.Claim(1000); m_Printer.DeviceEnabled = true; } catch (PosControlException e) { Console.WriteLine("error3"); Console.WriteLine(e); } finally { //release(); } }
public void Initialize() //初始化 { lock (mInitializeLock) { string strLogicalName = "PosPrinter"; if (mInitialized) { return; } PosExplorer posExplorer = null; try { posExplorer = new PosExplorer(); } catch (Exception e) { System.Console.WriteLine(e.InnerException.ToString()); } DeviceInfo deviceInfo = null; try { deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName); } catch (Exception getDeviceEx) { Console.WriteLine("当前系统中不止一台PosPrinter设备,请设置默认的PosPrinter类型打印机.", "打印机异常"); System.IO.File.AppendAllText(LogTxt, "PrintHelper.Initialize():" + DateTime.Now.ToString() + getDeviceEx.ToString() + "\r\n"); OutputOverHandle(); InitialError(getDeviceEx, "请运行: 开始 -> 程序 -> EPSON OPOS ADK for .NET -> SetupPOS for OPOS.NET\n" + "检查PosPrinter打印机配置,然后重启打印机"); return; } try { mPrinter = (PosPrinter)posExplorer.CreateInstance(deviceInfo); } catch (Exception createInstanceEx) { Console.WriteLine("创建PosPrinter设备实例失败.", "打印机异常"); System.IO.File.AppendAllText(LogTxt, "PrintHelper.Initialize():" + DateTime.Now.ToString() + createInstanceEx.ToString() + "\r\n"); OutputOverHandle(); InitialError(createInstanceEx, "请运行: 开始 -> 程序 -> EPSON OPOS ADK for .NET -> SetupPOS for OPOS.NET\n" + "检查PosPrinter打印机配置,然后重启打印机"); return; } AddOutputCompleteEvent(mPrinter); AddErrorEvent(mPrinter); AddStatusUpdateEvent(mPrinter); try { mPrinter.Open(); } catch (PosControlException openEx) { System.IO.File.AppendAllText(LogTxt, "PrintHelper.Initialize():" + DateTime.Now.ToString() + openEx.ToString() + "\r\n"); if (openEx.ErrorCode == ErrorCode.Illegal) { Console.WriteLine("打印机已经被打开!", "打印机故障"); } else { Console.WriteLine("打开打印机失败!", "打印机故障"); } OutputOverHandle(); InitialError(openEx); return; } try { mPrinter.Claim(1000); } catch (PosControlException claimEx) { System.Diagnostics.Debug.WriteLine(claimEx.ToString()); System.IO.File.AppendAllText(LogTxt, "PrintHelper.Initialize():" + DateTime.Now.ToString() + claimEx.ToString() + "\r\n"); Console.WriteLine("请检查打印机电源、连接线及退出其他正在占用打印机的程序,并稍后重试", "打印机故障"); OutputOverHandle(); InitialError(claimEx); return; } try { mPrinter.DeviceEnabled = true; } catch (PosControlException enabledEx) { System.Diagnostics.Debug.WriteLine(enabledEx.ToString()); System.IO.File.AppendAllText(LogTxt, "PrintHelper.Initialize():" + DateTime.Now.ToString() + enabledEx.ToString() + "\r\n"); Console.WriteLine("试图使能打印机失败", "打印机故障"); OutputOverHandle(); InitialError(enabledEx); return; } try { mPrinter.RecLetterQuality = true; mPrinter.MapMode = MapMode.Metric; } catch (PosControlException setModeEx) { System.Diagnostics.Debug.WriteLine(setModeEx.ToString()); System.IO.File.AppendAllText(LogTxt, "PrintHelper.Initialize():" + DateTime.Now.ToString() + setModeEx.ToString() + "\r\n"); OutputOverHandle(); InitialError(setModeEx); return; } mInitialized = true; } }
private void siparisYazdir_Click(object sender, EventArgs e) { FileInfo fisAyarInfo = new FileInfo(fisDosyasi); if (fisAyarInfo.Length == 0) { functions.hataMesajiGoster("İlk Önce Fiş Ayarları Yapmanız Gerekmektedir !"); fisAyarları.close = true; functions.formKapatAc(new fisAyarları()); } else { if (siparisListView.Items.Count > 0) { PosPrinter posPrinter; PosExplorer explorer = new PosExplorer(); DeviceInfo deviceInfo = explorer.GetDevice(DeviceType.PosPrinter); posPrinter = (PosPrinter)explorer.CreateInstance(deviceInfo); posPrinter.Open(); posPrinter.Claim(500); posPrinter.DeviceEnabled = true; posPrinter.PrintNormal(PrinterStation.Slip, string.Format("\t\t{0}{1}", sAdi.ToUpper(), Environment.NewLine)); posPrinter.PrintNormal(PrinterStation.Slip, string.Format("\t\t{0}{1}\t\t\t{2}{1}", adres, Environment.NewLine, ilIlce)); posPrinter.PrintNormal(PrinterStation.Slip, string.Format("\t\t{0}\t{1}{2}", vDaire.ToUpper(), vNo, Environment.NewLine)); posPrinter.PrintNormal(PrinterStation.Slip, string.Format("{0} TARİH:\t{1}{0} SAAT :\t{2}", Environment.NewLine, DateTime.Now.ToString().Split(' ')[0], DateTime.Now.ToString().Split(' ')[1])); posPrinter.PrintNormal(PrinterStation.Slip, string.Format("{0} -----------------------------------------------------------------------------{0}", Environment.NewLine)); posPrinter.PrintNormal(PrinterStation.Slip, string.Format(" ÜRÜN ADI\t\tÜRÜN ADEDİ\t\tÜRÜN FİYATI{0}{0}", Environment.NewLine)); for (int i = 0; i < siparisListView.Items.Count; i++) { if (siparisListView.Items[i].SubItems[0].Text.Length > 15) { siparisAdi = siparisListView.Items[i].SubItems[0].Text.Substring(0, 16); } else if (siparisListView.Items[i].SubItems[0].Text.Length < 15) { for (int j = 0; j < 15 - siparisListView.Items[i].SubItems[0].Text.Length; j++) { siparisAdi += " "; } } siparisAdi = siparisListView.Items[i].SubItems[0].Text + siparisAdi; posPrinter.PrintNormal(PrinterStation.Slip, string.Format(" {0}\t\t{1}\t\t\t{2}{3}", siparisAdi, siparisListView.Items[i].SubItems[1].Text, siparisListView.Items[i].SubItems[2].Text, Environment.NewLine)); siparisAdi = null; } posPrinter.PrintNormal(PrinterStation.Slip, string.Format("{0}{0} -----------------------------------------------------------------------------{0}", Environment.NewLine)); posPrinter.PrintNormal(PrinterStation.Slip, string.Format("\tTOPLAM FİYAT:\t{0}", label2.Text)); posPrinter.CutPaper(100); //posPrinter.Close(); FileInfo fi = new FileInfo(siparisDoc); if (fi.Length > 0) { JObject siparis = JObject.Parse(File.ReadAllText(siparisDoc)); int count = siparis.Count; for (int i = 0; i < siparisListView.Items.Count; i++) { siparis.Add(new JProperty((i + 1 + count).ToString(), new JObject(new JProperty("urunAdi", siparisListView.Items[i].SubItems[0].Text), new JProperty("urunAdedi", siparisListView.Items[i].SubItems[1].Text), new JProperty("urunFiyat", siparisListView.Items[i].SubItems[2].Text.Split(' ')[0]), new JProperty("saat", DateTime.Now.ToString().Split(' ')[1])))); } dosyayaYaz(siparis); } else { JObject obje = new JObject(); for (int i = 0; i < siparisListView.Items.Count; i++) { obje.Add(new JProperty((i + 1).ToString(), new JObject(new JProperty("urunAdi", siparisListView.Items[i].SubItems[0].Text), new JProperty("urunAdedi", siparisListView.Items[i].SubItems[1].Text), new JProperty("urunFiyat", siparisListView.Items[i].SubItems[2].Text.Split(' ')[0]), new JProperty("saat", DateTime.Now.ToString().Split(' ')[1])))); } dosyayaYaz(obje); } siparisListView.Items.Clear(); siparisSayisi = null; label2.Text = "0 ₺"; } } }
public void openConnection() { SesionEnt.printerEnabled = false; string logicalName = "PosPrinter2"; PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; try { deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, logicalName); } catch (Exception exceptionX) { throw exceptionX; } if (deviceInfo != null) { try { posPrinter = (PosPrinter)posExplorer.CreateInstance(deviceInfo); } catch (Exception exceptionX) { throw exceptionX; } try { posPrinter.Open(); posPrinter.PowerNotify = PowerNotification.Enabled; } catch (Exception exceptionX) { throw exceptionX; } if (posPrinter != null) { try { posPrinter.Claim(1000); } catch (PosControlException posControlExceptionX) { throw posControlExceptionX; } try { posPrinter.DeviceEnabled = true; } catch (PosControlException posControlExceptionX) { throw posControlExceptionX; } try { posPrinter.RecLetterQuality = false; posPrinter.MapMode = MapMode.Metric; SesionEnt.posPrinter = posPrinter; SesionEnt.printerEnabled = true; } catch (PosControlException posControlExceptionX) { throw posControlExceptionX; } } } }
public Printer(string logicalName, bool connect) { instance = this; if (connect) { this.profile = null; this.deviceStatus = PrintDeviceStatus.Properly; this.PrintStatus = PrintStatus.Stopped; try { DeviceInfo deviceInfo = null; PosExplorer posExplorer = new PosExplorer(); deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, logicalName); device = (PosPrinter)posExplorer.CreateInstance(deviceInfo); device.Open(); device.Claim(1000); device.AsyncMode = false; device.DeviceEnabled = true; device.StatusUpdateEvent += Device_StatusUpdateEvent; device.ErrorEvent += (a, b) => { WriteLog("ERROR - " + b.ToString()); }; WriteLog(""); WriteLog("Drucker initialisiert; Status: " + device.State + device); if (device.RecNearEnd) Device_StatusUpdateEvent(this, new StatusUpdateEventArgs(25)); this.connected = connect; } catch (Exception ex) { string s = ex.Source; try { if (device != null) device.Release(); } catch { } throw new Exception("Verbindung zum Drucker fehlgeschlagen.", ex); } } else { this.connected = false; this.PrintStatus = PrintStatus.Stopped; this.deviceStatus = PrintDeviceStatus.Properly; } }