Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-02

no driver and com printing [SOLVED]

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

fikri zainul
Show quoted text 11 lines
Hi all, I have a printer (Epson TM U220D, plugged in COM1 port) and my OS Linux/Fedora10 I can't found the driver printer for this OS (only for SUSE and Ubuntu that Epson provided). (Using Generic/TextOnly driver, not working) So, I can't do printing process for my lazarus application. My first question is, [?] Do you know how to handle this situation? (Driver problem)

Yes, set it in cups properly, but DO NOT use Generic Text, use Raw printing driver and set proper ESC/POS.
This is how I do that:
1.Prepare TStringList with commands and data to be printed. ? eg:
? MyPosList := TStringList.Create;
? MyPosList.Add(SEQUENCE_FOR_PRINTER_INITIALIZATION(read escposmanuals)) ? MyPosList.Add('Hello world line 1');
? MyPosList.Add('Hello world line 2');
? MyPosList.Add('Hello world line 3');
? MyPosList.Add(SEQUENCE_FOR_CUTTER (if there's cutter)); ? MyPosList.SaveToFile(YourTempFileOrWhatever);
? MyFunctionForPosPrinting(YourTempFileOrWhatever) (look below)

2.Save it to temp file eg. /tmp/myposprinter_XXXXX.txt 3.call cups to print it to desired pos printer (via Libc.System()/TProcess/ExecuteProcess) -> lpr -PMYPOSPRINTER /tmp/myposprinter_XXXXX.txt

I'm using ExecuteProcess()
http://www.freepascal.org/docs-html/rtl/sysutils/executeprocess.html

4.Delete temp file.

Show quoted text 6 lines
Temporary, I try to print via command line (Terminal/Dos command like) to the printer using command line 'cat textfile.log > /dev/ttyS0', and it's worked. Something printed.

DO NOT USE IT EVER. It's direct port printing and you can have troubles on user machines with permissions, selinux etc etc.
Cups handles that fine.

Show quoted text 7 lines
And the (second) question is, [?] How to apply this command (multiple lines sometimes) in Lazarus Code? (By pressing from a button maybe) Can you all give me some codes to execute?

1.Use ESC/POS docs (or any other docs for your pos printer, but I guess that TMU220D is pure ESC/POS printer.
2.Do as I explained above.

zeljko

---------------------------------------------------- Thank you very much to Zeljko for your answers
----------------------------------------------------

Here what I do exactly:

PRINTER PART

1. Plug my serial TM-U220D printer to my Linux Fedora 10 computer
2. Add Printer using CUPS (Common Unix Printing System) by typing http://127.0.0.1:631 on address bar mozilla
3. Setting Device to Serial Port #1
4. Setting Baud rate to 9600 ( my friend recommended )
5. Setting Make/Manufacture by RAW (thanks to Zeljko, I'm using Generic text before but won't work)
6. Setting Model to Raw Queue

LAZARUS PART

1. Add Printer4Lazarus package
2. Add printers in Uses (Uses Printers)
3. Create method

procedure PrintRawString(const S:String);
var
? Written: Integer;
begin
??? Printer.Write(S[1], Length(S), Written);
end;

2. Use the method

procedure TForm1.PrintItClick(Sender: TObject);
begin
? Printer.Title := ?My Title?;
? Printer.RawMode := True;
? Printer.BeginDoc;
? PrintRawString(?Print This String?);
? Printer.EndDoc;
end;

3. We can add some ESC/p codes to string.

PrintRawString(Chr(27)+Chr(97)+Chr(1)+?Print This String?);? //center alignment

------------------------------------------------------------------------------------------------

That's All :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120220/58ee1427/attachment.html>

Reply by email

zeljko
to fikri zainul
fikri zainul wrote 97 lines
> Hi all, > I have a printer (Epson TM U220D, plugged in COM1 port) and my OS > Linux/Fedora10 I can't found the driver printer for this OS (only for > SUSE and Ubuntu that Epson provided). (Using Generic/TextOnly driver, > not working) > > So, I can't do printing process for my lazarus application. > > My first question is, > > [?] Do you know how to handle this situation? (Driver problem) Yes, set it in cups properly, but DO NOT use Generic Text, use Raw printing driver and set proper ESC/POS. This is how I do that: 1.Prepare TStringList with commands and data to be printed. eg: MyPosList := TStringList.Create; MyPosList.Add(SEQUENCE_FOR_PRINTER_INITIALIZATION(read escposmanuals)) MyPosList.Add('Hello world line 1'); MyPosList.Add('Hello world line 2'); MyPosList.Add('Hello world line 3'); MyPosList.Add(SEQUENCE_FOR_CUTTER (if there's cutter)); MyPosList.SaveToFile(YourTempFileOrWhatever); MyFunctionForPosPrinting(YourTempFileOrWhatever) (look below) 2.Save it to temp file eg. /tmp/myposprinter_XXXXX.txt 3.call cups to print it to desired pos printer (via Libc.System()/TProcess/ExecuteProcess) -> lpr -PMYPOSPRINTER /tmp/myposprinter_XXXXX.txt I'm using ExecuteProcess() http://www.freepascal.org/docs-html/rtl/sysutils/executeprocess.html 4.Delete temp file. > Temporary, I try to print via command line (Terminal/Dos command like) to > the printer using command line 'cat textfile.log > /dev/ttyS0', > > and it's worked. Something printed. DO NOT USE IT EVER. It's direct port printing and you can have troubles on user machines with permissions, selinux etc etc. Cups handles that fine. > And the (second) question is, > > [?] How to apply this command (multiple lines sometimes) in Lazarus Code? > > (By pressing from a button maybe) Can you all give me some codes to > execute? 1.Use ESC/POS docs (or any other docs for your pos printer, but I guess that TMU220D is pure ESC/POS printer. 2.Do as I explained above. zeljko ---------------------------------------------------- Thank you very much to Zeljko for your answers ---------------------------------------------------- Here what I do exactly: PRINTER PART 1. Plug my serial TM-U220D printer to my Linux Fedora 10 computer 2. Add Printer using CUPS (Common Unix Printing System) by typing http://127.0.0.1:631 on address bar mozilla 3. Setting Device to Serial Port #1 4. Setting Baud rate to 9600 ( my friend recommended ) 5. Setting Make/Manufacture by RAW (thanks to Zeljko, I'm using Generic text before but won't work) 6. Setting Model to Raw Queue LAZARUS PART 1. Add Printer4Lazarus package 2. Add printers in Uses (Uses Printers) 3. Create method procedure PrintRawString(const S:String); var Written: Integer; begin Printer.Write(S[1], Length(S), Written); end; 2. Use the method procedure TForm1.PrintItClick(Sender: TObject); begin Printer.Title := ?My Title?; Printer.RawMode := True; Printer.BeginDoc; PrintRawString(?Print This String?); Printer.EndDoc; end;

Note that raw printing won't work with all widgetsets (via Printer object), so that's why I use file for Esc/Pos.

zeljko

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120220/b861b1ba/attachment.html>

Reply by email

patspiper
to zeljko
zeljko wrote 16 lines
On Monday 20 of February 2012 17:02:20 patspiper wrote: > On 20/02/12 13:18, zeljko wrote: > > Note that raw printing won't work with all widgetsets (via Printer > > object), so that's why I use file for Esc/Pos. > > That's a surprise! Why and which widgetsets? eg. qt

I have never used qt, but can't it use CUPS (as gtk does)?

This brings up another question: Is the communication of the printer object (not under qt) bidirectional? If not, is it in theory possible?

Stephano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120220/e47113f4/attachment.html>

Reply by email

zeljko
to patspiper
patspiper wrote 12 lines
On 20/02/12 18:33, zeljko wrote: > On Monday 20 of February 2012 17:02:20 patspiper wrote: > > On 20/02/12 13:18, zeljko wrote: > > > Note that raw printing won't work with all widgetsets (via Printer > > > > > > object), so that's why I use file for Esc/Pos. > > > > That's a surprise! Why and which widgetsets? > > eg. qt I have never used qt, but can't it use CUPS (as gtk does)?

Yes it can, but I don't want to ifdef such code, qt works on windows, linux, mac and others .... so it has it's own QPrinter class.

This brings up another question: Is the communication of the printer object (not under qt) bidirectional? If not, is it in theory possible?

dunno

zeljko
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120220/02453e52/attachment.html>

Reply by email