I need to print a non-fiscal role in Java.
On the client machine a Bematech 4200 is already installed on 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 to this port? Because it is always falling in catch.
Thank you.