What is the best practice to query the printer for each print job?

I'm a developer of a Java ticketing software, it sends raw ZPL commands to printers connected via USB (with LinkOS SDK), Ethernet (TCPSocket) or serial. This software is compliant with italian ticketing laws, where each ticket is unique and must be signed with a security smartcard.

The goal in this software is to be as fast as possibile and  prevent printing failure becase the procedure is this:

  1. Getting ticket request from client
  2. Get hash from smartcard
  3. Save details in database
  4. Print the ticket

The most critical is printing step because it is the last one, then if the printer fails I have to justify a smartcard emission without a paper ticket and I cannot undo the smartcard request.


For now I wrote a status test method that query the printer with ~HS command, waits few seconds and if the testus arrive in time and is right the job go on. I run it before every ticket.


Let's say I have to print many tickets, for each one I send ~HS as first command, wait the printer status, get the hash from smartcard, save details in database, send ZPL job to the printer.

With this procedure am I sure that if the paper ends I can stop the next ticket in time? Am I sure that printer replies to ~HS request after the end of previous print job?


Am I following the best practise for my situation?


Thank you for your help!