Print receipt using receipt printer - java

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.

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):
JavaPOS POSTest 2 - a JavaPOS application for testing JavaPOS devices (source code is here).
Also here are some projects hosted on GitHub (see the source code to get the idea and to play with):
JavaPOS
POSdeviceSimulator
POStest
Related links:
Old documentation page for
JavaPOS
How to develop using JavaPOS in
Eclipse?
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.

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.

Related

Specify output tray/mailbox using javax.print

I'm trying to print on a printer full of functionality (Kyocera TASKalfa 5501i), having a mailbox add-on with 7 outputs installed. I want to print to each of those outputs indiviually using Java on a server. Because my application runs on a remote server, Java has no UI available to, for example, open the drivers default preferences-window and select the output-tray there. Until now i got all attributes working, that are in the javax.print.attribute.standard package, but i have no idea how to select the output-tray.
I searched nearly the entire internet for a solution. Does anyone have an idea how to select the output-tray/mailbox or pass, any non-default parameter to the printer without having to implement the complete printing-stack from bottom up?
Kind regards.

How to get started reading data from magnetic card with a simple bi-direction swipe magnetic card reader?

Let's say I have a USB magnetic card reader
(http://image.ec21.com/image/szttce09/oimg_GC03950917_CA03950946/Triple_Track_USB_Magnetic_Credit_Card_Reader.jpg)
I am running windows 10 on my machine. All I want to do is read data from the magnetic card and use that data in a java Application. How can I do this ? I heard the java communications api is suitable for what I want. How exactly do I use this api or any other api to read data from the card reader and show that data in my java application. Assume I have eclipse opened. Now what? Do I import the communications api ? If yes , what do I do next ? If you can give a simple example of how to do this it would be greatly appreciated.
The first thing to do is search the internet for a Java library, which allows you to communicate with that device. Put in the model and serial number, and see what comes up. If nothing comes up, and that is quite likely to happen, you will need to find the native driver, and wrap it in Java.
This is not normally a straight forward or easy process. When dealing with third party hardware, most vendors don't supply a little Java library that you can use. If you can find the native drivers, you can wrap them from C to Java, but you might not even be able to find the drivers at all.
Start by going to the manufacturer's page, and looking around. If you find the driver, great. If you find documentation for the driver, even better. You will need to read the documentation, and understand how to use the driver from C code, which implicitly requires you to have a basic understanding of C.
Then you will need to link it in to Java, using the Java Native Interface.
In Summary: If it didn't say "For Java developers" in the description when you bought it, you're going to have to do a lot of work just to get it usable in Java.

How to add an available network printer using java code?

I would like to get the list of available network printers, and allow users to install (add) a selected printer on their pc using a JButton.
I have searched the net and did find a java api called java printer api but this didn't help me.
Any suggestions ?
As you have probably realized, the standard Java Print service API is for printing documents from a Java application. It works by interacting with an existing printer or print service provided by the host system. It does not address the concerns of setting up or configuring printers or print services.
I would like to get the list of available network printers, and allow users to install (add) a selected printer on their PC using a JButton.
The Java printing APIs don't provide that functionality.
So there is no way to automate the install process? Execute a batch script maybe?
If it is possible to automate printer installation, discovery, configuration (or what have you) using a shell script or batch file that can be run by an unprivileged user, then it is possible (actually simple) to get Java to run the script.
Writing that script is likely the hard part, and it is not a Java programming problem. And if you can't write / find a script to do this, then your chances of doing printer setup from a Java program are about zero. While it may be technically possible to do the task in Java, it is (IMO) not worth the development effort to do it that way.

How to access information in Windows Device Manager from Java?

I have a serial to USB device and more than one of those can be connected to the computer. I need to query and retrieve a list of COM ports that the devices are connected to. In Windows Device Manager you can get the COM port + friendly name of devices that are connected at the present time. This list is dynamic.
Reading from the registry did not work because the information stored is stale and static, not dynamic.
Devcon (from Microsoft) does list the ports that devices are connected to, but it cannot be used in my app because it is not re-distributable.
Any ideas or preferably, a solution?
I had to solve a similar issue just some weeks ago. I came accross the Jawin-Project that provided everything you need to use WMI-Queries. It is already quite old but works like a charm if you follow the documentation. A nice German walkthrough can be found codegods blog.
For me, it did not solve all problems (I had some very specific things to find out about the target device), I finally created an own JNI (Java Native Interface) Class and DLL in C incorporating the windows API.
I hope this is what you searched for.
Did you try this jUSB API or This example ?
I hope this will help you.
Use JNA (https://github.com/twall/jna) and take a look at the following page. It might be a useful point to start from.
http://www.digitalinferno.com/wiki/Wiki.jsp?page=JNAPrintDevices
I am looking at Java Native Access as it provides access to the windows API from pure Java code - no JNI to deal with. I was concerned about the LGPL license; whether it can be included in a commercial product but from what a few posts in the newsgroup say, it can be.
After I try it out in the next few weeks, I shall post back here.

printing to a dot matrix printer on a mac

So i am designing an art project that will print to a dot matrix printer the contents of my internet history. i have found info online to parse out a plist (what os x uses to store internet history) so im all set on that front but what i am looking to find out is how to send a request to the printer to print a new line, which would happen when a new page is visited. i was wondering if it is possible in any of the following languages: objective-c, javascript, php, or processing/java, all of which i have a decent understanding of. I am have tried to do a little research before asking here and it seems like i may need to use shell commands, which i am not familiar with at all. the printer i will most likely be using is an EPSON LX-300 Dot Matrix Printer if that matters. i would like to do this on os x, but if i have to use windows that is an option. if anyone knows how to do this or can give me some direction that would be a huge help. thanks
Here is how I might do it.
First, I suppose I might look around for a dot matrix printer with a modern interface and a Mac OS X driver. There might still be people printing multipart forms who need impact printers.
But failing that, I would then look for a serial (as in, RS-232 serial) printer and connect it to my mac via a USB-to-RS232-serial converter. Be careful, most of the generic such things don't work on the Mac, get a USB serial widget like this that specifically supports the mac.
Then, I would write the code in sh/bash and run it in a Terminal window. Those language systems you cite are overkill for this job, some lack system interfaces entirely, and the ones that can turn system knobs do it via complex interfaces. It's better to put together stty(2), echo(1), cat(1) et al and just get some strings to print.

Categories