我正在开发一个销售点android应用程序。我的Tysso prp188打印机是通过以太网连接的。我可以在打印机上打印,但我不知道打印完成后如何剪纸。
我要打印的字符串如下:
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" +
"nnnnnnnn";
,这就是我打印它的方式。
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});
在打印文本后使用以下命令剪纸:
oStream.write(0x1D);
oStream.write(86);
oStream.write(48);
oStream.write(0);
实际上我发送了这个
oStream.println(new char[]{0x1D, 0x56, 66, 0x00});
,它剪纸。不需要在文本中添加空行。这将自动添加换行和剪切。
尝试将自动切割机的转义码添加到打印字符串的末尾。您可能需要做一个char(0x1B)。以得到正确的输出形式。这个链接可能会帮助你在整数和字符之间的转换:我们可以将整数转换成字符
显示新行
osStream.println("nn");
osStream.println(new char[]{29,86,66});
或
printWriter.println(new char[]{0x1D, 0x56, 0x42});