【问题标题】:How to fire paper cutter of ESC/POS from android application如何从 Android 应用程序触发 ESC/POS 的切纸机
【发布时间】:2014-05-10 08:25:04
【问题描述】:

我正在开发一个销售点 Android 应用程序。我的 Tysso PRP 188 打印机通过以太网连接。我可以在打印机上打印,但我不知道打印完成后如何剪纸。

我用来打印的字符串如下:

                msg = "\n" + 
                            "                   KOT \n"+
                            "Voucher No: " + vno + "  \t  Order No: " + ono + "\n" + 
                            "Waiter Name: " + wname + " \t  Table: " + tno + "\n" + 
                            "Time: " + time + " \n" +
                            "- - - - - - - - - - - - - - - - - - - - - - - -\n" +
                            "       Item                          Quantity  \n" +
                            "- - - - - - - - - - - - - - - - - - - - - - - -\n" + 
                            "\n" + 
                            itemslist +
                            "\n- - - - - - - - - - - - - - - - - - - - - - - -\n" + 
                            "\n\n\n\n\n\n\n\n";

这就是我打印它的方式。

private class MyPrinter extends AsyncTask<String, String, String>
{

    Socket sock;
    PrintWriter oStream;
    DataInputStream is;
    ProgressDialog pDialog = null;
    Context context;

    public MyPrinter(Context context)
    {
        this.context = context;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(CustomerInformation.this);
        pDialog.setTitle("Print Order");
        pDialog.setMessage("Please Wait ...");
        pDialog.show();
    }

    protected String doInBackground(String... params) {

        try 
        {
            sock = new Socket(params[0], Integer.parseInt(params[1]));
            sock.setSoTimeout(300);

            is = new DataInputStream(sock.getInputStream());

            if(sock.getRemoteSocketAddress() != null)
            {
            oStream = new PrintWriter(sock.getOutputStream());

            oStream.println(params[2]);

            }
            else
            {
                Log.i("cycle", "Remote Socket Address");
            }



            oStream.flush();
            oStream.close();

            sock.close();

        }
        catch (UnknownHostException e) 
        {
            Log.i("cycle", "00");
            e.printStackTrace();
        } 
        catch (IOException e) 
        { 

            Log.i("cycle", "11");
            e.printStackTrace();
        }
        finally{

        }
        return null;
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);

        if(pDialog != null)
            if(pDialog.isShowing())
                pDialog.dismiss();


        finish();

    }

}

我不确定,但我认为要解决我的问题,我必须将我的 Text-to-print 转换为某种打印机可以理解的编码,所以我不知道该怎么做!!!

【问题讨论】:

  • 如何打印订单详情?你能分享你的代码吗?

标签: android printing stream ethernet


【解决方案1】:

谢谢大家。我通过以下方式实现了这一目标:

oStream.println(new char[]{0x1D, 0x56, 0x41, 0x10});

【讨论】:

  • 在打字稿中:this.cut = new Uint8Array(4); this.cut[0] = 0x1D; this.cut[1] = 0x56; this.cut[2] = 0x41; this.cut[3] = 0x10;
  • 非常适合我!
【解决方案2】:

打印文本后使用此命令剪纸:

oStream.write(0x1D);
oStream.write(86);
oStream.write(48);              
oStream.write(0);

【讨论】:

  • 在此之前可能需要一些新行。我添加了 oStream.println("\n\n\n");换行并剪切
【解决方案3】:

尝试将自动切纸器的转义码添加到打印字符串的末尾。您可能需要执行 char(0x1B) 。获得正确的输出形式。此链接可能会帮助您进行整数和字符之间的转换:can we convert integer into character

【讨论】:

    【解决方案4】:

    其实是我发的

     oStream.println(new char[]{0x1D, 0x56, 66, 0x00});
    

    它把纸剪了。无需在文本中添加空行。 这会自动添加换行和剪切。

    【讨论】:

      【解决方案5】:

      换行

      osStream.println("\n\n");
      
      osStream.println(new char[]{29,86,66});
      

      printWriter.println(new char[]{0x1D, 0x56, 0x42});
      

      全部完成。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-12-14
        • 2020-11-16
        • 1970-01-01
        • 2020-10-19
        • 2015-02-18
        • 1970-01-01
        • 2013-02-25
        • 1970-01-01
        相关资源
        最近更新 更多