java-Linux上的自定义TG2480H USB
作者:互联网
我有JavaPOS和XML文件的示例代码,但是当我运行代码时,在printer.claim(1)上遇到了异常,我在此link上使用了示例的默认xml(pos.xml)文件
我已经将必需的本机驱动程序安装到/usr/java / packages / lib /中,因此本机驱动程序应该没有问题.
码:
import jpos.JposException;
import jpos.POSPrinter;
import jpos.POSPrinterConst;
import jpos.events.StatusUpdateEvent;
import jpos.events.StatusUpdateListener;
import jpos.util.JposPropertiesConst;
import java.util.StringTokenizer;
public class Printer {
public static void main(String[] args) {
System.setProperty(JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME, "jpos.xml");
POSPrinter printer = new POSPrinter();
// constants
String ESC = ((char) 0x1b) + "";
String LF = ((char) 0x0a) + "";
try {
//Open Printer
printer.open("CUSTOM TG2480H POS Printer USB Linux");
printer.claim(1);
printer.setDeviceEnabled(true);
//Print a Text String
printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, "Print Test");
//Close Printer
printer.setDeviceEnabled(false);
printer.release();
printer.close();
} catch (JposException e) {
// display any errors that come up
e.printStackTrace();
} finally {
// close the printer object
try {
printer.close();
} catch (Exception e) {
}
}
System.exit(0);
}
}
XML档案:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE JposEntries PUBLIC "-//JavaPOS//DTD//EN" "jpos/res/jcl.dtd">
<JposEntries>
...
<JposEntry logicalName="CUSTOM TG2480H POS Printer USB Linux">
<creation factoryClass="custom.services.posprinter.SimpleJPOSServiceInstanceFactory" serviceClass="custom.services.posprinter.TG2480H.CUSTOM_TG2480HPrinterService"/>
<vendor name="CUSTOM" url="http://www.custom.biz"/>
<jpos category="POSPrinter" version="1.8"/>
<product description="Jpos printer driver" name="CUSTOM TG2480H POS Printer" url="http://www.custom.biz"/>
<prop name="PhysicalDevice" type="String" value="CUSTOM TG2480H POS Printer"/>
<prop name="PID" type="String" value="01A8"/>
<prop name="deviceBus" type="String" value="USB"/>
<!--"portname" for USB device is the "USB Address Number" (refer to the printer Setup)-->
<prop name="portName" type="String" value="0"/>
<!--"logging" values: "none", "file://[file path / name]" and "video" -->
<prop name="logging" type="String" value="Video"/>
<!--CUSTOM PROPERTIES:-->
<!--PrintTextAutoLF: If true, the driver sends a LF after every PrintNormal or PrintImmediate-->
<prop name="PrintTextAutoLF" type="String" value="true"/>
<!--EnableTOStsSignal: If true, and the printer supports it, the driver signals PTR_SUE_REC_CARTRIDGE_EMPTY if the ticket is present on output, otherwise PTR_SUE_REC_CARTDRIGE_OK-->
<prop name="EnableTOStsSignal" type="String" value="false"/>
</JposEntry>
...
</JposEntries>
错误:
[Friday, 14 August 2015 12:23:27][M]claim [1]
[Friday, 14 August 2015 12:23:27][I][BasePrinterService] claim Begin
[Friday, 14 August 2015 12:23:27][I]Opening USB device with Pid:<01A8> and Address Number <0> ...
[Friday, 14 August 2015 12:23:27][E]
[Friday, 14 August 2015 12:23:27][I]Retry Open...
[Friday, 14 August 2015 12:23:27][E][BasePrinterService] jpos.JposException : Claim timeout Error
jpos.JposException : Claim timeout Error
at custom.services.posprinter.BasePrinterService.claim(Unknown Source)
at jpos.BaseJposControl.claim(Unknown Source)
at .<init>(<console>:11)
at .<clinit>(<console>)
at .<init>(<console>:7)
at .<clinit>(<console>)
at $print(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
.....
信息管理系统
[ 78.993713] usb 2-1.5: new full-speed USB device number 5 using ehci-pci
[ 79.067711] usb 2-1.5: device descriptor read/64, error -32
[ 79.231704] usb 2-1.5: device descriptor read/64, error -32
[ 79.405698] usb 2-1.5: new full-speed USB device number 6 using ehci-pci
[ 79.479695] usb 2-1.5: device descriptor read/64, error -32
[ 79.643657] usb 2-1.5: device descriptor read/64, error -32
[ 79.817685] usb 2-1.5: new full-speed USB device number 7 using ehci-pci
[ 80.219464] usb 2-1.5: device not accepting address 7, error -32
[ 80.418552] usb 2-1.5: new full-speed USB device number 9 using ehci-pci
[ 80.508162] usb 2-1.5: New USB device found, idVendor=0dd4, idProduct=0193
[ 80.508178] usb 2-1.5: New USB device strings: Mfr=4, Product=56, SerialNumber=210
[ 80.508180] usb 2-1.5: Product: TG2480
[ 80.508183] usb 2-1.5: Manufacturer: CUSTOM Engineering S.p.A.
[ 80.508185] usb 2-1.5: SerialNumber: TG2480 Num.: 0
[ 80.513602] usblp 2-1.5:1.0: usblp0: USB Bidirectional printer dev 9 if 0 alt 0 proto 2 vid 0x0DD4 pid 0x0193
解决方法:
根据dmesg日志,您的设备是TG2480(不是TG2480H),根据技术支持的电子邮件,该设备不支持JavaPOS.
标签:linux,xml,java,javapos 来源: https://codeday.me/bug/20191028/1948900.html