Recent

Author Topic: Printer - detect end of paper/ deleting print jobs  (Read 1311 times)

ermok

  • Newbie
  • Posts: 5
Printer - detect end of paper/ deleting print jobs
« on: January 23, 2024, 09:44:34 am »
Hey,

I have question how to get no paper error and deleting pending print jobs?

Im developing a kiosk where user can answer some questions and system will print a ticket.
The problem is, sometimes we run out of paper, but program still send new job to printer. Finally someone will figure out that there is no paper, installs new paper roll and
suprise, gets ton of pending tickets...
I really need to avoid that kind of "error"
I tried to get paper sensor data using passtrough and Escape function but no luck, probably im doing something wrong.

I tried following code:
Code: Pascal  [Select][+][-]
  1. type
  2.  TPrinterData = record
  3.     DataLength: Word;
  4.     Data: array [0..255] of Byte; //
  5. end;
  6.  
  7. procedure TForm1.Button3Click(Sender: TObject);
  8. var
  9.   TestInt: Integer;
  10.   BufferIn: TPrinterData;
  11.   BufferOut: TPrinterData;
  12.   I: Integer;
  13.  
  14. begin
  15.   Printer.BeginDoc;
  16.  
  17.   try
  18.     TestInt := PASSTHROUGH;
  19.  
  20.  
  21.     if Escape(TWinPrinter(Printer).Handle, QUERYESCSUPPORT, SizeOf(TestInt), @TestInt, nil) > 0 then
  22.     begin
  23.       BufferIn.Data[0]:= 29;
  24.       BufferIn.Data[1]:= 114;
  25.       BufferIn.Data[2]:= 1;
  26.  
  27.       BufferIn.DataLength := 3;
  28.       // clearing the buffer
  29.      for I:= 0 to 254 do
  30.        BufferOut.Data[I]:= 0;
  31.  
  32.       BufferOut.DataLength := 0;
  33.       Escape(TWinPrinter(Printer).Handle, PASSTHROUGH, 0, @BufferIn, @BufferOut); // buffer out gets always zero length
  34.  
  35.      // check bits, determine sensor status ...
  36.     end;
  37.  
  38.   finally
  39.     Printer.EndDoc;
  40.   end;
  41.  
  42. end;  
  43.  
  44.  

Escape code is taken here:

https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=124
you need to accept the terms and then you will see the description


OS is Win10 64bit
Lazarus ver 2.2.6
FPC ver 3.2.2

Printer is Epson TM-T20III

rvk

  • Hero Member
  • *****
  • Posts: 6328
Re: Printer - detect end of paper/ deleting print jobs
« Reply #1 on: January 23, 2024, 10:12:31 am »
The problem is, sometimes we run out of paper, but program still send new job to printer. Finally someone will figure out that there is no paper, installs new paper roll and
suprise, gets ton of pending tickets...
When that happens... what does the status in Windows say?
If it says "Out of paper" you shouldn't mess with passthrough but just read out the status from the Windows-driver.

You should be able to get the status from PPrinterInfo2.
For a complete example look at my post here: https://forum.lazarus.freepascal.org/index.php/topic,37125.msg248804.html#msg248804


ermok

  • Newbie
  • Posts: 5
Re: Printer - detect end of paper/ deleting print jobs
« Reply #2 on: January 23, 2024, 12:21:02 pm »
Thanks, it maybe solves my problem.

First answer is Not available; Printing; 1 document(s) waiting

Im going to grab new roll of paper, and test it again, if Not Available message comes with no paper, then i can just skip the further print requests and send warning message to crew.

ermok

  • Newbie
  • Posts: 5
Re: Printer - detect end of paper/ deleting print jobs
« Reply #3 on: January 25, 2024, 01:25:12 pm »
Many thanks again.

Your answer solved my problem. It will not detect "No paper" but gives Not Available response
And this is enough to trigger corresponding action. Stuff will see that there is error with
Printer and thats all i needed.

Thaddy

  • Hero Member
  • *****
  • Posts: 15555
  • Censorship about opinions does not belong here.
Re: Printer - detect end of paper/ deleting print jobs
« Reply #4 on: January 25, 2024, 01:44:46 pm »
You may even get away with GetLastError/GetLastOSError based on what RVK wrote.
If I smell bad code it usually is bad code and that includes my own code.

 

TinyPortal © 2005-2018