爱普生TM-U220印刷垃圾字符

人气:602 发布:2022-09-22 标签: .net c# .NET .NET2.0

问题描述

你好朋友请帮助我,我已经忍受了2个星期以来的痛苦。 我做了一个POS申请餐馆。使用Win-form,c#,。Net。 打印机Epson TM-U220用我的应用程序打印垃圾字符。 但是当我试图打印普通文本时通过Epson TM-U220上的记事本,它也是垃圾。 现在神奇的是餐厅所有者有一个旧的POS打印应用程序,只有这个Epson TM-U220正确打印。 我的应用程序还可以使用其他Inkjet& amp;激光打印机 我真的很沮丧&困惑我已经重新安装了打印机的驱动程序,但仍然是相同的情况..任何人都可以帮助我。 听到我的打印代码 Rajkumar

 使用系统;  使用 System.Collections.Generic;  使用 System.ComponentModel;  使用 System.Data;  使用 System.Drawing;  使用 System.Text;  使用 System.Windows.Forms;  使用 Telerik.WinControls;  使用 System.Windows;  使用 System.Runtime.InteropServices;  使用 Telerik.WinControls.UI;  使用 System.Data.OleDb;  使用 CrystalDecisions.CrystalReports.Engine;  使用 System.IO;  使用 System.Collections;  使用 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 笔(Color.Black, 2  .5f); 字体drawFont = 新字体(  Arial , 10 ); 字体drawFont2 = 新字体(  Arial黑色, 10 ); 字体drawFont3 = 新字体(  Lucida控制台, 8 );        #region第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 笔(Color.Black, 1 );     e.Graphics.DrawString( 酒店名称 ,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 ),新点( 300 , 135 ));  e.Graphics.DrawString(  Bill No:,radGridView3.Font,Brushes。黑色,新 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。黑色,新 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( 详情数量率,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 ),新点( 300 , 150 ));       #endregion      #region draw column $     e.Graphics.DrawString(radGridView3.Columns [ 1 ]。HeaderText,radGridView3.Font,Brushes.Black, new  RectangleF( 100  + < span class =code-digit> 180 , 100 , 180 ,radGridView3.Rows [ 0 ]。高度),str);   width =  100  +  180 ;  height =  130 ;   //  变量i在类级声明,如果e.hasmorepages为真,则保留i的值   while (i <  radGridView3.Rows.Count) {  if (height >  e.MarginBounds.Height) { height =  100 ;  width =  100 ;  e.HasMorePages =  true ;   return ; }  身高+ =  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  + < span class =code-digit> 20 ,height, 180 , 26 ), STR);  e.Graphics.DrawString(radGridView3.Rows [i] .Cells [ 2 ]。Value.ToString(),radGridView3.Font,Brushes.Black,  new  RectangleF( 20  +  170  + < span class =code-digit> 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( 总计: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 ,身高+  28 , 250 , 26 ),str);  e.Graphics.DrawString(txtgrtotal.Text.ToString(),drawFont3,Brushes.Black, new  RectangleF( 250 ,身高+ 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( 折扣:Rs。,radGridView3.Font,Brushes .Black, new  RectangleF( 165 ,height + 26 + 11 + 2, 250 , 26 ),str);  e.Graphics.DrawString( 总计: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(  ------谢谢-------,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 点( 20 ,身高+  20 ), new  Point( 300 ,height + < span class =code-digit> 20 ));    i =  0 ;    #endregion        #region第3列       #endregion    }    catch  {}    }     私人  void  button1_Click( object  sender,EventArgs e) {   printDocument1.Print();  } 

解决方案

这是Epson TM-U220手册的链接: http://www.icscale.com/TECH%20MANUALS/ TMU220_TRG_RevD.pdf [ ^ ] 根据手册,Epson上有一个DIP开关,用于确定打印机的控制方式。在一个位置,它通过您安装的两种类型的Windows驱动程序之一进行控制。另一方面,它是通过ESC / POS专用命令语言中的不需要驾驶员的直接命令来控制的。 无需进一步深入研究,我敢打赌ESC / POS语言是通过RS232端口或类似的简单ASCII字符。如果您的打印机设置为该模式,它可能会将其作为要打印的字符发送的每个字节解释 - 因此您看到的是giberish。 查看是什么安装打印机的端口并尝试在cmd shell中键入这样的内容: echohello> lpt1 看看你的打印机上是否打印hello。 如果你仍然需要支持旧的POS应用程序,然后你需要更改你的打印功能,只需将字符写入打印机端口。 如果你不需要为了支持旧的POS应用程序,然后尝试翻转拨码开关,看看它是否解决了你的问题。

你可以将餐馆申请发送到 bhanuchinna513 @gmail。 COM

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

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();   
        
        }

解决方案

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.

can u send restaurant application to bhanuchinna513@gmail.com

194