Ask a questionAsk a question
 

AnswerPOS Printer example in C# 2005

  • Wednesday, October 14, 2009 9:00 AMBaditala Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi All,


    I am new to POS Devlopment.  Plase help me in POS Printer.

    I need an example, which will checks the Printer is connected. enabled and it should print sample. I am using EPSON (POS printer) TM -T881V.

    Please send me C# sample applciation. Thanks in advance.


    • Edited byBaditala Wednesday, October 14, 2009 9:00 AMquestion changed
    •  

Answers

  • Wednesday, October 14, 2009 10:04 AMYortAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    Go to www.epsonexpert.com, register and log in. Go to application development -> OPOS and then scroll down until you find the Epson OPOS for .Net ADK download, and download it.

    That contains the service object (drivers) you need to work with Pos .Net and the Epson printer you are using, and it also contains samples that demonstrate printing (text, images, barcodes, rotation, cutting etc.) as well as handling errors and detecting printer state. There is a seperate sample for each major printer feature, which makes it easy to read the code for just the bit you are interested in. I believe there are samples for both C# and VB .Net.

    You will also need to download the Pos .Net library as well, which you can get here; http://www.microsoft.com/downloads/details.aspx?FamilyID=eaae202a-0fcc-406a-8fde-35713d7841ca&displaylang=en  

    The Pos .Net SDK documentation also contains good developer help for how to use Pos Printers, and that combined with the Epson samples should get you a long way.

    Good luck !
    • Marked As Answer byYortAnswererFriday, October 30, 2009 3:41 AM
    • Proposed As Answer byYortAnswererWednesday, October 14, 2009 7:17 PM
    •  

All Replies

  • Wednesday, October 14, 2009 10:04 AMYortAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,

    Go to www.epsonexpert.com, register and log in. Go to application development -> OPOS and then scroll down until you find the Epson OPOS for .Net ADK download, and download it.

    That contains the service object (drivers) you need to work with Pos .Net and the Epson printer you are using, and it also contains samples that demonstrate printing (text, images, barcodes, rotation, cutting etc.) as well as handling errors and detecting printer state. There is a seperate sample for each major printer feature, which makes it easy to read the code for just the bit you are interested in. I believe there are samples for both C# and VB .Net.

    You will also need to download the Pos .Net library as well, which you can get here; http://www.microsoft.com/downloads/details.aspx?FamilyID=eaae202a-0fcc-406a-8fde-35713d7841ca&displaylang=en  

    The Pos .Net SDK documentation also contains good developer help for how to use Pos Printers, and that combined with the Epson samples should get you a long way.

    Good luck !
    • Marked As Answer byYortAnswererFriday, October 30, 2009 3:41 AM
    • Proposed As Answer byYortAnswererWednesday, October 14, 2009 7:17 PM
    •  
  • Wednesday, October 14, 2009 11:19 AMBaditala Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Yort.


    Thanks for the information shared. Now my question is, I want to make my POS App as generic for all Devices(of any vendor type eg. Epson,...).
    Is it possible to do that using POS SDK. If so sugesst me the way to achive this.


    Thanks in Advance.
    • Marked As Answer byBaditala Wednesday, October 14, 2009 12:30 PM
    • Unmarked As Answer byBaditala Wednesday, October 14, 2009 12:30 PM
    •  
  • Wednesday, October 14, 2009 11:47 AMBaditala Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Yort,

    This is sample code, which I had written to print the BMP in EPSON using POS. While runnin this I stucked with error message.


    Error Msg:  (PostControl Exception was unhandeled)
    The specified station does not support bitmap printing.


    Code :

    oPrinter.RecLetterQuality =

    true;
    Bitmap bitmap = (Bitmap)Bitmap.FromFile(@"C:\Test.bmp");
    int imageWidth = bitmap.Width;
    int imageHeight = bitmap.Height;
    Bitmap retVal = new Bitmap(imageWidth, imageHeight, PixelFormat.Format1bppIndexed);
    BitmapData data = retVal.LockBits(new Rectangle(0, 0, imageWidth, imageHeight), ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed);

     

    for (int y = 0; y < imageHeight; y++)

    {

     

    byte[] scan = new byte[(imageWidth + 7) / 8];

     

    for (int x = 0; x < imageWidth; x++)

    {

     

    Color c = bitmap.GetPixel(x, y);

     

    if (c.GetBrightness() >= 0.5) scan[x / 8] |= (byte)(0x80 >> (x % 8));

    }

     

    Marshal.Copy(scan, 0, (IntPtr)((int)data.Scan0 + data.Stride * y), scan.Length);

    }

    retVal.UnlockBits(data);

    retVal.Save(

    "Test.bmp");

    oPrinter.SetBitmap(1,

    PrinterStation.Slip, "Test.bmp", PosPrinter.PrinterBitmapAsIs, PosPrinter.PrinterBitmapCenter);

     

    //MessageBox.Show("GO");

    oPrinter.PrintNormal(

    PrinterStation.Slip, (char)27 + "|1B");

     

    MessageBox.Show("Done");

    oPrinter.PrintBitmap(

    PrinterStation.Slip, "Test.bmp", PosPrinter.PrinterBitmapAsIs, PosPrinter.PrinterBitmapCenter);

     

    MessageBox.Show("Done");



  • Wednesday, October 14, 2009 12:26 PMBaditala Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Yort,


    I have downloaded the Epson OPOS for .Net ADK and I ran the Sample applicaton. But still getting error while opening the Printer. though the printer is plugged in and ON. but still i am getting this error. Plase help in fixing this.

    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 ex)

    {

    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);  //Throwing exception here

     

    //Enable the device.

    m_Printer.DeviceEnabled =

    true; //Throwing exception here

    }

     

    catch(PosControlException ex)

    {}



    Error  Meesage : Microsoft.PointOfService.ErrorCode.NoHardware
    Error Code : 5008
    Message  : "The power supply of the device is off." 

    Thanks in advance..

  • Wednesday, October 14, 2009 12:42 PMBaditala Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Yort,


    Issue resolved. Thanks.

    Now I am able to Print the Sample output using POS Printer.
  • Wednesday, October 14, 2009 7:13 PMYortAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Yort.


    Thanks for the information shared. Now my question is, I want to make my POS App as generic for all Devices(of any vendor type eg. Epson,...).
    Is it possible to do that using POS SDK. If so sugesst me the way to achive this.


    Thanks in Advance.

    Using Pos .Net you can make your application work with any device which has a compatible service object available (if you write your code correctly). The same goes for OPOS and JavaPOS... they give you device independence, but only where a service object exists (or you build your own) and so long as you write your code so it properly handles errors, checks device capabilities, and doesn't use device specific commands etc.
  • Wednesday, October 14, 2009 7:17 PMYortAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    It's entirely possible the Slip station on your printer doesn't support bitmaps... in fact, I don't recall seeing an Epson TM-88IV printer with a slip station built in so it may be you don't have a slip station at all (although I could be wrong, I haven't seen every piece of hardware there is !).

    Try changing your code so it uses PrinterStation.Receipt everywhere where you have PrinterStation.Slip.

    Are you actually trying to print a bitmap to the slip station specifically, or do you just choose a station at random ?

    Also, please keep your questions one question to a thread (so the answer/proposed answer system works properly), and keep the threads seperate. Thanks.
    • Marked As Answer byBaditala Thursday, October 22, 2009 11:18 AM
    • Unmarked As Answer byBaditala Wednesday, October 28, 2009 4:41 AM
    •  
  • Sunday, October 25, 2009 10:15 AMWhatMSDN Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Im sitting here with the same problem as you. How did you resolve the problem??
  • Friday, November 06, 2009 9:33 AMvelthune Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Baditala!
    I've your same problem.. can you explain me in wich way have you solved the problem? I just need a sample code to begin! ):
    How can I select a printer from my pc?

    Thank in advance! 
  • Tuesday, November 10, 2009 5:52 AMBaditala Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Velthune,

    this is code which I used to Print sample using Epson TM-T88IV.

     

    //in Form_Loading event
    DeviceInfo
    oDevicePrinter = myExplorer.GetDevice(DeviceType.PosPrinter, "POSPrinter");
    oPrinter = (
    PosPrinter)myExplorer.CreateInstance(oDevicePrinter);
    try
    {
    if (oPrinter != null)
    {
    oPrinter.Open();
    oPrinter.Claim(1000);
    oPrinter.DeviceEnabled =
    true;
    }
    }
    catch (Exception exPrinter)
    {
       MessageBox.Show(exPrinter.ToString(), "Warning");
    }


    // Print Button Click Event handle this code.

    try

     

    {
    oPrinter.PrintNormal(
    PrinterStation.Receipt, txtPrint.Text + DateTime.Now.ToString());
    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.ToString());
    }


    First configure your printer using ESPON Setup(to COM Port).
    Then try this code.