Retrieving a response sending print command via Socket

B Beau Tremblay 3 years 7 months ago
159 0 0

Hello, I'm creating a UI to print labels using the GK420t network printer.   I wrote a service in Groovy to send the print command to the the printer.  I'm printing many labels at once, so I did have to troubleshoot to learn I could only print 9 labels in one command.
 
I was hoping there might be some response that came back from the socket's input stream, but if I try to read it (see commented lines) the printing hangs.  I'd like to display some kind of feedback to the user the printing worked.  What is the preferred way to do this?  Is there a property I can read to determine the result of the last command?
 
class ZebraPrintService {
 
   static final PRINTER_CONFIG = "ZebraPrinterConfig"   static int PRINTER_PORT = 9100   static ZebraCommandBuilder commandBuilder = new ZebraCommandBuilder();
   private String ip   private Map formatMap = [:]
   private String lastCommand   String getIp() {
   return ip ?: Lookups.findByField(PRINTER_CONFIG).value1
  }
 
  String sendPrintInstructions(List plates) {
   final int MAX_PRINTING = 9   def platesToPrint = plates
   while (platesToPrint.size() > 0) {
   def plateBatch = platesToPrint.take(MAX_PRINTING)
  platesToPrint = platesToPrint.drop(MAX_PRINTING)
 
   def socket = createCommandSocket()
   try {
   def cmdOut = new DataOutputStream(socket.getOutputStream())
   //def responseIn = new BufferedReader(new InputStreamReader(socket.getInputStream()))   int msgNum = 1   lastCommand = ""   for (LabelPrintable p in plateBatch) {
  cmdOut.writeByte(msgNum++)
  String cmd = getPrintCommand(p);
  cmdOut.writeUTF(cmd)
  cmdOut.flush()
 
   // lastCommand

CONTACT
Can’t find what you’re looking for?