Java - Print on Bematech_com3 port

Asked

Viewed 77 times

2

I need to print a non fiscal paper in Java.

The customer’s machine already has a Bematech 4200 installed in the Bematech_com3 port:

I’m trying to print using the following method:

private void imprimir(String frase) {
    //Gera o arquivo de desconto
    try {
        File arquivo = new File("teste.txt");
        if (arquivo.exists()) {
            //se existir
            FileWriter arquivoTxt = new FileWriter(arquivo, true);
            PrintWriter linhasTxt = new PrintWriter(arquivoTxt);
            //ACREDITO QUE SO PODE TER 42 CARACTERES
            linhasTxt.println("==========================================");
            linhasTxt.println("            Thiosti Restaurante           ");
            linhasTxt.println("===========================================");
            linhasTxt.println("********** NAO E DOCUMENTO FISCAL *********");
            linhasTxt.println("===========================================");
            linhasTxt.println("============= CUPOM DE DESCONTO ============");
            linhasTxt.println("===========================================");
            linhasTxt.println(frase);
            linhasTxt.println("===========================================");
            linhasTxt.println("       Agradecemos a preferencia!        ");
            linhasTxt.println("Delivery - 3095-3838");
            //emiteComanda();
        } else {
            //se não existir
            arquivo.createNewFile();
            //criaTxt();
        }
    } catch (IOException error) {
        System.out.println("nao encontrei arquivo");
    }

    try {
        java.io.InputStream is = new FileInputStream("teste.txt");
        Scanner sc = new Scanner(is);
        FileOutputStream fs = new FileOutputStream("Bematech_COM3:");
        PrintStream ps = new PrintStream(fs);
        while (sc.hasNextLine()) {
            String linhas = sc.nextLine();
            ps.println(linhas);
        }
        fs.close();
    } catch (IOException ex) {
        ex.printStackTrace();
        JOptionPane.showMessageDialog(null, "Erro encontrado ao imprimir comanda." + ex.toString());
    }
}

Is there a simpler way to print directly on this port? Because it is always falling in the catch.

Thank you.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.