anastaciocintra / escpos-coffee

Java library for ESC/POS printer
https://anastaciocintra.github.io/escpos-coffee
MIT License
282 stars 74 forks source link

where can i find the printer name? #49

Closed palanganero closed 4 years ago

palanganero commented 4 years ago

In this line it asks me for the name of the printer, where can I find the name of the printer? PrintService printService = PrinterOutputStream.getPrintServiceByName("printerName");

anastaciocintra commented 4 years ago

hi @palanganero, the answer is PrinterOutputStream.getListPrintServicesNames() you can make something like this:

    public static void main(String[] args) throws IOException {
        if(args.length!=1){
            System.out.println("Usage: java -jar xyz.jar (\"printer name\")");
            System.out.println("Printer list to use:");
            String[] printServicesNames = PrinterOutputStream.getListPrintServicesNames();
            for(String printServiceName: printServicesNames){
                System.out.println(printServiceName);
            }

            System.exit(0);
        }
        PrintService printService = PrinterOutputStream.getPrintServiceByName(args[0]);
palanganero commented 4 years ago

ok, thank you. But If I had more than one device connected to bluetooth or even had more than one printer, how does this software distinguish which device to send the data to?

anastaciocintra commented 4 years ago

This is same list of windows installed printers. Each printer have one unique name.

anastaciocintra commented 4 years ago

When you print one notepad document You notice this same list

palanganero commented 4 years ago

ok I understand. And will this code print a simple hello world? `package impresoratickets;

import com.github.anastaciocintra.escpos.EscPos; import com.github.anastaciocintra.escpos.image.EscPosImage; import java.io.Closeable; import java.io.Flushable; import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.util.Objects; import java.util.Properties;

import com.github.anastaciocintra.escpos.barcode.BarCodeWrapperInterface; import com.github.anastaciocintra.escpos.image.ImageWrapperInterface; import com.github.anastaciocintra.output.PrinterOutputStream; import javax.print.PrintService;

public class ImpresoraTickets { public static void main(String[] args) throws IOException {

PrintService printService = PrinterOutputStream.getPrintServiceByName("printer_name"); PrinterOutputStream printerOutputStream = new PrinterOutputStream(printService); EscPos escpos = new EscPos(printerOutputStream); escpos.writeLF("Hello Wold"); escpos.feed(5); escpos.cut(EscPos.CutMode.FULL); escpos.close(); }

}`

anastaciocintra commented 4 years ago

yes, it should print Hello World

palanganero commented 4 years ago

ok, thank you!

anastaciocintra commented 4 years ago

count on me see you

anastaciocintra commented 4 years ago

any exception?

palanganero commented 4 years ago

and what command should be sent to open the cash drawer?