简体   繁体   English

ESC命令将条形码打印到热敏打印机?

[英]ESC commands to print barcode to a thermal printer?

When you purchase a thermal receipt printer, you also get a manual that tells you which byte sequence should be used to do what (cutting, finishing job, setting fonts etc). 当您购买热敏票据打印机时,还会得到一本手册,告诉您应该使用哪个字节序列来执行操作(剪切,整理工作,设置字体等)。 However I do not have an understanding of Java that is sufficient for me to be able to use the ESC/POS commands. 但是,我对Java的了解不足以使我能够使用ESC / POS命令。

I have a Citizen CT S2000 thermal receipt printer. 我有一台Citizen CT S2000热敏票据打印机。 I have already managed to use the byte sequences for cutting and line feeding and manipulating what fonts the thermal printer is supposed to have. 我已经设法将字节序列用于剪切和换行以及操纵热敏打印机应该具有的字体。 However I can not figure out how to use the ESC commands for generating and printing barcode. 但是我不知道如何使用ESC命令生成和打印条形码。

The manual on how to do this is here on page 144. Here a sample code is provided in BASIC. 如何做到这一点的手册是在这里第144页以下示例代码在BASIC提供。

LPRINT CHR$(&H1D);"k"; CHR$(73); CHR$(10);
LPRINT "{BNo.{C"; CHR$(12); CHR$(34); CHR$(56);
LPRINT CHR$(&HA);
END

Here is my attempt to print the barcode. 这是我尝试打印条形码的尝试。

public static void barcode() throws Exception{
    byte[] b = {0x7b, 0x43, 0x12, 0x34}; 
    //This is the commands as I interpreted the to print out 12 and 34

    DocPrintJob job = PrintServiceLookup.lookupDefaultPrintService().createPrintJob();

    DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; 
    /*This is how I send byte sequences. 
    if you got something better then don't hesitate yelling at me :D : ). */

    Doc doc = new SimpleDoc(b, flavor, null);

    job.print(doc, null);                   
}

Yet this does not yield anything at all and the printer doesn't do anything at all. 但这根本不产生任何结果,并且打印机根本不执行任何操作。

I really can't find any examples of how to do it. 我真的找不到如何做到这一点的例子。

Any answers/comments would be appreciated. 任何答案/评论将不胜感激。

Try the below command you can print the barcode. 尝试使用以下命令可以打印条形码。

byte[] barCode = {0x1d,0x6b,0x07,0x6e,0x61,0x72};

Here 0x6e,0x61,0x72 are the charters "nar" which converted into barcode.

I'm sure it will work. 我敢肯定它将起作用。 Please let me know in case of any query. 如有任何查询,请通知我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM