Esempio n. 1
0
        public void Dispose()
        {
            if (_printer != null)
            {
                _printer.TransactionPrint(PrinterStation.Receipt, PrinterTransactionControl.Normal);
                _printer.AsyncMode = false;

                _printer.Release();
                _printer.Close();
                _printer = null;
            }
        }
Esempio n. 2
0
        private void DisposePrinter()
        {
            if (m_Printer != null)
            {
                try
                {
                    //Cancel the device
                    m_Printer.DeviceEnabled = false;

                    //Release the device exclusive control right.
                    m_Printer.Release();

                    //Finish using the device.
                    m_Printer.Close();
                }
                catch (PosControlException ex)
                {
                    _logger.LogError(ex, "An error occurred", "frmMain", "DeactivateScanner");
                }
                finally
                {
                    Application.Exit();
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// When the method "closing" is called,
 /// the following code is run.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void ReleasePrinter()
 {
     //<<<step1>>>--Start
     if (m_Printer != null && HavePrinter)
     {
         try
         {
             //Cancel the device
             //m_Printer.DeviceEnabled = false;
             m_Printer.Close();
             //Release the device exclusive control right.
             m_Printer.Release();
             m_Printer   = null;
             HavePrinter = false;
         }
         catch (PosException)
         {
         }
         finally
         {
             //Finish using the device.
             //m_Printer.Close();
             HavePrinter = false;
         }
     }
     //<<<step1>>>--End
 }
Esempio n. 4
0
        private void DeactivatePrinter()
        {
            if (activePrinter != null)
            {
                // We have an active scanner, lets log that we are
                // about to close it.

                try
                {
                    // Close the active scanner
                    activePrinter.Close();
                }
                catch (PosControlException ex)
                {
                    _logger.LogError(ex, "The application received an error", "frmHardwaresetup", "DeactivatePrinter");
                    Helper.ShowMessage("The application received an error  \n" + ex.Message,
                                       "Test Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    // Don't forget to set activeScanner to null to
                    // indicate that we no longer have an active
                    // scanner configured.
                    activePrinter = null;
                }
            }
        }
Esempio n. 5
0
 public void Stop()   //停止打印
 {
     mStop = true;
     if (m_Printer != null)
     {
         m_Printer.Close();
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Cierra la conexion a la impresora y corta el papel
 /// </summary>
 public void Close()
 {
     if (_printer != null)
     {
         _printer.CutPaper(100);
         _printer.Release();
         _printer.Close();
     }
 }
Esempio n. 7
0
 public void Dispose()
 {
     try
     {
         posPrinter.DeviceEnabled = false;
         posPrinter.Release();
         posPrinter.Close();
     }
     catch { } // 握り潰し
 }
 private void DisconnectFromPrinter(PosPrinter printer)
 {
     try
     {
         printer.Release();
         printer.Close();
     }
     catch
     {
     }
 }
Esempio n. 9
0
        private void Panel_productos_Faltantes_Bodega_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (posPrinter != null)
            {
                try
                {
                    //Cancel the device
                    posPrinter.DeviceEnabled = false;

                    //Release the device exclusive control right.
                    posPrinter.Release();
                    //Finish using the device.
                    posPrinter.Close();
                }
                catch (PosControlException)
                {
                    //Finish using the device.
                    posPrinter.Close();
                }
            }

            dataGrid1.Dispose();
        }
Esempio n. 10
0
 public void Close()
 {
     try
     {
         m_Printer.DeviceEnabled = false;
         m_Printer.Release();
     }
     catch (PosControlException)
     {
     }
     finally
     {
         m_Printer.Close();
     }
 }
 public void UnloadPrinter()
 {
     try
     {
         if (m_Printer == null)
         {
             return;
         }
         m_Printer.Release();
         m_Printer.Close();
     }
     catch (PosControlException)
     {
         Debug.WriteLine("Printer cannot unload, perhaps its turned off? Or not connected?");
     }
 }
        public void Dispose()
        {
            if (m_Printer != null)
            {
                try
                {
                    //Cancel the device
                    m_Printer.DeviceEnabled = false;

                    //Release the device exclusive control right.
                    m_Printer.Release();
                }
                catch (PosControlException)
                {
                }
                finally
                {
                    //Finish using the device.
                    m_Printer.Close();
                }
            }
            Release();
        }
Esempio n. 13
0
        public void print(String PrintString)
        {

            try
            {
                string myString;

                _printer.Open();
                _printer.Claim(1000);
                _printer.AsyncMode = false; //Must be False!!!!!!!!
                _printer.DeviceEnabled = true;

                myString = PrintString.Replace("ESC", Convert.ToChar(27).ToString()) + Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString();

                _printer.PrintNormal(PrinterStation.Receipt, myString);

                //_printer.PrintNormal(PrinterStation.Receipt, Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString());

                //_printer.PrintNormal(PrinterStation.Receipt, Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString());

                //_printer.PrintNormal(PrinterStation.Receipt, Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString());

                //_printer.PrintNormal(PrinterStation.Receipt, Convert.ToChar(13).ToString() + Convert.ToChar(10).ToString());

                _printer.CutPaper(90);

                _printer.DeviceEnabled = false;
                _printer.Release();
                _printer.Close();

            }
            catch (Exception ex)
            {
               // MessageBox.Show(ex.Message);
            }

        }
Esempio n. 14
0
        /// <summary>
        /// When the method "closing" is called,
        /// the following code is run.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmStep1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //<<<step1>>>--Start
            if (m_Printer != null)
            {
                try
                {
                    //Cancel the device
                    m_Printer.DeviceEnabled = false;

                    //Release the device exclusive control right.
                    m_Printer.Release();
                }
                catch (PosControlException)
                {
                }
                finally
                {
                    //Finish using the device.
                    m_Printer.Close();
                }
            }
            //<<<step1>>>--End
        }
Esempio n. 15
0
 public void Cerrar()
 {
     _oPrinter.Close();
 }
Esempio n. 16
0
 private static void DisconnectFromPrinter(PosPrinter printer)
 {
     printer.Release();
     printer.Close();
 }
Esempio n. 17
0
        public void Initialize(PosPrinter mPrinter)
        {
            PosExplorer posExplorer    = null;
            DeviceInfo  deviceInfo     = null;
            string      strLogicalName = "Printer";

            try
            {
                //Create PosExplorer
                posExplorer = new PosExplorer();

                try
                {
                    deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName);
                }
                catch (Exception e)
                {
                    mSend("当前系统中不止一台Printer设备,请设置默认的Printer类型打印机. 打印机异常");
                    mSend("前往 C:\\Program Files\\epson\\OPOS for .NET\\SetupPOS,运行 Epson.opos.tm.setpos.exe ,更改默认实例名为'Printer'");
                    System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + e.ToString() + "\r\n");
                    return;
                }
                try
                {
                    mPrinter = (PosPrinter)posExplorer.CreateInstance(deviceInfo);
                }
                catch (Exception e)
                {
                    mSend("创建PosPrinter设备实例失败.打印机异常");
                    mSend("前往 C:\\Program Files\\epson\\OPOS for .NET\\SetupPOS,运行 Epson.opos.tm.setpos.exe ,检查默认实例名是否为'Printer'");
                    System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + e.ToString() + "\r\n");
                    return;
                }

                AddErrorEvent(mPrinter);
                AddStatusUpdateEvent(mPrinter);

                //Open the device
                try
                {
                    mPrinter.Open();
                }
                catch (PosControlException e)
                {
                    System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + e.ToString() + "\r\n");
                    if (e.ErrorCode == ErrorCode.Illegal)
                    {
                        mSend("打印机已经被打开! 打印机故障");
                    }
                    else
                    {
                        mSend("打开打印机失败! 打印机故障");
                    }
                    return;
                }

                //Get the exclusive control right for the opened device.
                //Then the device is disable from other application.
                try
                {
                    mPrinter.Claim(1000);
                }
                catch (Exception e)
                {
                    mSend("请检查打印机电源、连接线及退出其他正在占用打印机的程序,并稍后重试 打印机故障");
                    System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + e.ToString() + "\r\n");
                    return;
                }

                //Enable the device.
                try
                {
                    mPrinter.DeviceEnabled = true;
                }
                catch (Exception e)
                {
                    mSend("试图使能打印机失败 打印机故障");
                    System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + e.ToString() + "\r\n");
                    return;
                }

                try
                {
                    //Output by the high quality mode
                    mPrinter.RecLetterQuality = true;


                    // Even if using any printers, 0.01mm unit makes it possible to print neatly.
                    mPrinter.MapMode = MapMode.Metric;
                }
                catch (Exception e)
                {
                    System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + e.ToString() + "\r\n");
                    return;
                }
            }
            catch (Exception ex)
            {
                System.IO.File.AppendAllText(@"C:\hot.txt", DateTime.Now.ToString() + ": " + ex.ToString() + "\r\n");
                return;
            }

            try
            {
                mPrinter.DeviceEnabled = false;
                mPrinter.Release();
            }
            catch (PosControlException)
            {
            }
            finally
            {
                mPrinter.Close();
            }
            mSend("打印机正常!");
        }