Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/397.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中使用Xon Xoff协议?_Java - Fatal编程技术网

如何在Java中使用Xon Xoff协议?

如何在Java中使用Xon Xoff协议?,java,Java,我试图开发一个用于打印财政票据的代码。 我使用Java编程语言XON-XOFF和协议来打印票据 因此,我编写了以下代码: public SerialPortHandler(String portaCOM){ log = new MyLog4J(); try { this.connect(portaCOM); this.provaScontrino(); } catch (IOException

我试图开发一个用于打印财政票据的代码。 我使用Java编程语言XON-XOFF和协议来打印票据

因此,我编写了以下代码:

    public SerialPortHandler(String portaCOM){
        log = new MyLog4J();
        try {
            this.connect(portaCOM);
            this.provaScontrino();
        } catch (IOException e) {
            log.logStackTrace(e);
        }
    }

    public void connect(String portName) throws IOException {
        try {
            // Obtain a CommPortIdentifier object for the port you want to open
            CommPortIdentifier portId =
                CommPortIdentifier.getPortIdentifier(portName);
            log.information("apro porta seriale");
            //System.out.println("apro porta seriale");
            // Get 
            serialPort =
                (SerialPort) portId.open("Demo application", 5000);
            // Set the parameters of the connection.
            setSerialPortParameters();
            log.information("settaggio porta terminato");

        } catch (NoSuchPortException e) {
            log.logStackTrace(e);
            throw new IOException(e.getMessage());
        } catch (PortInUseException e) {
            log.logStackTrace(e);
            throw new IOException(e.getMessage());
        } catch (IOException e) {
            log.logStackTrace(e);
            serialPort.close();
            throw e;
        }
    }

   public void provaScontrino(){
        try {
            outStream = serialPort.getOutputStream();
            //inStream = serialPort.getInputStream();
            log.information("output acquisito ora provo a stampare uno scontrino");
            String messageString = "j";
            outStream.write(messageString.getBytes()); 
            //messageString = "'PANTALONE'10H1R";
            //outStream.write(messageString.getBytes()); 
            messageString = "\"MAGLIA\"3*100H1P";
            outStream.write(messageString.getBytes()); 
            messageString = "1T";
            outStream.write(messageString.getBytes());
            messageString = "J";
            outStream.write(messageString.getBytes());
            log.information("scontrino stampato ora apro il cassetto");
            apriCassetto();
        } catch (Exception e) {
            log.logStackTrace(e);
        }
    }
因此,我认为有3张MAGLIE的非财政票据,但我收到的票据如下:

DITTA S.R.L.
  NAME OF CITY
   P.IVA

                 EURO
Operatore 12
Reparto 1         0,00
TOTALE EURO       0,00
CONTANTI          0,00

14/10/14 10:55     SF.4
我们能帮我吗


Reguards

要得到答案,你应该解释一下你期望的是什么,3 MAGLIE到底是什么,以及你正在使用的打印机型号。代码messageString=\MAGLIA\3*100H1P;我用它在票上打印文章的名字。