0

Thank you in advance for reading this!

I am using a java app to send bytes through the usb interface to an EPSON TM-T88V receipt printer using esc/pos commands

The behaviour is different when executed on the raspberry pi compared to when executed on my dev laptop (which is super strange!)

When the bytes are printed from the raspberry pi - it stops before completing

The code is as below:

public void sendToPrinter(byte[] message) throws UsbException {
   UsbDevice device = getPrinterDevice(); //find the usb using usb4java

   UsbConfiguration configuration = device.getActiveUsbConfiguration();
   UsbInterface iface = configuration.getUsbInterfaces().get(0); //There was only 1

   if (!iface.isClaimed()) {
      iface.claim(usbInterface -> true);
   }

   UsbEndpoint endpoint = (UsbEndpoint) iface.getUsbEndpoints().get(0);
   UsbPipe pipe = endpoint.getUsbPipe();

   pipe.open();

   try {
      LOG.info(Arrays.toString(message));
      int sent = pipe.syncSubmit(message);
      LOG.info("Bytes Sent: " + sent);
   } finally {
      pipe.close();
   }

   iface.release();
}

Things I have investigated:

  1. I read on about java8 that during heavy processing, the pi might lose power to usb devices and I have upgraded the power source to the pi so that it is receiving 2A
  2. I have tried comparing the bytes sent to the printer from my dev machine and the pi and they are identical (the bytes sent and the number of bytes sent are identical)

I can provide more info on the bytes I sent to the printer, although the esc/pos commands sent from my laptop work as expected so I don't believe that could be the cause - but may be wrong!

Thanks again for all your help!

spxcxlxxs
  • 57
  • 8

2 Answers2

0

I seem to have found a solution

Splitting the array and sending 8 bytes at a time has allowed the printer/pi to communicate successfully without the printer randomly stopping:

public static void sendAsBatch(int batchSize, byte[] payload, UsbPipe pipe) throws UsbException {

   int offset = 0;
   for (int multiplier = 1; offset < payload.length; multiplier++) {

      byte[] batch = offset + batchSize < payload.length ?
            Arrays.copyOfRange(payload, offset, offset + batchSize) :
            Arrays.copyOfRange(payload, offset, payload.length);

      pipe.syncSubmit(batch);
      offset = multiplier * batchSize;
   }
}

I still don't know what the actual problem is though and if anyone can shed any light would be amazing

But for anyone else facing the same issue this seems to have solved it :)

spxcxlxxs
  • 57
  • 8
-1

Try sending more bytes (one, two thousands?!) to the printer after you sent the ones that you want. Try with 0x00 or 0xFF.

LOTUSMS
  • 10,317
  • 15
  • 71
  • 140
  • What would that help? And are there any sources this will help? – Johannes Jander Jan 12 '16 at 19:29
  • It is a way to make sure that whatever it is in printer's internal buffer comes out at the other end. I've seen it mentioned in a Brother or Zebra label printer as a way to make sure that the internal buffer is empty. I've encountered a similar situation... the application worked when printing several labels, but it didn't work when printing just one - sending more bytes helped. – Not Relevant Jan 12 '16 at 19:58
  • @LOUTUSMS - I've just tried sending an extra thousand 0x00 bytes to the printer but to no avail it still not printing properly. Still getting the same issue where the printer stops printing roughly halfway before finishing Any help is appreciated! Thanks in advance! – spxcxlxxs Feb 11 '16 at 01:42