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

                _printer.Release();
                _printer.Close();
                _printer = null;
            }
        }
예제 #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();
                }
            }
        }
예제 #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
 }
예제 #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;
                }
            }
        }
예제 #5
0
 public void Stop()   //停止打印
 {
     mStop = true;
     if (m_Printer != null)
     {
         m_Printer.Close();
     }
 }
예제 #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();
     }
 }
예제 #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
     {
     }
 }
예제 #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();
        }
예제 #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();
        }
예제 #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);
            }

        }
예제 #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
        }
예제 #15
0
 public void Cerrar()
 {
     _oPrinter.Close();
 }
예제 #16
0
 private static void DisconnectFromPrinter(PosPrinter printer)
 {
     printer.Release();
     printer.Close();
 }
예제 #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("打印机正常!");
        }