2

我一直在研究 javaPOS、JCL、JDK、路径和类路径的来龙去脉,现在试图弄清楚如何使用 JavaPOS 在我的 Epson TM-T20 Receipt 打印机上成功打印一行。由于从光盘(打印机随附)安装的 javaPOS 无法在 Windows 10 上正确安装(认为它安装在 Linux 上),我需要创建自己的 jpos.xml 文件。它需要包含我的打印机的设备条目。(我也尝试过从 Epson 下载新的 JavaPOS ADK 以及旧版本但没有成功)。

这是我到目前为止的设置....

  1. 我已经提取了最新的 JCL。我没有将类路径设置为 JCL 二进制文件(jar 文件),而是将它们放在 java ext 目录中。
  2. 我将位于JDK1.8.0_74中的Java“src.zip”作为“src”解压到JDK1.8.0_74目录中。
  3. 我已将包含所有 jpos 源文件的“jpos”文件夹放入该“src”文件夹中,因此我可以轻松地将它们导入到我的测试应用程序中。
  4. 我研究了其他 jpos.xml(包括 POSTest/2 和 Starmicronics 等),以了解我需要包含哪些条目。
  5. 我已将 jpos.xml 放在 Java“src”文件夹中。

这是我的 jpos.xml....

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE JposEntries PUBLIC "-//JavaPOS//DTD//EN"

"jpos/res/jcl.dtd">

<JposEntries>
<!--Saved by JavaPOS jpos.config/loader (JCL) version 2.3.0-RC3 on 6/03/16 1:20 PM-->

<JposEntry logicalName="TM-T20">

<creation factoryClass="jpos.loader.JposServiceInstanceFactory" serviceClass="jpos.services.POSPrinterService114"/>
<vendor name="Seiko Epson" url="http://www.Epson.com"/>

<jpos category="POSPrinter" version="1.14"/>

<product description="Epson Thermal Receipt Printer TM-T20" name="TM-T20" url="http://www.Epson.com"/>


<!--Other non JavaPOS required property (mostly vendor properties and bus specific properties i.e. RS232 )-->

<prop name="deviceBus" type="String" value="USB"/>
<prop name="portName" type="String" value="ESDPRT001"/>

<prop name="model" type="String" value="TM-T20"/>
</JposEntry>


 </JposEntries>

这是我的测试应用程序...

import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.UIManager;
import jpos.util.JposPropertiesConst;



public class ReceiptPrintMain {


public ReceiptPrintMain() {

    ReceiptPrint2 frame = new ReceiptPrint2();

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    frame.setVisible(true);
}

public static void main(String[] args) {
    System.setProperty(JposPropertiesConst.JPOS_POPULATOR_FILE_PROP_NAME, "C:\\Program Files (x86)\\Java\\jdk1.8.0_74\\src\\jpos.xml");
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
    catch(Exception e) {
        e.printStackTrace();
    }
    new ReceiptPrintMain();
}
}

// File: ReceiptPrint2
// Purpose:

import java.awt.AWTEvent;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import jpos.JposException;
import jpos.POSPrinter;
import jpos.POSPrinterConst;



public class ReceiptPrint2 extends JFrame {   


POSPrinter ptr = new POSPrinter();
JPanel contentPane;
JPanel jPanel_reciept = new JPanel();
TitledBorder titledBorder1;
GridBagLayout gridBagLayout1 = new GridBagLayout();
GridBagLayout gridBagLayout2 = new GridBagLayout();
JButton jButton_Print = new JButton();


public ReceiptPrint2() {

    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
        jbInit();
    }
    catch(Exception e) {
        e.printStackTrace();
    }
}

private void jbInit() throws Exception  {

    contentPane = (JPanel) this.getContentPane();
    titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(134, 134, 134)),"Receipt");
    contentPane.setLayout(gridBagLayout1);
    this.setSize(new Dimension(300, 180));
    this.setTitle("Step 1  Print \"Hello JavaPOS\"");
    jPanel_reciept.setLayout(gridBagLayout2);
    jPanel_reciept.setBorder(titledBorder1);
    jButton_Print.setText("Print");
    jButton_Print.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
                jButton_Print_actionPerformed(e);
        }
    });
    contentPane.add(jPanel_reciept, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
                    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(15, 0, 0, 0), 20, 20));
    jPanel_reciept.add(jButton_Print, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
                    ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 10, 5, 10), 130, 0));
}   

protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
            this.closing();
    }

    else if (e.getID() == WindowEvent.WINDOW_OPENED) {

        try {
            ptr.open("TM-T20");

            ptr.claim(1000);

            ptr.setDeviceEnabled(true);
        }
        catch(JposException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
        }
    }
}

void jButton_Print_actionPerformed(ActionEvent e) {     
    try{                
        ptr.printNormal(POSPrinterConst.PTR_S_RECEIPT,"Hello JavaPOS\n");
    }
    catch(JposException ex){
       JOptionPane.showMessageDialog(null, ex.getMessage());
    }       
}

void closing(){     
    try{            
        ptr.setDeviceEnabled(false);

        ptr.release();

        ptr.close();
    }
    catch(JposException ex){
    }        
    System.exit(0);
}    
}

我收到的错误消息是....“无法使用logicalName = TM-T20 连接到服务:Exception.message = jpos.loader.jpos.ServiceInstanceFactory.init()”

我猜我的 jpos.xml 文件条目不正确,主要是 factoryClass 和/或 serviceClass。请任何人都可以帮助我。也许有人拥有为 TM-T20 创建的 jpos.xml 文件并且不介意共享。

4

0 回答 0