4

I am developing an Point-Of-Sale android application. My Tysso PRP 188 printer is connected by Ethernet. I can print on the printer but i don't know how to cut paper after print is finished.

The String i am using to print is below:

                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";

and this is how i print it.

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();

    }

}

I am not sure but i think to solve my problem i have to convert my Text-to-print in some kind of encoding which this printer understands so how to do it i don't know !!!

Mian.Ammar
  • 663
  • 1
  • 9
  • 22

5 Answers5

6

Thanks to all. I achived this by:

oStream.println(new char[]{0x1D, 0x56, 0x41, 0x10});
Mian.Ammar
  • 663
  • 1
  • 9
  • 22
2

To cut paper use this commands after printing text:

oStream.write(0x1D);
oStream.write(86);
oStream.write(48);              
oStream.write(0);
grig
  • 848
  • 6
  • 15
1

actually I sent this

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

and it cut the paper. No need to add empty lines to the text. This automatically adds line feed and cuts.

Alp Altunel
  • 3,324
  • 1
  • 26
  • 27
0

Try adding the escape code for the auto cutter to the end of the print string. You may have to do a char(0x1B) . to get the right form of the output. This link might help you with the conversion between integer and character: can we convert integer into character

Community
  • 1
  • 1
Gravitoid
  • 1,294
  • 1
  • 20
  • 20
0

for new lines

osStream.println("\n\n");

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

or

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

is all done.

Alp Altunel
  • 3,324
  • 1
  • 26
  • 27