I am trying to check the status of a thermal printer using ESC/POS commands which is connected using USB in kotlin. The code I have implemented is as follows,
val usbInterface = usbDevice.getInterface(0)
val usbEndpoint = usbInterface.getEndpoint(0)
val usbConnection = usbManager?.openDevice(usbDevice)
usbConnection?.claimInterface(usbInterface, true)
val data = byteArrayOf(0x10, 0x04, 0x04)
val d = usbConnection?.bulkTransfer(usbEndpoint, data, data.size, 500)
val buffer = ByteArray(8)
val bytes = usbConnection?.bulkTransfer(usbInterface.getEndpoint(1), buffer, buffer.size, 500)
println("$bytes in ${buffer.contentToString()}")
However according to the documentation and other materials on ESC/POS commands I should receive something like this 0b01101100 if there is no paper (refer: https://escpos.readthedocs.io/en/latest/reliance_status.html). But what I am receiving in the above println statement is [114, 0, 0, 0, 0, 0, 0, 0]
.
Is this the desired output or have I done anything wrong?
The information on the Pyramid ESC/POS page you are referring to is missing.
If you want to refer to the corresponding specifications of ESC/POS, this page is better.
DLE EOT
- Each status consists of 1 byte, and the value is 0xx1xx10b.
The real time status can be differentiated by the bits 0, 1, 4, and 7 from other transmission data, except for data in block data (Header – NUL).
The printer reports 1 byte, and the question is not just the received data, but the entire buffer, including the unused area, so it's not the correct question.
Given the size of the data received, it would be correct to present only the first byte 114
in the question.
Since 114
is a decimal number, it is 01110010
when expressed as a binary number.
This value indicates that the roll paper end sensor bit (5,6)
is 1
and there is no paper.
And the reason why the bits (2,3)
of the roll paper near-end sensor are 0
is that the value 0
is notified because the near-end sensor has no meaning when there is no paper.