如何从Android中的热敏打印机打印吗?热敏、打印机打印、Android

2023-09-12 10:55:21 作者:我的领悟始终不够

我工作的一个Android设备,将有一个内置的行式打印机的应用程序。我必须在此打印机交互并使用它来打印收据上,然后用切​​割器自动切断该收据的细节。我见过一些ESC键在它的命令,但我不知道如何执行这些ESC命令。

I am working on an application for an Android device that will have a built in line printer. I have to interact with this printer and use it to print the details on receipt and then with cutter cut that receipt automatically. I have seen some ESC commands in it, but I don't know how to execute these ESC commands.

我有一个关于卡西欧设备打印机三个主要问题:

1.我已经使用了打印$ C $下生成的打印机,但打印刀后不激活

BuildinEx840 ex840 = new BuildinEx840();
int response = ex840.open();
System.out.println("ex840 open:" + response);

byte[] set = {
    'N', 'A', 'R', 'E', 'S', 'H', 'S', 'H', 'A', 'R', 'M', 'A', (byte) 0x0d, (byte) 0x0a
};

try {        

    ex840.write(set);   

} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

try {

    response = ex840.getEndStatus();
    System.out.println("getEndStatus:" + response);
    response = ex840.initCutter();
    ex840.close();    
    System.out.println("initCutter:" + response);

} catch (Exception e) {         
    e.printStackTrace();         
}

2。我不知道如何发送ESC命令到打印机中的Andr​​oid

有命令的数量像下面

ESC FF DataPrint,
[code]  <1B>H<OC>H,
[Function] Print all the data in the print area collectively.

我们如何能够通过编程执行这些ESC android的命令??

How can we execute these ESC commands in android by programming ??

3 我不知道如何打印收据要求的格式

有一些ESC命令是可从左侧和右侧和一些其它命令提供边距。那么,如何可以打印数据在某些甲酸,可以改变文本的大小以及文本的某些其他设置进行打印。

There are some ESC commands are available for providing margins from left and right and some other commands. So how can I print the data in some formate and can change the size of the text as well as some other settings of the text to be printed.

任何帮助是AP preciated。

Any help is appreciated.

推荐答案

工作了最后7天之后,我得到了正确的方式来获得打印,然后将那收到的刀具。 ESC命令来获取打印和与打印机的其他任务非常重要。我们要通过这些ESC CMD的字节数组的行式打印机的形式。

After working for last 7 days i got the right way to get the print and then cut that receipt by the cutter. ESC commands are very important to get the print and other tasks related to the printer. We have to pass those ESC CMD in form of the byte array to the Line Printer.

有命令的数量像下面

ESC FF DataPrint,
[code]  <1B>H<OC>H,
[Function] Print all the data in the print area collectively.

所以只是简单的创建这个命令的字节数组,并将其传递到打印机。

So just simple create a byte array of this command and pass it to the printer.

e.g. byte[] print = {0x1b,0x0c};

现在把它传递到打印机。必须有一些方法,像getCmd(),或writeCmd()等,这取决于打印机时。

now pass it to the printer. There must be some method like getCmd(), or writeCmd() etc. depending upon the printer.

我们如何执行这些通过编程机器人ESC命令? 下面是code要做到这一点

How can we execute these ESC commands in android by programming ?? Below is the code to do that

    BuildinEx840 lpd=new BuildinEx840();
            lpd.setMulticharMode(LinePrinterDeviceBase.CHARACTERSET_USA);
//initialise Cutter
            lpd.initCutter();
            LinePrinter lp=new LinePrinter();
            lp.open(lpd);
            lpd.open();
            try{
                lpd.init();
            }catch(IOException e){
                e.printStackTrace();
            }
            for(int i=0; i<5;i++){
                lp.printNormal("Testing the Line Printer");
            }
            int totalLinefeed=listofItemList.size();
//ESC CMD for line feeds
            byte[] lfs=new byte[]{0x1B,'d', 5};
            sendtoExprinter(lpd,lfs);
//ESC CMD for paper cut
            lfs=new byte[]{0x1B,'i'};
            sendtoExprinter(lpd, lfs);

private void sendtoExprinter(BuildinEx840 dev, byte[] instr) {
        try{
            dev.write(instr);
        }catch(IOException e){
            e.printStackTrace();
        }

    }

更新: 通过热敏打印机打印图像的

在某些打印机可以定义打印机的非易失性存储器中的图像,然后通过 ESC CMD 1C 70 01 30 从那里打印图像。在其他一些打印机可以给图像的直接路径而经由热敏式打印机打印的图像。

In some of the printer you can define the image in non-volatile memory of the printer and then print the image from there through ESC cmd 1C 70 01 30. In some of the other printers you can give a direct path of the image while printing an image through thermal printer.

在任何行式打印机,我们有这个 printerObj.write(命令),以通过ESC CMD; 办法。我要感谢SO社会,特别感谢TheBlastOne谁引导我正确的方式。

In any line printer we have to pass the ESC CMD by this printerObj.write(command); way. I want to Thanks to SO community and special thanks to TheBlastOne who guided me to the right way.

如果某人具有集成热敏打印机随意问任何问题。