kr403 sdk java sendAndWaitForResponse

P Plagnes Didier 2 years 11 months ago
2 1 0

Hello,
 
usb.sendAndWaitForResponse("~HQES".getBytes(), 1000, 1000,null);
 
When I run this command line, sometimes answer is empty or length is double (message is double but right).
 
Do you know why ? do I need reset buffer before run ?
 
thanks
 
Didier

Please register or login to post a reply

1 Replies

V Vedsatx Saddvv

Hi Didier,
I'm moving this question to the printer pages. 

The ~HQES may take the printer a little time to process.   If the printer doesn't respond within the timeout you have given, it may still respond and sit in the USB buffer on the Android until you request it again.  That's why sometimes it's empty and other times you get double.  It may have the previous response in the buffer.  Also the printers, when powering off, sometimes flush the last USB response again, so you may get an extra then. 
Some ideas:
1. Try upping the initialResponseTimeout to maybe 2000, and cutting the timeToWaitForMoreData to 500.  Once the printer starts responding, it doesn't take long for it to finish on this command.
2. You could also just try again if you get an empty response the first time and discard the extra data you get back.
3. Try using the string terminator to just pull a single response: usb.sendAndWaitForResponse("~HQES".getBytes(), 2000, 1000,new String(new byte[] { 0x03 }));

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