Recent

Author Topic: Print an image when printer in raw mode.  (Read 30486 times)

Roosters

  • New Member
  • *
  • Posts: 16
Print an image when printer in raw mode.
« on: July 14, 2011, 10:05:29 pm »
I'm printing to a receipt printer (Epson TM-T88ii), I would like to place a logo at the top of the page.

I've searched for a couple of hours to find a way of doing this, but have come up short.

Please note that I cannot use the normal printer driver to print the logo as this driver cuts the paper at the end of every print job.


Is this even possible (when in raw mode) ?

One more question relating to this printer, there is a simple visual basic example of cutting the paper :-

PRINT #1, CHR$(&H1D);"V";CHR$(66);CHR$(0); 'Feeds paper & cut

How would I send similar commands to the printer in Pascal (I've never used Basic)

Thanks in advance.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Print an image when printer in raw mode.
« Reply #1 on: July 15, 2011, 09:12:32 am »
Don't know if you can print a logo; depends on what's in the manual, I'd guess  :)

If my Basic skills are still good enough, the command sends ASCII character 29 (=Hexadecimal 1D), the letter V, ASCII 66 and finally ASCII 0 to the file/device opened with file number 1. What is behind file number 1 depends on the rest of the code.
But if you're already printing using raw mode, you'd just have to insert that sequence of characters at the appropriate spot, I'd think...

Ciao,
BigChimp
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Mando

  • Full Member
  • ***
  • Posts: 181
Re: Print an image when printer in raw mode.
« Reply #2 on: July 15, 2011, 11:18:37 am »
Hi:

I did things like this many years ago.

If the printer is connected to lpt1 do this

Code: [Select]
var myPrinter: TextFile;
..
begin
..
  assignFile(myPrinter,'lpt1');
  rewrite(myPrinter);
  writeln(myPrinter,'Hello world!');
 
   


  closerFile(myPrinter);
end;
And then, use the ESC commands to cut paper, set grapical mode, open cash drawer, etc...

open drawer 27,121,48,55,121 -> write(myPrinter,#27#121#48#55#121);
cut paper 27,"d",3,27,109 -> write(myPrinter,#27'd'#3#27#109);
... and so ...

To print a logo (image) you must send a command to put printer in graphical mode and then send the data of image(mono), after that put printer in text mode again. You must send the bytes that make up the image, but vertically:

if the image is like this: (vertical stripes)

01010101
01010101
01010101
01010101
01010101
01010101
01010101
01010101
 
you must send 0,255,0,255,0,255,0,255 instead of 85,85,85,85,85,85,85,85.

I haven't a handbook with the esc commands for this printer, so i can't help you with more detail.

Regards


« Last Edit: July 15, 2011, 11:30:33 am by Mando »

Roosters

  • New Member
  • *
  • Posts: 16
Re: Print an image when printer in raw mode.
« Reply #3 on: July 17, 2011, 07:18:09 am »
Thanks for all the help, but so far your suggestions have not been successful.

The printer is at a different location (at work), I've found some VB code released by Epson there as well, will try and convert that and ask back for help when I come unstuck.

Thanks.


Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Print an image when printer in raw mode.
« Reply #4 on: July 17, 2011, 08:16:41 am »
I believe you can probably "copy" an bit map image of the logo to the printer, BEFORE you print the receipt.

Roosters

  • New Member
  • *
  • Posts: 16
Re: Print an image when printer in raw mode.
« Reply #5 on: July 18, 2011, 08:56:24 am »
Yes, just found out that's possible using software released by Epson years ago, which is no longer available on their website, the updated version of the software doesn't work with this older printer.

Will look for older software.

Still no joy with the cutting from within Delphi, but I have found some code from a different development system (WinDEV) and some code from VB, will try and convert that.

Will post any solutions.




Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Print an image when printer in raw mode.
« Reply #6 on: July 18, 2011, 09:47:32 am »
Roosters,

I think there'd be a set of Esc(ape characters to send to the printer to put it FIRST in the Graphics mode...then copy the file to the printer....then send Esc(ape characters to the printer to put it back to the Text mode..Then print your receipt.

So, like you need to know from the manual what are the Esc(characters to send, and maybe no need for software.

Likely, the printer makers can inform you, or search the web?

Mando

  • Full Member
  • ***
  • Posts: 181
Re: Print an image when printer in raw mode.
« Reply #7 on: July 18, 2011, 05:47:30 pm »
Elmug:

your answer is exactly the same as I gave.


Rooster:

Why does not work the code you provided?

Probably because ESC sequences are not correct. If you have the code in VB, Put it and you will convert it no problem.

Regards

« Last Edit: July 19, 2011, 09:23:43 am by Mando »

Roosters

  • New Member
  • *
  • Posts: 16
Re: Print an image when printer in raw mode.
« Reply #8 on: July 19, 2011, 06:21:06 pm »
Hi, and thanks for all the help.

The code you supplied now works (a different printer driver was also on com1, I had to move this to  different com port).

BUT !!!, it only works once, on a second attempt I get an "access denied" error (I'm on Windows XP).

It's as if the file hasn't been closed (it has).

If i restart the program, it prints once, then access denied.

Here's the code I'm using

procedure TForm1.Button9Click(Sender: TObject);

  var myPrinter: TextFile;

begin
  assignFile(myPrinter,'com1');
  rewrite(myPrinter);


  writeln(myPrinter, escInitialise );
  writeln(myPrinter,'Hello world!');
  writeln(myPrinter,chr(28) + chr(112) + chr(01) + chr(00) + chr(10));
  //the line above prints the first .bmp in printer memory
  writeln(myPrinter,escFeedAndCut);

  closeFile(myPrinter);
end;



Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Print an image when printer in raw mode.
« Reply #9 on: July 19, 2011, 10:08:09 pm »
Maybe should close the file before feed and cut?

Roosters

  • New Member
  • *
  • Posts: 16
Re: Print an image when printer in raw mode.
« Reply #10 on: July 20, 2011, 08:27:38 am »
I can't close the file before cutting, I must be able to send the cut command when the file is open.

What I think **must** be happening is that the com port is remaining open (hence access denied).

Is there a way of releasing the com port ?


Mando

  • Full Member
  • ***
  • Posts: 181
Re: Print an image when printer in raw mode.
« Reply #11 on: July 20, 2011, 04:26:14 pm »
Maybe you must configure the com port with printer parameters. Baud speed, parity ... and so...

I don't remeber now how can do it. I'm searching....

It's only an idea...



regards...

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Print an image when printer in raw mode.
« Reply #12 on: July 21, 2011, 10:36:39 am »
I can't close the file before cutting, I must be able to send the cut command when the file is open.

What I think **must** be happening is that the com port is remaining open (hence access denied).

Is there a way of releasing the com port ?
Perhaps you have to properly close/release your com port component... also grasping at straws here...

What component/code are you using for the com port? Are there any posts/Google results for people with similar problems?
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Elmug

  • Hero Member
  • *****
  • Posts: 849
Re: Print an image when printer in raw mode.
« Reply #13 on: July 21, 2011, 11:03:04 am »
Maybe need to use Reset file?

Mando

  • Full Member
  • ***
  • Posts: 181
Re: Print an image when printer in raw mode.
« Reply #14 on: July 21, 2011, 11:24:04 am »
HI.

In delphi I used this code to configure com port:
Code: [Select]
function TPuertoComm.Conectar: boolean;
var CommPort: string;
    TimeoutBuffer: PCOMMTIMEOUTS;
    DCB:TDCB;
    Escrito: Cardinal;
begin
  result:=false;
  CommPort := format('COM%d',[FPuerto]);
  hCommFile := CreateFile(PChar(CommPort),
                          GENERIC_WRITE+GENERIC_READ,
                          0,
                          nil,
                          OPEN_EXISTING,
                          FILE_ATTRIBUTE_NORMAL,
                          0);

  if hCommFile = INVALID_HANDLE_VALUE then begin  showMessage('Error abriendo puerto'); exit; end;

  result:=true;

  // +---- Configurar el puerto -----------------------------------------------+
  GetCommState(hCommFile,DCB);
  DCB.BaudRate:=57600;
  DCB.ByteSize:=8;
  DCB.Parity  :=0;
  DCB.StopBits:=0;
  SetCommState(hCommFile,DCB);

  // +--- Configurar timeouts -------------------------------------------------+
  GetMem(TimeoutBuffer, sizeof(COMMTIMEOUTS));

  GetCommTimeouts (hCommFile, TimeoutBuffer^);
  TimeoutBuffer.ReadIntervalTimeout        := 10;
  TimeoutBuffer.ReadTotalTimeoutMultiplier := 10;
  TimeoutBuffer.ReadTotalTimeoutConstant   := 10;

  SetCommTimeouts (hCommFile, TimeoutBuffer^);

  FreeMem(TimeoutBuffer, sizeof(COMMTIMEOUTS));
end;


this to send data:
Code: [Select]
var
  Escrito: Cardinal;

begin

Text:='Hello world!';

WriteFile(hCommFile,
            PChar(Text)^,
            Length(Text),
            Escrito,
            nil);
end;

to close port:
Code: [Select]
closeHandle(hCommFile);


define:
hCommFile: THandle;


I don't try in Lazarus....

regards


 

TinyPortal © 2005-2018