Forum > Windows

Printer - detect end of paper/ deleting print jobs

(1/1)

ermok:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  TPrinterData = record    DataLength: Word;    Data: array [0..255] of Byte; //end;  procedure TForm1.Button3Click(Sender: TObject);var  TestInt: Integer;  BufferIn: TPrinterData;  BufferOut: TPrinterData;  I: Integer; begin  Printer.BeginDoc;   try    TestInt := PASSTHROUGH;      if Escape(TWinPrinter(Printer).Handle, QUERYESCSUPPORT, SizeOf(TestInt), @TestInt, nil) > 0 then    begin      BufferIn.Data[0]:= 29;      BufferIn.Data[1]:= 114;       BufferIn.Data[2]:= 1;       BufferIn.DataLength := 3;       // clearing the buffer     for I:= 0 to 254 do       BufferOut.Data[I]:= 0;       BufferOut.DataLength := 0;      Escape(TWinPrinter(Printer).Handle, PASSTHROUGH, 0, @BufferIn, @BufferOut); // buffer out gets always zero length      // check bits, determine sensor status ...    end;   finally    Printer.EndDoc;  end; end;    
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:

--- Quote from: ermok on January 23, 2024, 09:44:34 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...
--- End quote ---
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:
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:
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:
You may even get away with GetLastError/GetLastOSError based on what RVK wrote.

Navigation

[0] Message Index

Go to full version