首页 > 解决方案 > 热敏打印机打印条形码但打印字节而不是数字

问题描述

我尝试在热敏打印机中打印条码,但打印机打印的编号不同,我需要打印我定义的条码编号。

当前行为 我的号码是:“12345678” 条码打印机是:https : //snag.gy/VNxQs3.jpg 4950515253545556

预期行为 我的号码是:“12345678” 条码打印机是:https : //snag.gy/OVlebj.jpg 12345678

   @Override
public void run()
{
    try {
        if(usbInterface != null && connection != null && mEndPoint != null) {
            if(connection.claimInterface(usbInterface, true)) {

                printBarcode(connection,usbInterface);
            }
            else {
                System.out.println("ClaimInterface is false, print again.");
            }
        }
        else {
            System.out.println("Ocurrio un problema con la conexión...");
        }
    }
    catch(Exception e) {
    }
}

private void printBarcode(UsbDeviceConnection connection, UsbInterface interfaceUsb) {
String uuid  = "12345678";
byte[] uuidBytes = uuid.getBytes();
byte[] formats  = {(byte) 0x1d, (byte) 0x6b, (byte) 0x49, (byte)uuidBytes.length};

byte[] bytes    = new byte[formats.length + uuidBytes.length];


System.arraycopy(formats, 0, bytes, 0, formats.length );
System.arraycopy(uuidBytes, 0, bytes, formats.length, uuidBytes.length);

connection.bulkTransfer(mEndPoint, bytes, bytes.length, TIMEOUT_COMMAND_PRINTER); }

在 Command POS 打印机的文档中,我发现: 1D 6B m d1…dk 00 Print bar code 或 1D 6B mn d1…dn 这与我使用的命令相同

在调试中,我可以看到打印机的数字与 uuidBytes.getBytes 相同,例如 [49,50,51,52,53,54,55,56] [ 1, 2, 3, 4, 5, 6, 7、8]

我正在使用这台打印机: https ://support.hp.com/mx-es/drivers/selfservice/hp-dual-serial-usb-thermal-receipt-printer/4169725/model/4169726?sku=BM476AA

标签: androidthermal-printer

解决方案


推荐阅读