I'm having a project in android that need to print RAW text (to support ESC/P command) using UsbManager class. I did it using bulkTransfer, and the code looks like this. And now I should give an option to cancel the job. How can I do it?
I've tried to search and somehow I couldn't find it anywhere. And I'm new to android too. Thanks.
Edit:
The printer I use is Tally T5040 and Epson PLQ-30.
What I've tried is clear printer buffer by sending 0x18 (CANCEL DATA) command. But still no luck.
Edit 2:
Finally I was able to soft reset the printer (clearing all buffer) by using controlTransfer. The full command is controlTransfer(0x21, 2, 0, 0, null, 0, 0)
. I got the references from this site. But the problem right now is the reset command only work on Epson PLQ-30.
According to Universal Serial Bus Device Class Definition for Printing Devices, there is a Class-Specific Request called SOFT_RESET:
This class-specific request flushes all buffers and resets the Bulk OUT and Bulk IN pipes to their default states. Thisrequest clears all stall conditions. This reset does NOT change the USB addressing or USB configuration.
So you just need to send SOFT_RESET request using controlTransfer, the code is (Kotlin):
controlTransfer(0x21, 2, 0, 0, null, 0, 0)
The reason why my other printer (Tally T5040) didn't work was because the firmware didn't support SOFT_RESET request. I already contact them and got the update for the firmware to support SOFT_RESET.
In case anyone looking for references about how to print in Android using USB (including soft reset, checking paper status), you can check my project here.