473,385 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1.  class Program
  2.     {
  3.         public const short FILE_ATTRIBUTE_NORMAL = 0x80;
  4.         public const short INVALID_HANDLE_VALUE = -1;
  5.         public const uint GENERIC_READ = 0x80000000;
  6.         public const uint GENERIC_WRITE = 0x40000000;
  7.         public const uint CREATE_NEW = 1;
  8.         public const uint CREATE_ALWAYS = 2;
  9.         public const uint OPEN_EXISTING = 3;
  10.  
  11.         [DllImport("kernel32.dll", SetLastError = true)]
  12.         static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess,
  13.             uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition,
  14.             uint dwFlagsAndAttributes, IntPtr hTemplateFile); 
  15.         static void Main(string[] args)
  16.         {
  17.  
  18.             IntPtr ptr = CreateFile("LPT1", GENERIC_WRITE, 0,
  19.                      IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);
  20.  
  21.             if (ptr.ToInt32() == -1)
  22.             {
  23.                 Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());
  24.             }
  25.             else
  26.             {
  27.                 string command = "test";
  28.                 FileStream lpt = new FileStream(ptr, FileAccess.ReadWrite);
  29.                 Byte[] buffer = new Byte[2048];
  30.  
  31.                 buffer = System.Text.Encoding.ASCII.GetBytes(command);
  32.           //    lpt.Write(buffer, 0, buffer.Length);
  33.                 lpt.Write(GetDocument(), 0, GetDocument().Length);
  34.                 lpt.Close();
  35.             }
  36.  
  37.         }
  38.         private static byte[] GetDocument()
  39.         {
  40.             using (var ms = new MemoryStream())
  41.             using (var bw = new BinaryWriter(ms))
  42.             {
  43.               //  bw.Write((char)0x1B);//esc
  44.                 //  bw.Write('@');
  45.              //   bw.Write((char)0x0C);//ff
  46.  
  47.                 bw.Write('a');
  48.                 bw.Write((byte)66);
  49.                 bw.Write((byte)3);
  50.  
  51.                 bw.Flush();
  52.  
  53.                 return ms.ToArray();
  54.             }
  55.         }
  56.     }
When I am using the method GetDocument() printer is not responding, but it prints only text when I call the buffer variable:
Expand|Select|Wrap|Line Numbers
  1. lpt.Write(buffer, 0, buffer.Length);
Sep 7 '12 #1
1 5607
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?
Sep 9 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Joe | last post by:
I'm using Python 2.4 on Windows XP SP2. I'm trying to receive a command line argument that is a newline (\n) Here is the command line to use sample.py "\n" Here is a sample.py script
7
by: N U | last post by:
How to program your own escape sequence using basic functions available in C?
2
by: junky_fellow | last post by:
N869 " Each of these escape sequences shall produce a unique implementation-defined value which can be stored in a single char object. The external representations in a text file need not be...
4
by: Guadala Harry | last post by:
I need to place the following into a string... How can I properly escape the % " / < and > characters? <table width="100%" border="0" cellspacing="0" cellpadding="4px" class="hfAll"></Table> ...
1
by: h babu | last post by:
I have a need to send escape sequences to the printer on the client side from a web page using .NET. - Is this first of all possible from a web page rendered through .aspx? - Can this be achieved...
1
by: Jeff | last post by:
Hey asp.net 2.0 I'm developing a website using visual web developer 2005 express. In this project I'm trying to connect to the aspnetdb.mdf database (the project's own database created by...
6
by: sloan | last post by:
I have a fairly simple RegEx code below. I am given a file name, (which I don't control) , and need to change a folder name in it. The code below is choking on the filename not being...
9
by: Rui Maciel | last post by:
Is there a function which takes a string and outputs another equivalent string where all the non-ASCII characters (i.e., escapable characters) are replaced with the respective escape character...
5
by: vlsidesign | last post by:
The printf function returns "warning: unknown escape sequence: \040" for a backslash-space combination. If the ascii decimal number for space is 32 and the backslash is 92, why this particular...
0
by: santoshnavle | last post by:
i m printing on a dot matrix printer.. I m generating a text file and printing that text file... While printing i want some part of the text to be printed in condensed form say small font and other...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.