Java 中的 JavaPOS Hello World
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1675059/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaPOS Hello World in Java
提问by Philippe Carriere
I would like to print a sample line on my USB POS (Point-Of-Sale) printer from a java program on Windows XP.
我想通过 Windows XP 上的 Java 程序在我的 USB POS(销售点)打印机上打印一个示例行。
I tried to setup a JavaPOS implementation but I get exception after exception for a missing jpos.xml or missing javax.usb.properties file.
我尝试设置 JavaPOS 实现,但由于缺少 jpos.xml 或缺少 javax.usb.properties 文件而出现异常。
Can anyone tell me how to generate those files? They somewhat need to link to an implementation or something like that and I'm not sure what the (rare, unclear and incomplete) documentation means. Any other help would be appreciated.
谁能告诉我如何生成这些文件?他们有点需要链接到一个实现或类似的东西,我不确定(罕见的、不清楚的和不完整的)文档是什么意思。任何其他帮助将不胜感激。
My current printer model is Star TSP 100 with a USB connector. My printer seems to be connected correctly since I can print a file on it from windows.
我当前的打印机型号是带有 USB 连接器的 Star TSP 100。我的打印机似乎连接正确,因为我可以从 Windows 打印文件。
回答by Philippe Carriere
Well, I finally found it myself. It seems like you need a part of the program from JavaPOS (that part only has interfaces and abstract classes) and you need the library from the manufacturer of the device. The jpos.xml is generated after the printer is installed. A software (also provided by the manufacturer) generates entries in the jpos.xml file based on the name of the printer and other settings. You must include this file in your program.
嗯,我终于自己找到了。看起来您需要 JavaPOS 程序的一部分(该部分只有接口和抽象类),并且您需要设备制造商提供的库。jpos.xml 是在打印机安装后生成的。软件(也由制造商提供)根据打印机名称和其他设置在 jpos.xml 文件中生成条目。您必须在程序中包含此文件。
Finally, the following code makes the connection to the printer :
最后,以下代码连接到打印机:
POSPrinter printer = new POSPrinter();
// open the printer object according to the entry names defined in jpos.xml
printer.open("printerName");
The method printnormal() is then used to print. If you printing asynchonously, you also need transactionPrint() to empty the buffer.
然后使用方法 printnormal() 进行打印。如果您异步打印,您还需要 transactionPrint() 来清空缓冲区。

