Print receipt using receipt printer
Asked Answered
M

2

6

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.

Moynahan answered 18/8, 2015 at 11:19 Comment(0)
H
4

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.

Halfcocked answered 18/8, 2015 at 12:3 Comment(7)
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/DOMParserMoynahan
@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.Halfcocked
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.Halfcocked
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-9501d6413ba6c19d87b19be2123a9010cb3b0d4f\src\main\java\postest2\POSTest2Controller.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/MojoFailureExceptionMoynahan
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)Moynahan
@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 CompilerHalfcocked
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 ))Halfcocked
A
1

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.

Abridgment answered 18/8, 2015 at 11:29 Comment(5)
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.Matt
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.Matt
"\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 #3866687Academy
@ChristofferHammarström ah okay, sorry, I've only done this in c#, so I just checked online :) thanks for the feedbackAbridgment
Just specifying the string as "\n" instead should work.Academy

© 2022 - 2024 — McMap. All rights reserved.