3
Reply

POS for .NET

Jan Montano

Jan Montano

16 years ago
23.5k
Hi guys,

Have any of you had experience using Microsft POS for .Net? I'm trying to print on an EPSON TM U220 POS printer. But everytime I call PosPrinter.PrintNormal, I get an error saying "It is not initialized" and that's the only info I could get. I could print on the pos printer normally (via textpad or windows test print). I just can't get it to print from my .net Code. I'm not sure if I'm missing something.

Unfortunately, I have no luck googling the error. Here's the sample code I've been using.

            string strLogicalName = "PosPrinter";
            PosPrinter m_Printer = null;

            try
            {
                //Create PosExplorer
                PosExplorer posExplorer = new PosExplorer();
           
                DeviceInfo deviceInfo = null;
               
                try
                {
                    //DeviceCollection deviceCollection = posExplorer.GetDevices(DeviceType.PosPrinter);
                  
                    deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter,strLogicalName);
                   
                    // this call returns a valid object
                    m_Printer =(PosPrinter)posExplorer.CreateInstance(deviceInfo);
                   
                   
                }
                catch(Exception 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.
                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();
            }

            try
            {
                //As using the PrintNormal method, send strings to a printer, and print it
                //[\n] is the standard code for starting a new line.

                // ************ ERROR OCCURS HERE ************* IT IS NOT INITIALIZED
                m_Printer.PrintNormal(PrinterStation.Receipt,"Hello OPOS for .Net\n");
            }
            catch(PosControlException exception)
            {
                MessageBox.Show(exception.ErrorCode.ToString());
            }

Answers (3)