Solved

Using a POS-printer (EPSON TM-U210B) in Delphi-app.

Posted on 2001-08-16
6
7,355 Views
Last Modified: 2007-11-27
Hi,

I am developing an application that uses the EPSON TM-U210B printer. This is a POS-printer (POS=Point Of Sales).

On the EPSON-website, I have found the specific driver and also some example source code to access the printer's functions.

However, these examples are written in Visual Basic.

For example, the printer has a special function to cut off the paper. In VB the code is like:

Printer.FontSize = 10
Printer.FontName = "control"
Printer.Print "F"
Printer.EndDoc

OK, I have tried to translate this into Delphi-code by using these lines:

with Printer do
begin
  BeginDoc;
  Canvas.Font.Size := 10;
  Canvas.Font.Name := 'control';
  Canvas.TextOut(0,0,'F');
  EndDoc;
end;

However, this is not working very well. Maybe I made a big mistake by trying to translate the VB-code without asking any help to you guys...

Furthermore, by using the canvas it seems like the printer is very fast running out of memory. Someway it is only possible to add about 20 lines into the canvas-text, or it will delete the last (few) lines.

I hope there is someone who can help me with this.
If you need to have some additional information, please ask!

Thank you in advance.

RoosieDB
0
Comment
Question by:roosiedb
  • 3
  • 2
6 Comments
 
LVL 40

Accepted Solution

by:
RQuadling earned 200 total points
ID: 6396356
Printing with these printers is a strange affair in Windows.

Whilst you can use the Windows printer drivers, I have found that writing direct to the port to be far easier.

Assuming you have the printing working, then, to get the cutter working, you will need to identify the port that the printer is connected to, open it, send the cutter code and close the port.

Something like ...

var
  Device, Driver, Port: Array[0..255] Of Char;
  DeviceMode: THandle;

ComboBox1.Items.Text := Printer.Printers.Text;
Printer.PrinterIndex := ComboBox1.ItemIndex;

Printer.GetPrinter(Device,Driver,Port,DeviceMode);
Reg := TRegistry.Create;

Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.OpenKey('System\CurrentControlSet\Control\Print\Printers\'+Device+'\',False);
sPort := Reg.ReadString('Port');
Reg.CloseKey;

Then, using standard file writing, send the string

#27 + 'i' for Full Cut
or
#27 + 'm' for Partial Cut.

Regards,

Richard Quadling.
0
 
LVL 3

Expert Comment

by:VSF
ID: 6398522
The best way to print on Matrix printer AFAIK is using writeln commands, it's faster and allow you to use the printer commands, take a look at the following:

//SIMPLE PRINTing WITH WriteLn
procedure TForm1.Button1Click(Sender: TObject);
var
F : TextFile; i : integer;
begin
AssignFile(F,'LPT1');  //Assign the file to the port
Rewrite(F);
Writeln(F,'Test line - 0');
Writeln(F,'Test Line - 1');
Writeln(F, #27#69 + 'Bold Line' + #27#70);
Writeln(F, #15 + 'Compressed Mode Line' + #18);
Writeln(F,#12);        // Eject page
CloseFile(F);
end;


//BETTER PRINTING WITH WriteLn
//Demonstrates the usage of the justify function of the printer!
procedure TForm1.Button1Click(Sender: TObject);
const
  cJustif = #27#97#51;
  cEject = #12;
  { Font Size }
  c10cpi = #18;
  c12cpi = #27#77;
  c17cpi = #15;
  cIExpanded = #14;
  cFExpanded = #20;
  { Font Format }
  cIBold = #27#71;
  cFBold = #27#72;
  cIItalic = #27#52;
  cFItalic = #27#53;
var
  Text: string;
  F: TextFile;
begin
  Text := c10cpi +
  'This is a test for EPSON LX-300 Printer. ' +
  'This procedure ilustrates the usage of the JUSTIFY function of the printer' +
  'without loosing the font format: ' +
  cIbold + 'BOLD - Bold, ' + cFbold +
  cIItalic + 'ITALIC - Italic, ' + cFItalic +
  c17cpi + 'Condensed (17cpi), ' + c10cpi +
  c12cpi + '12 cpi, ' + c10cpi +
  cIExpanded + 'Expanded.' + cFExpanded +
  ' Remenber This is only a simple and incomplete sample' +
  'you can Do much more if u want to.';
  AssignFile(F, 'LPT1');
  Rewrite(F);
  try
  WriteLn(F, cJustif, Texto);
  WriteLn(F, cEject);
  finally
  CloseFile(F);
  end;
end;

Hope this helps!
VSF
www.victory.hpg.com.br

0
 

Author Comment

by:roosiedb
ID: 6403054
It was very difficult to choose between the proposed answers, however, RQuadling's solution worked after I added some code from the other comment. I don't understand because the printer's manual says that #27 + 'f' is cutting off paper, not #27 + 'i' or 'm'... But, as I said, it worked.

I have graded your solution as "average" because I still had to find out what you mean by "using standard file writing" (example?). And I still don't understand why I need to access the registry for just a simple printing job...

I hope you appreciate my honesty here and that you don't kill me???  :-)

Anyway, thank you for your help...
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 40

Expert Comment

by:RQuadling
ID: 6405515
There is a difference between using the windows drivers and writing to the port directly.

In answer to your points though.

The windows drivers uses a wierd font called "Control" to talk to the printer. The characters you send using this font are very specific. And to be honest with you, I've never got them working as easily as I have with the normal control codes. Control codes aka escape sequences/control strings, normally start with an ESC (char 27) and normally contain keyboard enterable characters. But not always. Also, it is sometimes necessary to send NUL (char 0). This can be quite hard for some languages/programming.

The case of the letters is VERY important! F is not f.

ESC 'f' m n, deals with the delay for handling things like cheque printing or any other bit of paper shoved in. (m and n are delays).

I do not know if ESC 'F' is a real sequence for the TM series.

Sorry about the "standard file writing". Should have done an example.

Thanks for the points though.

If I where you, try and get hold of the Operator's manual for your printer. Normally, they contain the control strings in the appendix along with a full description. From what I can tell, the codes, when applicable, have the same meaning across the entire TM series (I've been doing this for around 11 years and that still holds true, but I think the new TM-HL series may not!).

Regards,

Richard Quadling.
0
 

Author Comment

by:roosiedb
ID: 6407790
Maybe that's what I didn't understand quite well: in the manual there was some example in Visual Basic, with something like: printer.font = "Control". And after that: printer.print "F". And now I am not using the Control-font, that explains everything!! Thank you.
0
 

Author Comment

by:roosiedb
ID: 6424446
I have posted another question about this EPSON printer problem. Could you please review this new question for me?

Rgrds,
RoosieDB
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now