Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:13:10+00:00 2026-06-04T10:13:10+00:00

I am using a thermal printer which kicks out the drawer before or after

  • 0

I am using a thermal printer which kicks out the drawer before or after printing. But i want to stop that and i am sending a hex code to kickout the draw when needed. The sequence i am using is openDrawerCommand = "\u001B\u0070\u0030\u0042\u0045"; This is working fine in windows but if i run this on linux i am getting some error not in the application but from the printer driver saying that “There was a problem processing document ‘Java Printing'”. What is this all about ? I thing there is something to do with the code so tat it runs well on all platforms. The code i am using is shown below:

public OpenCashDrawer() {
    PrintService pservice = PrintServiceLookup.lookupDefaultPrintService();
    System.out.println("printservice"+pservice);
    try {
        DocPrintJob job = pservice.createPrintJob();
        String openDrawerCommand = ((char)0x1B70111)+"";
        //
        openDrawerCommand = "\u001B\u0070\u0030\u0042\u0045";
        byte by[] = openDrawerCommand.getBytes();
        //char[] printdata = "hello world\n".toCharArray();
        // System.out.println(by[1]);
        DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
        //PrintService pservice = PrintServiceLookup.lookupDefaultPrintService();
        //DocPrintJob pjob = pservice.createPrintJob();
        //DocFlavor flavor = DocFlavor.CHAR_ARRAY.TEXT_PLAIN;
        Doc doc = new SimpleDoc(by, flavor, null);
        job.print(doc, null);
    } catch (Exception e) {
        System.out.println("Whoa bro. The printer is balls. Check it:");
        e.printStackTrace();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:13:12+00:00Added an answer on June 4, 2026 at 10:13 am

    I got this working by the following code.

    public OpenCashDrawer() {
        SwingWorker worker = new SwingWorker<String, Void>() {
    
            public String doInBackground() {
                try {
                    String sql = "INSERT INTO pos_cashdraw SET user_id='"+global_variables.user_id+"', message='Opened For Sale'";
                    mysql_query.update_mysql(variables.con.conn, sql);
                    String out = "";
                    do {
                        out = "";
                        //System.out.println("opened cashdraw");
                        //String openDrawerCommand = "\u001B\u0070\u0030\u0042\u0045";
                        String openDrawerCommand2 = "\u0017";
                        //String cmd = "echo -e " + openDrawerCommand2 + " > /dev/usblp0";
                        String cmd = "echo -e " + openDrawerCommand2 + " > /dev/ttyS0";
                        ProcessBuilder pb = new ProcessBuilder("bash", "-c", cmd);
    
                        pb.redirectErrorStream(true);
                        if (pb != null) {
                            Process shell = pb.start();
                            InputStream shellin = shell.getInputStream();
                            int c;
                            while ((c = shellin.read()) != -1) {
                                System.out.write(c);
                                out += (char) c;
                            }
                            shellin.close();
                        }
                    } while (out.contains("busy"));
                } catch (IOException ex) {
                    System.err.println("Not supported in your operating system");
                }
                return "Opened";
            }
        };
        worker.execute();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am printing to a thermal ticket printer which has no standard drivers. Traditionally
I'm writing an iOS application which needs to print using a Boca thermal printer.
Using Nunit, I want to be able to write a test fixture that will
Using top it's easy to identify processes that are hogging memory and cpu, but
Does anyone know how to monitor cash drawer's open/close state using Advanced Printer Driver's
Using Yii, I want to delete all the rows that are not from today.
Using the navigator.geolocation object in JavaScript. Trying to establish accurate ranges, but wondering exactly
Using android 2.3.3, I have a background Service which has a socket connection. There's
Using WPF/PRISM I want to log my messages through ILoggerFacade to my GUI (A
Using jQuery, one can easily find out whether a particular element is visible using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.