java - Linux 上的自定义 TG2480H USB

标签 java xml linux javapos

我有 JavaPOS 和 XML 文件的示例代码,但是当我运行代码时,我在 printer.claim(1) 上遇到了异常,我使用了默认的 xml (pos.xml) 示例文件 link

我已经在/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)
    .....

DMESG<​​/h2>
[   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。

关于java - Linux 上的自定义 TG2480H USB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32005100/

相关文章:

java - Swing 组件在离开键盘焦点时自行调整大小

java - ColdFusion ~ 类不能是接口(interface)(仅限 OSX)

c# - 如何在具有多个数据的 XML 节点中获取单个数据属性

Python communicate() 与 NMap

linux - 从设备驱动程序的下半部分发出磁盘读取

linux - 通过 ssh 在返回的文本中保留 '\n' 换行符

java - 如何在 Struts ValueStack 中设置 EL 变量

java - 网络编程语言

xml - xsl :variable? 中<step>的含义是什么

XML 和 XSLT 将输出写入文本文件