Print receipt using receipt printer

10,902

Solution 1

Here is an open source project for testing, that may also be used as a reference on how to program using JavaPOS (source code available):

Also here are some projects hosted on GitHub (see the source code to get the idea and to play with):


Related links:


NOTE:
in order to utilize JavaPOS (which is now a part of the UnifiedPOS specification, see Appendix B), the producer of your Datecs DPP-255 device must provide the related drivers. Are they provided? JavaPOS - is a specification, so accordingly there must be some implementation of it.

Solution 2

So it looks like this printer supports something called ESC/POS, which is like a command set that allows you to print and format data. There are a few guides available online, this is one I've used before: http://www.starmicronics.com/support/mannualfolder/escpos_cm_en.pdf

Note that printers sometimes subtly differ in which command sets from ESC/POS they support, so you might have a bit of trial and error on your hands.

In terms of sending that data to the printer, it depends on what type of connection it is. For serial, you should just be able to open and write to that port, using the ESC/POS command set.

Not all of the data you will send will be ASCII or UTF encoded, a lot of them are binary values you need to send. So for example, to tell the printer to write a new line, the Hex value for that is 0A. So in Java you would need to specify that as String s = "\u000A"; etc.

For java you will need to download the Java Comm API from http://java.sun.com/products/javacomm/

There is a tutorial on this here: http://www.java-samples.com/showtutorial.php?tutorialid=214

Hopefully this helps.

Share:
10,902
Yunus Einsteinium
Author by

Yunus Einsteinium

I am a passionate Java and web developer

Updated on June 17, 2022

Comments

  • Yunus Einsteinium
    Yunus Einsteinium almost 2 years

    I am developing a Point Of Sale application, and one of the functionality is to print receipt in a thermal/receipt printer. Currently I have a Datecs DPP-255 printer.

    I have no idea where to begin my quest.

    I tried search through internet, found out that JavaPOS/UnifiedPOS exists but I couldn't find enough documentation to get me started. Please shed some light.

  • Esben Skov Pedersen
    Esben Skov Pedersen over 8 years
    Note the installation of Java Comm is really painful. It includes copying dll's directly into the jvm installation. An alternative is just using plink(from putty) which is just started as a process from java and read/write with stdio.
  • Esben Skov Pedersen
    Esben Skov Pedersen over 8 years
    Also I had some stability issues with java comm last time I used it. If using plink, the plink process can just be killed and restarted in event of an error and will then release all resources back to the OS.
  • Christoffer Hammarström
    Christoffer Hammarström over 8 years
    "\u000A" is also known as "\n", i.e. newline. And "\u000A" won't work as the Java compiler will interpret that as a literal linebreak within quotes. See stackoverflow.com/questions/3866187/…
  • Keiran van Vuuren
    Keiran van Vuuren over 8 years
    @ChristofferHammarström ah okay, sorry, I've only done this in c#, so I just checked online :) thanks for the feedback
  • Christoffer Hammarström
    Christoffer Hammarström over 8 years
    Just specifying the string as "\n" instead should work.
  • Yunus Einsteinium
    Yunus Einsteinium over 8 years
    i create a project for above POStest, the following error i got jpos/res/jpos.properties file not found jpos/res/jpos.properties file not found Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/parsers/DOMParser
  • informatik01
    informatik01 over 8 years
    @YunusEinsteinium Seems like Apache Xerces library is not available on the classpath. I have updated a link to POSTest project (the first link), the initial page seems to be outdated, so there is a version 2 of this project that is more up to date (plus bug fixes). Download from there, that ZIP file definitely contains xerces,jar file.
  • informatik01
    informatik01 over 8 years
    And the jpos.properties is not on the classpath too. Btw the new POSTest 2 project is Maven based, so it has the required dependency (Apache Xerces) defined in the POM file. The binary (i.e. the compiled POSTest) has the xerces.jar.
  • Yunus Einsteinium
    Yunus Einsteinium over 8 years
    Thanks for the update. I used the sourceforge project(updated--2), and when build and downloading dependencies an error displayed in console: Compilation failure javapospostest2-code-9501d6413ba6c19d87b19be2123a9010cb3b0d4‌​f\src\main\java\post‌​est2\POSTest2Control‌​ler.java:[424,6] error: try-with-resources is not supported in -source 1.5 -> [Help 1] For more information about the errors and possible solutions, please read the following articles: [Help 1] cwiki.apache.org/confluence/display/MAVEN/MojoFailureExcepti‌​on
  • Yunus Einsteinium
    Yunus Einsteinium over 8 years
    In the file POSTest2Controller.java, an error is shown in this code // Clear file and write new path! try (PrintWriter writer = new PrintWriter(f)) { writer.print(""); } catch (FileNotFoundException e1) { e1.printStackTrace(); } : a red underline in the try saying: try-with-resources is not supported in -source 1.5 (use -source 7 or higher to support try-with-resources)
  • informatik01
    informatik01 over 8 years
    @YunusEinsteinium By default Maven currently uses Java 1.5. Add this to your POM: <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build>. See this for more: Setting the -source and -target of the Java Compiler
  • informatik01
    informatik01 over 8 years
    Try with resources is available since Java 7 (1.7), that's why you were getting this error. Also POSTest 2 project has a "Discussion" area (forum), so you could also try to ask for help right from the authors of this project, in case something specific needs clarification. P.S. Don't give up ))