Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

C# POS.NET PrintNormal() Issue 'It is not Initialized'

By: a guest on Feb 24th, 2012  |  syntax: None  |  size: 2.12 KB  |  views: 102  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. void K8POSPrint()
  2.         {
  3.  
  4.             /// <summary>
  5.             /// PosPrinter object
  6.             /// </summary>
  7.             PosPrinter m_Printer = null;
  8.  
  9.             try
  10.             {
  11.  
  12.                 //Use a Logical Device Name which has been set on the SetupPOS.
  13.                 string strLogicalName = "PosPrinter";
  14.                 try
  15.                 {
  16.                     //Create PosExplorer
  17.                     PosExplorer posExplorer = new PosExplorer();
  18.  
  19.                     DeviceInfo deviceInfo = null;
  20.  
  21.                     try
  22.                     {
  23.                         // Device Info is not null when the printer has the logical name
  24.                         deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName);
  25.                         m_Printer = (PosPrinter)posExplorer.CreateInstance(deviceInfo);
  26.                     }
  27.                     catch (Exception ExDevice)
  28.                     {
  29.                     }
  30.  
  31.                     //Open the device
  32.                     m_Printer.Open();
  33.  
  34.                     //Get the exclusive control right for the opened device. Then the device is disable from other application.
  35.                     m_Printer.Claim(1000);
  36.  
  37.                         //Enable the device.
  38.                     m_Printer.DeviceEnabled = true;
  39.  
  40.                     //    ////CheckHealth.
  41.                     //m_Printer.CheckHealth(Microsoft.PointOfService.HealthCheckLevel.Interactive);
  42.  
  43.                     //    //As using the PrintNormal method, send strings to a printer, and print it [n] is the standard code for starting a new line.
  44.                     /// Current Issue Next Line thows an exception - 'It is not initialized'
  45.                     m_Printer.PrintNormal(PrinterStation.Receipt, "Hey Now OPOS for .NETn");
  46.                     // the next line would throw the exception 'The specified station is not mounted.'
  47.                     // m_Printer.PrintNormal(PrinterStation.Slip,"Hey Now Slip OPOS.NETn");
  48.  
  49.                 }
  50.                 catch (PosControlException)
  51.                 {
  52.  
  53.                 }
  54.             }
  55.             catch (Exception ex)
  56.             {
  57.  
  58.             }
  59.  
  60.         }