Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends please help me , i have been suffering with this since 2 weeks .

I have made a POS application for a restaurant . with Win-form ,c# ,.Net .
The printer Epson TM-U220 is printing the junk characters with my app.
However when i tried to print a normal text through notepad on Epson TM-U220 , it was junk too
.


Now the magic is The restaurant owner has an old POS application for bill printing with that only this Epson TM-U220 prints correctly .


One more thing my app prints fine with other Inkjet & Laser printers


I am really frustrated & confused i have reinstalled the drivers for printer but still the same situation ..Can anyone please help me .



Hear is my code for printing

Rajkumar



C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using System.Windows;
using System.Runtime.InteropServices; 
using Telerik.WinControls.UI;
using System.Data.OleDb;
using CrystalDecisions.CrystalReports.Engine;
using System.IO;
using System.Collections;
using System.Configuration;















    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {

            try
            {


                int width = 0;
                int height = 0;
                int x = 0;
                int y = 0;
                int rowheight = 0;
                int columnwidth = 0;

                StringFormat str = new StringFormat();
                str.Alignment = StringAlignment.Near;
                str.LineAlignment = StringAlignment.Center;
                str.Trimming = StringTrimming.EllipsisCharacter;
                Pen p = new Pen(Color.Black, 2.5f);
                Font drawFont = new Font("Arial",10);
                Font drawFont2 = new Font("Arial Black", 10);
                Font drawFont3 = new Font("Lucida Console", 8);
          
                
               

                #region Draw Column 1

                int xb ;

                 if(radGridView3.Rows.Count ==1 )
                 
                 
                 {xb =  200;}
                 
                 
                 else
                 
                 
                 
                 
                 {xb= radGridView3.Rows.Count* 100 ;}








                 float[] dashValues = { 2, 2, 2, 2 };
                 Pen blackPen = new Pen(Color.Black, 1);


               
                 e.Graphics.DrawString("  Hotel Name       ", drawFont2, Brushes.Black, new RectangleF(76, 76, 300, 26), str);
             
                e.Graphics.DrawString("   -----------------------CASH MEMO-----------------------", radGridView3.Font, Brushes.Black, new RectangleF(10,100, 500, 26), str);
                blackPen.DashPattern = dashValues;
                e.Graphics.DrawLine(blackPen, new Point(20, 135), new Point(300, 135));
                e.Graphics.DrawString(" Bill No: ", radGridView3.Font, Brushes.Black, new RectangleF(17, 110, 400, 26), str);
                 e.Graphics.DrawString(txtbid.Text.ToString(), radGridView3.Font, Brushes.Black, new RectangleF(55,110, 250, 26), str);
                e.Graphics.DrawString(" W No: ", radGridView3.Font, Brushes.Black, new RectangleF(245, 110, 400, 26), str);
                  e.Graphics.DrawString(txtlogid.Text.ToString(), radGridView3.Font, Brushes.Black, new RectangleF(285,110, 250, 26), str);
                
                
                e.Graphics.DrawString("Particulars                        Quantity                   Rate ", radGridView3.Font, Brushes.Black, new RectangleF(20,130, 400, 26), str);
                //e.Graphics.DrawLine(Pens.Black, 20, 150, 300, 150);

               
                blackPen.DashPattern = dashValues;
                e.Graphics.DrawLine(blackPen, new Point(20, 150), new Point(300, 150));
                
               
                
                #endregion

                #region Draw column 2

              
                e.Graphics.DrawString(radGridView3.Columns[1].HeaderText, radGridView3.Font, Brushes.Black, new RectangleF(100 + 180, 100, 180, radGridView3.Rows[0].Height), str);

                width = 100 + 180;
                height = 130;
                //variable i is declared at class level to preserve the value of i if e.hasmorepages is true
                while (i < radGridView3.Rows.Count)
                {
                    if (height > e.MarginBounds.Height)
                    {
                        height = 100;
                        width = 100;
                        e.HasMorePages = true;
                        return;
                    }

                    height += 26;
                    //e.Graphics.DrawRectangle(Pens.Black, 100, height, 180, 26);
                    e.Graphics.DrawString(radGridView3.Rows[i].Cells[0].Value.ToString(), radGridView3.Font, Brushes.Black, new RectangleF(20, height, 180, 26), str);

                    //e.Graphics.DrawRectangle(Pens.Black, 100 + 180, height, 180, 26);
                    e.Graphics.DrawString(radGridView3.Rows[i].Cells[1].Value.ToString(), radGridView3.Font, Brushes.Black, new RectangleF(20 + 130, height, 180, 26), str);
                    e.Graphics.DrawString(radGridView3.Rows[i].Cells[3].Value.ToString(), radGridView3.Font, Brushes.Black, new RectangleF(20 + 130 + 20, height, 180, 26), str);
                    e.Graphics.DrawString(radGridView3.Rows[i].Cells[2].Value.ToString(), radGridView3.Font, Brushes.Black, new RectangleF(20 + 170 + 60 , height, 180, 26), str);
                  
                    //e.Graphics.DrawString(radGridView3.Rows[i].Cells[4].Value.ToString(), radGridView3.Font, Brushes.Black, new RectangleF(20 + 20 + 170 + 40 + 40, height, 180, 26), str);


                    width += 180;
                    i++;
                }



                e.Graphics.DrawString(System.DateTime.Now.ToString(), radGridView3.Font, Brushes.Black, new RectangleF(30, height+26, 250, 26), str);

                if (txtdescount.Text == "")
                { e.Graphics.DrawString(radTextBox1.Text.ToString(), drawFont3, Brushes.Black, new RectangleF(250, height + 28, 250, 26), str);

                 e.Graphics.DrawString("Grand Total :Rs.", radGridView3.Font, Brushes.Black, new RectangleF(165, height + 26, 250, 26), str);
                
                
                }
                else
                { 
                  
                
                 e.Graphics.DrawString(txtdescount.Text.ToString(), drawFont3, Brushes.Black, new RectangleF(250, height + 26+10+2+3, 250, 26), str);
                 e.Graphics.DrawString(radTextBox1.Text.ToString(), drawFont3, Brushes.Black, new RectangleF(250, height + 28, 250, 26), str);
                 e.Graphics.DrawString(txtgrtotal.Text.ToString(), drawFont3, Brushes.Black, new RectangleF(250, height + 28+11+11+2, 250, 26), str);
                 e.Graphics.DrawString(" Total :Rs.", radGridView3.Font, Brushes.Black, new RectangleF(165, height + 26, 250, 26), str);
                 e.Graphics.DrawString(" Discount:Rs.", radGridView3.Font, Brushes.Black, new RectangleF(165, height + 26+11+2, 250, 26), str);
                 e.Graphics.DrawString("Grand Total :Rs.", radGridView3.Font, Brushes.Black, new RectangleF(165, height + 26 + 11+11+2, 250, 26), str);
                
                
                }
                
                
              
                //e.Graphics.DrawLine(Pens.Black, 20, height + 20, 300, height + 20);
                e.Graphics.DrawString("------Thank You------- ", radGridView3.Font, Brushes.Black, new RectangleF(85, height + 50+11, 250, 26), str);

                //float[] dashValues = { 2, 2, 2, 2 };
                //Pen blackPen = new Pen(Color.Black, 1);
                blackPen.DashPattern = dashValues;
                e.Graphics.DrawLine(blackPen, new Point(20, height + 20), new Point(300, height + 20));


                i = 0;
                #endregion



                #region Draw Column 3

              

                #endregion


            }

            catch { }



        }

       

      private void button1_Click(object sender, EventArgs e)
        {
           

            printDocument1.Print();   
        
        }
Posted

Here's a link to the manual for an Epson TM-U220:

http://www.icscale.com/TECH%20MANUALS/TMU220_TRG_RevD.pdf[^]

Per the manual, there is a dip switch on the Epson which determines how the printer is controlled. In one position, it is controlled via one of two types of windows drivers that you install. In the other it is controlled via direct command in the "ESC/POS" propietary command language that "doesn't require a driver".

Without digging into it further, I'd bet the "ESC/POS" language is simple ASCII characters over an RS232 port or something similar. If your printer is set in that mode, it will probably interpret every byte it is sent as a character to print -- thus the giberish you see.

Check out what port the printer is installed on and try typing something like this in the cmd shell:

echo "hello" > lpt1

And see if that doesn't print "hello" on your printer.

If you still need to support the old POS application, then you'll need to change your print function to just write characters to the printer port.

If you don't need to support the old POS application, then try flipping the dip switch and see if it fixes your problem.
 
Share this answer
 
Comments
rajkumar9867 31-May-12 18:23pm    
I think you are right m trying to find dip switch combination in the manual thanks
rajkumar9867 4-Jun-12 2:09am    
You are great thanks for your help ... My app is printing fine now ..
TRK3 4-Jun-12 13:51pm    
I am happy I could help.
can u send restaurant application to
bhanuchinna513@gmail.com
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900