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