Write Escape Sequence for Epson printer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zlristovski
    New Member
    • Sep 2012
    • 5

    Write Escape Sequence for Epson printer

    I want to send control codes for Epson printer with c# application, I wrote some code, I have the connection with the printer, but when I am sending codes it not responding. On the other side, I found Java application for sending control codes, from that app some of the codes is working but not all of them. For example I want to use ESC EM 66 control code but when I am sending this code, printer not responding or just print the code in numbers. Can anyone to help me to find solution for this problem? I read many articles but without help.

    The code who I use is:
    Code:
     class Program
        {
            public const short FILE_ATTRIBUTE_NORMAL = 0x80;
            public const short INVALID_HANDLE_VALUE = -1;
            public const uint GENERIC_READ = 0x80000000;
            public const uint GENERIC_WRITE = 0x40000000;
            public const uint CREATE_NEW = 1;
            public const uint CREATE_ALWAYS = 2;
            public const uint OPEN_EXISTING = 3;
    
            [DllImport("kernel32.dll", SetLastError = true)]
            static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess,
                uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition,
                uint dwFlagsAndAttributes, IntPtr hTemplateFile); 
            static void Main(string[] args)
            {
               
                IntPtr ptr = CreateFile("LPT1", GENERIC_WRITE, 0,
                         IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
    
                if (ptr.ToInt32() == -1)
                {
                    Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
                }
                else
                {
                    string command = "test";
                    FileStream lpt = new FileStream(ptr, FileAccess.ReadWrite);
                    Byte[] buffer = new Byte[2048];
                    
                    buffer = System.Text.Encoding.ASCII.GetBytes(command);
              //    lpt.Write(buffer, 0, buffer.Length);
                    lpt.Write(GetDocument(), 0, GetDocument().Length);
                    lpt.Close();
                }
              
            }
            private static byte[] GetDocument()
            {
                using (var ms = new MemoryStream())
                using (var bw = new BinaryWriter(ms))
                {
                  //  bw.Write((char)0x1B);//esc
                    //  bw.Write('@');
                 //   bw.Write((char)0x0C);//ff
                
                    bw.Write('a');
                    bw.Write((byte)66);
                    bw.Write((byte)3);
    
                    bw.Flush();
    
                    return ms.ToArray();
                }
            }
        }
    When I am using the method GetDocument() printer is not responding, but it prints only text when I call the buffer variable:
    Code:
    lpt.Write(buffer, 0, buffer.Length);
  • zlristovski
    New Member
    • Sep 2012
    • 5

    #2
    ESC EM control code for Epson printer

    I want to know how to use ESC EM 82 control code for epson printer in C# application, I don't know how to correct call this code. I am colling FF control code and sending to the printer, that is succeed, but I don't know how to call ESC EM 82 or any other code?
    Last edited by zmbd; Sep 9 '12, 01:53 PM. Reason: (Z) Merged threads as this is a duplicate post.. Zlristovski please see PM

    Comment

    Working...