android - 如何从 Android 应用程序启动 ESC/POS 的切纸器

标签 android printing stream ethernet

我正在开发一个销售点安卓应用程序。我的 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();

    }

}

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

最佳答案

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

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

关于android - 如何从 Android 应用程序启动 ESC/POS 的切纸器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23578789/

相关文章:

Android:将图像剪辑成形状

java - 使用适用于 android 的 SIMPLE XML 库将不同命名的元素解析为单个列表

java - 将 Hashmap 写入文件

python - 对音频流使用多处理

Java 与 Python HMAC-SHA256 不匹配

.net - PrintDocument_PrintPage 和 Graphics.DrawImage 大小(以英寸为单位)

javascript - 用 window.print() 打印大表只打印一页

css - 特定于打印的 javascript

java - 从 ObjectInputStream 读取与写入 ObjectOutputStream 不同的 byte[]

Java:通过流将排序的映射键分配给数组