[Lazarus] no driver and com printing [SOLVED]

zeljko zeljko at holobit.net
Mon Feb 20 12:18:40 CET 2012


On Monday 20 of February 2012 11:50:42 fikri zainul wrote:
> > 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-ide.org/pipermail/lazarus/attachments/20120220/b861b1ba/attachment-0003.html>


More information about the Lazarus mailing list