 |
|
 |
Hello rob tillaart,
I want to send character by LPR. I'm writing driver for Epson Printer but how to send command Printer and command LPR.
Can you help me? I need to send character in order to command printer by print server.
Thanks,
Hung
|
|
|
|
 |
|
 |
Hi Hung,
Please take a look at An LPR client in C#[^] .
The democode can send a file to an device by means of the LPR/LPD protocol. You can create small files, eg. a file with codes to reset a printer, and send these to the printer or you could extend the interface of the class to allow a string to be send over the protocol. If you do the latter please let me know as I might include it in the demo code.
Hopes this helps you enough,
regards, Rob
|
|
|
|
 |
|
 |
Hi Rob,
Thank for answering my question.
I saw your demo. At present, I can send a file (Text mode) to printer by means of the LPR/LPD protocol. But i don't know how to edit file include command Printer to print on Printer (EX: Epson Printer). I tryed editing content of file (include command to control Epson printer) but not active, I wonder whether this way is true? can you give idea?
Thanks,
Hung
|
|
|
|
 |
|
 |
Hi Hung,
Quite some questions arise :
- What is the type of the Epson printer?
- Can you give examples of the characters you want to send to the printer and their purpose?
Are these "binary" escape sequences?
Where do you want to insert these codes? begin, end or anyplace within the file?
Or do you want to send commands to the printer between files.
(e.g. a reset command)
- Can you provide an (URL to the) specification of the Epson printer?
- Does the Epson printer print the textfiles correctly?
- Does the Epson printer support LPR directly or do you send the file via a printserver?
(and printer connected by USB, parallel to this server?)
- Does the Epson printer support command codes over TCP/IP?
Note: input-channels of printers sometimes differ in behavour.
Regards,
Rob
|
|
|
|
 |
|
 |
Hi rob tillaart,
Thank for answering my question.
I want to send file to Epson TM-U220(Paralell gate) printer. I need to command (EPS/pos).(EX: reset, feed(LF), select font( ESC !),...)
I need to send textfile via a printserver and printer connected by parallel to this server.
Epson printer supports command codes over TCP/IP.
Thanks,
Hung
|
|
|
|
 |
|
 |
Hi Hung,
According to http://www.icscale.com/TECH%20MANUALS/TMU220_TRG_RevD.pdf[^] the EPSON printer has a parallel interface or a TCP IP interface, but not both at the same time or am I incorrect.
I would make a copy of the textfile (e.g. COPY.TXT) to be printed and insert the ESC-codes in the proper place and then send COPY.TXT to the printer.
If this does not work try the following:
put the printer in het HEX mode to see exact context of whats received
2) send COPY.TXT to the printer over TCP/IP by means of my C# LPR code.
2) send COPY.TXT to the printer over TCP/IP by means of the windows LPR command.
3) send COPY.TXT directly to the printer over the parallel port. So skip the printserver completely.
If (3) doesn't work => there probably is something wrong with the file or the hardware of the printer
If (2) doesn't work and (3) does => the printserver is interfering somehow.
If (1) doesn't work and (2) and (3) does => there probably is a bug in my code.
Succes,
Rob
|
|
|
|
 |
|
 |
Hi Rob,
I insert the ESC-codes in textfile to send printer but not work. I send string directly to the printer by pararell port (no printserver, no LPR protocol) is ok. I don't understand. can you help me?
Hung
|
|
|
|
 |
|
 |
Hi Hung,
Test 3 = OK => The printer works
Test 2 = NOK => printerserver interferes somehow
Q1: Did you sent the textfile to the printserver with my LPR class or with the windows LPR application? Please try both and report results separately.
Q2: What are you using as printserver, Windows/Solaris/Linux/other?. Which version?
Q3: Can you halt the spooling of the printserver, so you can compare the sent file with the received file by the printserver. What are the results?
Regards,
Rob
|
|
|
|
 |
|
 |
Hi Rob,
Thank you for answering my question.
I used Window OS. I send textfile to the printserver with your LPR class. I used to RFC 1179 (LPR protocol) but I don't find command of LPR which permit me insert command printer with filetext. Can you help me?
Thank, Hung
|
|
|
|
 |
|
 |
Hi Hung,
There is no LPR command that permits inserting commands as far as I know. My class doesn't allow it either and I do not intend to extend it such way. The reason: LPR is a transportprotocol that does not change the content of the printfile (See RFC 1179). So your application should first create or modify the printfile before sending it by means of LPR. It is almost as simple as copying a file.
Your answers are very short and so questions remain:
Q1: You state that you sent the textfile with my LPR class. Did it work?
Q2: As asked before, have you tried the windows LPR application? It is a commandline tool. Start a dosbox and type LPR /? for explanation of the parameters. Please send the manually changed textfile through the commandline LPR to the printserver. What are the results?
Q3: Can you halt the spooling of the printserver, so you can compare the sent file with the received file by the printserver. What are the results?
Please send one answer per question.
Regards,
Rob
|
|
|
|
 |
|
 |
Hi Hung,
sample code to prepend escape sequences to an existing file. adapt to your need.
Regards,
Rob
public static void Modify(string path, string path2, string escapes)
{
StreamReader sr = new StreamReader(path);
StreamWriter sw = new StreamWriter(path2);
sw.Write(escapes);
while (sr.Peek() > 0) sw.Write(sr.ReadLine());
sr.Close();
sw.Close();
}
modified on Wednesday, April 7, 2010 4:10 AM
|
|
|
|
 |
|
 |
Hi Rob,
Thanks for relying.
I saw Modify function. I think this is ok. But I need one filetext (include escape sequences and string,..). can you send me one filetext ( PCL HP). Thanks.
Hung
|
|
|
|
 |
|
 |
Hi Hung,
Inserting escape codes / characters in a textfile is really elementary coding. The code below is just one way to do it, define strings that hold a 'complete printer function'.
public static void CreateFile()
{
string INITPRINTER = string.Format("{0}@", (char)27);
// Other escape strings can be defined in a similar way
StreamWriter sw = new StreamWriter(@"C:\temp.txt");
sw.Write(INITPRINTER); // at the begin to be sure printer is in defined condition
sw.WriteLine("put your text here");
sw.WriteLine("put your text here");
sw.Write(INITPRINTER); // insert escape code in another place,
// can also be another escape code
sw.WriteLine("put your text here");
sw.Write(INITPRINTER); // and at the end to reset the printer for next job.
sw.Close();
}
The ESC/POS commands for your TM-U220 printer see:
http://postechgroup.com/updata/support/drivers/EPSON/FAQ_ESCPOS.pdf[^]
Regards,
Rob
|
|
|
|
 |
|
 |
Hi Rob
Thanks for replying.
Can i combine CreateFile() function with your class LPR C# ?
If ok, how do i do ? Can you help me?
Thanks
Hung
|
|
|
|
 |
|
 |
Hi Hung,
yes you can combine them, but I will not extend the LPR class in such way as I explained earlier. I have mailed you 'sample-code' of all the building blocks you need so now it is up to you. By integrating it yourself you will get better understanding of the code of your project so you will be able to maintain it.
Succes,
Rob
|
|
|
|
 |
|
 |
While there is some small issues to deal with, overall this is a great project to understand LPD/LPR protocol. Thanks a lot...
|
|
|
|
 |
|
|
 |
|
 |
Hi Rob,
If possible, hope you can support your LPD in Windows service mode, so that it can be automatically started once Windows is started, and with command-line flag parameter we can easily do start/stop/pause/continue/restart. I think LPD running in the Windows service mode is much more useful.
May be this webpage is useful to your development:
http://www.codeproject.com/csharp/svcmgr.asp[^]
Best Regards
mswumei
|
|
|
|
 |
|
 |
If I keep sending some big files to it from one or two DOS prompt by Windows XP LPR command, it gives me error message "Error: print server unreachable or specified printer does not exist".
mswumei
|
|
|
|
 |
|
 |
Hi Mswumei,
Your observation is correct. The current implementation only handles one connection at a time. To handle multiple connections simultaneous, the procedure 'StartListen' should start a background thread to handle a request. If time permits I will implement it.
If you want to code this yourself, be aware that every thread should have its own local variables to prevent interference between multiple connections.
Regards,
Rob
|
|
|
|
 |
|
 |
Hi rob,
Hope you will support it soon in your next release, thanks.
With your current release, I also got problem with only one session, for example, with my testing if I submit printing jobs (each job file size is about 3 MB) continuously by run a *.bat bacth job, it returns error "Error: print server unreachable or specified printer does not exist".
It works fine only if I pause few seconds after previuos print submission.
Best Regards
mswumei
|
|
|
|
 |
|
 |
I tested with current version and found it does not support binary mode.
With latest LPR command provided by Windows XP, I have specified option flag "-o l" for binary mode. Can you suport binary mode with your new release, thanks.
|
|
|
|
 |
|
 |
Hi,
To add support for accepting binary files only a small change is needed in the core of the LPR handling (region LPR subcommand around line 340-350). Instead of the StreamWriter() a BinaryWriter() should be used, code should become:
// TODO: support 'no byte counting'
// receive the file
Stream fstr = new FileStream(path + filename, FileMode.Create);
BinaryWriter bw = new BinaryWriter(fstr);
while (size > 0)
{
int cnt = nws.Read(buffer, 0, BUFSIZE);
size -= cnt;
if (size < 0) cnt--; // strip last \0
bw.Write(buffer, 0, cnt);
}
bw.Close();
fstr.Close();
I did a quick test by LPR-ing a .exe, and after receive I renamed it and it still worked. I will include this patch in the next version,
Thanx for your remark,
rob
|
|
|
|
 |
|
 |
I would like to implement this function.
a user upload a file through browser to "server", the server will try to print this file:
IF printed, then the user will receive a return message, including when the file was printed, the printer name and total pages printed.
If Not printed, then the user should receive a return message with ERROR code.
Any idea? Please help!
Rgds
LJ
|
|
|
|
 |
|
 |
Hi,
Take a look at my LPR client demo => http://www.codeproject.com/csharp/lpr.asp. It may be not 100% directly useable but use it as a starting point. The LPR client sends a printable file to a printer that supports the LPD protocol. Currently it prints the file in the background.
You should put the LPR code in the "upload handler" after the upload is completed. If the job is send to the printer you can notify the user.
The easiest way is to create an LPR client that runs in the foreground. The client waits until all transfer is done. Then the webserver sends the result. If the LPR cannot connect an errormessage is sent to the user.
Alternative is to print in the background and mail the user when the job is ready.
Please note that LPR does not convert Word or other formats to printable formats. It just sends the file.
Hope this helps a bit,
regards,
rob
|
|
|
|
 |